diff options
Diffstat (limited to 'bin/lh')
-rwxr-xr-x | bin/lh | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/bin/lh b/bin/lh index 016b37f..e662589 100755 --- a/bin/lh +++ b/bin/lh @@ -15,34 +15,40 @@ split() { set +f } -case "$1" in +# handle redirects. tr removes control characters, so the case statement below works as expected. +URL=$(curl -IL "$1"|grep '^location: '|tail -1|sed 's/location: //'|tr -d '[:cntrl:]') +# if there were no redirects, just set URL to the first argument +[ -z "$URL" ] && URL="$1" + +echo $URL +case "$URL" in gemini://*|gopher://*) - $TERMINAL -e bombadillo "$1" ;; + $TERMINAL -e bombadillo "$URL" ;; *mkv|*webm|*mp4) - mpv "$1" >/dev/null 2>&1 & ;; + mpv "$URL" >/dev/null 2>&1 & ;; *youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*|*twitch.tv/*/v/*) - mpv --ytdl "$1" >/dev/null 2>&1 & ;; + mpv --ytdl "$URL" >/dev/null 2>&1 & ;; *twitch.tv/*) - STREAMQUAL="$(split "$(streamlink "$1"|grep 'Available streams')" ", "|\ + STREAMQUAL="$(split "$(streamlink "$URL"|grep 'Available streams')" ", "|\ grep -E "[0-9]"|\ - dmenu -p "choose stream quality for $1")" - streamlink -p mpv $1 $STREAMQUAL >/dev/null 2>&1 & ;; + dmenu -p "choose stream quality for $URL")" + streamlink -p mpv $URL $STREAMQUAL >/dev/null 2>&1 & ;; *png|*jpg|*jpe|*jpeg|*gif) - IMGPATH="/tmp/$(echo "$1"|sed "s/.*\\///")" - curl -sL "$1" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;; + IMGPATH="/tmp/$(echo "$URL"|sed "s/.*\\///")" + curl -sL "$URL" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;; *mp3|*m4a|*flac|*aiff|*opus|*ogg|*mp3?source*) - mpv "$1" >/dev/null 2>&1 & ;; + mpv "$URL" >/dev/null 2>&1 & ;; *epub|*pdf|*djvu) - BOOKPATH="/tmp/$(echo "$1"|sed "s/.*\\///")" + BOOKPATH="/tmp/$(echo "$URL"|sed 's/.*\///')" if [ -n "$READER" ]; then - curl -sL "$1" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 & + curl -sL "$URL" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 & else - curl -sL "$1" >"$BOOKPATH" & + curl -sL "$URL" >"$BOOKPATH" & fi ;; *) - if [ -f "$1" ]; then - $TERMINAL -e "${EDITOR:-vi} $1" + if [ -f "$URL" ]; then + $TERMINAL -e "${EDITOR:-vi} $URL" else - $BROWSER "$1" >/dev/null 2>&1 & + $BROWSER "$URL" >/dev/null 2>&1 & fi ;; esac |