💾 Archived View for ait.place › dot › bin › dhandler.txt captured on 2022-07-16 at 13:48:26.

View Raw

More Information

➡️ Next capture (2023-01-29)

-=-=-=-=-=-=-

#!/bin/sh

# Feed this script a link and it will give dmenu
# some choice programs to use to open it.

# You cant overwrite $1, so make a new variable
url=$1

# Reads form stdin if - is first argument or empty
if [ -z "$url" ] || [ "$url" = "-" ] ; then
	if [ -t 0 ]; then
		url="$(xclip -selection c -o)"
	else
		url="$(cat /dev/stdin)"
	fi
	# if stdin empty then exit
	[ -z "$url" ] && exit 255
fi

case "$(printf "mpv\\nmpvhome\\nyoutube-dl\\naria2-mpv\\nyoutube-mpv\\naudio\\ndownload\\nfeh\\nbrowser\\ntransadd\\ncopy" | dmenu -i)" in
	mpv) setsid mpv "$url" >/dev/null 2>&1 & ;;
	mpvhome) $TERMINAL -e mpvhome "$url" >/dev/null 2>&1 & ;;
	youtube-dl) setsid $TERMINAL -e youtube-dl -ic -o "$XDG_VIDEOS_DIR/mpv/%(title)s.%(ext)s" "$url" >/dev/null 2>&1 &;;
	youtube-mpv) setsid $TERMINAL -e youtube-dl -ic -o "$XDG_VIDEOS_DIR/mpv/%(title)s.%(ext)s" --exec mpv "$url" >/dev/null 2>&1 &;;
	aria2-mpv) setsid $TERMINAL -e youtube-dl --external-downloader=aria2c --external-downloader-args '--min-split-size=2M --max-connection-per-server=16 --max-concurrent-downloads=32 --split=32' -ic -o "$XDG_VIDEOS_DIR/mpv/%(title)s.%(ext)s" --exec mpv "$url" >/dev/null 2>&1 ;;
	audio) setsid $TERMINAL -e youtube-dl -f bestaudio -ic "$url" --exec mpv >/dev/null 2>&1 & ;;
	download) curl -LO "$url" >/dev/null 2>&1 ;;
	feh) setsid feh "$url" >/dev/null 2>&1 & ;;
	browser) setsid "$BROWSER" "$url" >/dev/null 2>&1 & ;;
	transadd) transmission-remote -a "$url" >/dev/null 2>&1 & ;;
	copy) echo "$url" | xclip -selection clipboard ;;
esac