linkhandler massively streamlined, posix sh

This commit is contained in:
Luke Smith 2018-09-15 20:04:47 -04:00
parent 4ab18960b3
commit 4384979599

View file

@ -6,32 +6,19 @@
# if a music file or pdf, it will download,
# otherwise it opens link in browser.
# Sci-Hub's domain occasionally changes due to shutdowns:
scihub="http://sci-hub.tw/"
# List of sites that will be opened in mpv.
vidsites="youtube.com
\|hooktube.com
\|bitchute.com
"
# setsid nohup
# List of academic sites whose pdfs can be dled via sci-hub.
academic="springer.com"
ext="${1##*.}"
mpvFiles="mkv mp4 gif webm"
fehFiles="png jpg jpeg jpe"
wgetFiles="mp3 flac opus mp3?source=feed pdf"
if echo $fehFiles | grep -w $ext > /dev/null; then
setsid nohup feh "$1" >/dev/null & disown
elif echo $mpvFiles | grep -w $ext > /dev/null; then
setsid nohup mpv -quiet "$1" > /dev/null & disown
elif echo $wgetFiles | grep -w $ext > /dev/null; then
wget "$1" >/dev/null & disown
elif echo "$@" | grep "$vidsites">/dev/null; then
setsid nohup mpv -quiet "$1" > /dev/null & disown
elif echo "$@" | grep "$academic">/dev/null; then
curl -sO "$(curl -s "$scihub$*" | grep -Po "(?<=location.href=').+.pdf")" & disown
else
setsid nohup $BROWSER "$1" 2>/dev/null & disown
fi
case "$1" in
*mkv|*webm|*mp4|*gif|*youtube.com*|*hooktube.com*)
setsid mpv -quiet "$1" >/dev/null 2>&1 & ;;
*png|*jpg|*jpe|*jpeg)
setsid feh "$1" >/dev/null 2>&1 & ;;
*mp3|*flac|*opus|*mp3?source)
setsid tsp wget "$1" >/dev/null 2>&1 & ;;
*springer.com*)
setsid curl -sO "$(curl -s "$scihub$*" | grep -Po "(?<=location.href=').+.pdf")" >/dev/null 2>&1 & ;;
*) setsid "$BROWSER" "$1" >/dev/null 2>&1 & ;;
esac