dotfiles/.local/bin/tools/dmenuhandler

51 lines
2.3 KiB
Plaintext
Raw Normal View History

2020-07-04 14:23:27 +02:00
#!/bin/sh
# Feed this script a link and it will give dmenu
# some choice programs to use to open it.
makepathabsolute(){
if echo "$1" | grep -qE '^/'; then
dl_location="$1"
else
dl_location="$HOME/$1"
fi
echo "$dl_location"
}
2024-03-09 13:38:38 +01:00
choices="$(printf 'mpv\ncopy url\nqueue download\nrifle file\nqueue youtube-dl\nbrowser\nrip media\ncast\nadd torrent\n')"
2021-04-07 15:23:34 +02:00
if echo "$1" | grep -q "4chan"; then
2023-10-12 15:12:12 +02:00
choices="$(printf '%s\nwatch thread' "$choices")"
2021-04-07 15:23:34 +02:00
fi
choice="$(echo "$choices" | dmenu -i -p "Open link with what program?")"
2021-04-07 15:23:34 +02:00
case "$choice" in
2020-07-04 14:23:27 +02:00
"copy url") echo "$1" | xclip -selection clipboard ;;
2023-10-12 15:12:12 +02:00
mpv) setsid mpv --quiet --ytdl-format='bestvideo[height<=1080]+bestaudio/best[height<=1080]' --force-window=yes "$1" & ;;
2020-07-04 14:23:27 +02:00
"mpv (loop)") setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet --loop "$1" >/dev/null 2>&1 & ;;
"queue download") name="$( dmenuinput 'Name for file:' )"
[ -z "$name" ] && tsp curl -C - -LO "$1" >/dev/null 2>&1
2020-12-30 15:48:47 +01:00
tsp curl -C - -L -o $name "$1" >/dev/null 2>&1 ;;
2020-09-17 13:43:37 +02:00
"queue youtube-dl") youtube-dl --add-metadata -i -o $HOME/'%(upload_date)s-%(title)s.%(ext)s' "$1" >/dev/null 2>&1;;
2020-07-04 14:23:27 +02:00
cast) setsid $TERMINAL -e mkchromecast -y $1 --video --control
;;
browser) setsid "$BROWSER" "$1" >/dev/null 2>&1 & ;;
#feh) setsid feh "$1" >/dev/null 2>&1 & ;;
#w3m) w3m "$1" >/dev/null 2>&1 ;;
#"mpv (float)") setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) --geometry=+0-0 --autofit=30% --title="mpvfloat" "$1" >/dev/null 2>&1 & ;;
"rifle file") curl -L "$1" -o "/tmp/riflefile"
rifle /tmp/riflefile;;
2023-10-12 15:12:12 +02:00
"watch thread") dest="$(find $HOME -maxdepth 5 -type d -not -path "$HOME/.*" | dmenu -i -p 'name of folder:')"
2021-06-25 11:03:00 +02:00
[ -z "$dest" ] && exit
echo "dmenuhandler:$dest"
2021-06-25 11:03:00 +02:00
mkdir -p "$(makepathabsolute "$dest")"
threadwatcher add "$1" "$dest" &
2021-04-07 15:23:34 +02:00
notify-send "dmenuhandler" "Thread watcher started. Download initialized.";;
2024-03-09 13:38:38 +01:00
"rip media") dest="$(dmenuinput 'name of folder:')"
lynx --dump --nonumbers --listonly "$1" | grep -E "\.(webm|mp4|gif|jpg|jpeg|png|pdf|epub|mobi|djvu)" | sort -u | xargs wget -P "$(makepathabsolute "$dest")"
notify-send "dmenuhandler" "all media ripped into $dest";;
"add torrent") echo "$1" | grep -q '^magnet:' && transadd "$1"
if echo "$1" | grep -q "\.torrent$"; then
curl -L "$1" -o "/tmp/torrentfile"
transadd "/tmp/torrentfile"
rm "/tmp/torrentfile"
fi
2020-07-04 14:23:27 +02:00
esac