From 43849795993ef6074746556818be548b61faf1df Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Sat, 15 Sep 2018 20:04:47 -0400 Subject: [PATCH] linkhandler massively streamlined, posix sh --- .scripts/linkhandler | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/.scripts/linkhandler b/.scripts/linkhandler index f540dc0..79e1e29 100755 --- a/.scripts/linkhandler +++ b/.scripts/linkhandler @@ -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