1 changed files with 63 additions and 0 deletions
@ -0,0 +1,63 @@ |
|||
#!/bin/sh |
|||
|
|||
# TODO: detect term or set it globally |
|||
TERM_EMU="kitty" |
|||
|
|||
die() { |
|||
notify-send "$@" |
|||
exit 1 |
|||
} |
|||
|
|||
check_exists() { |
|||
which "$1" > /dev/null 2>&1 || die "$1 doesn't appear to be installed" |
|||
} |
|||
|
|||
if ! which wl-paste > /dev/null && [ ! -z "$WAYLAND_DISPLAY" ]; then |
|||
die "Wayland detected and wl-paste not found" |
|||
elif ! which xsel > /dev/null && [ -z "$WAYLAND_DISPLAY" ]; then |
|||
die "xsel not found" |
|||
fi |
|||
|
|||
if [ -z "$WAYLAND_DISPLAY" ]; then |
|||
clip="$(xsel -b -o)" |
|||
else |
|||
clip="$(wl-paste)" |
|||
fi |
|||
|
|||
urls="$(echo $clip | grep -o 'https\?://[a-zA-Z0-9~#%&_+=,.?/-]\+')" |
|||
opts="qr |
|||
audio search" |
|||
if [ -n "$urls" ]; then |
|||
opts="$(printf '%s\ndownload\nplay' "$opts")" |
|||
fi |
|||
|
|||
choice="$(printf "%s" "$opts" | dmenu -p "$(printf "%s" "$clip" | cut -c 1-48)")" |
|||
case "$choice" in |
|||
"qr") |
|||
check_exists "qrencode" |
|||
check_exists "feh" |
|||
printf "%s" "$clip" | qrencode -o - | feh -. -Z --force-aliasing --geometry 400x400 - |
|||
;; |
|||
# Download supports optional folder target |
|||
"download"*) |
|||
check_exists "youtube-dl" |
|||
path="$HOME/mus/$(printf "%s" "$choice" | cut -d " " -f 2-)" |
|||
[ -d "$path" ] || mkdir -p "$path" |
|||
cd "$path" || exit |
|||
youtube-dl -x --audio-format mp3 --no-playlist -o "%(title)s.%(ext)s" "$clip" 2>&1 | grep 'ERROR:' | xargs -n1 -d "\n" notify-send |
|||
#notify-send "Error while downloading: $clip" |
|||
;; |
|||
"play") |
|||
check_exists "mpv" |
|||
mpv --ytdl-format='bestvideo[height<=?720]+bestaudio/best' "$clip" 2>&1 | grep 'ERROR:' | xargs -n1 -d "\n" notify-send |
|||
|
|||
;; |
|||
"audio search") |
|||
check_exists "mpv" |
|||
check_exists "$TERM_EMU" |
|||
"$TERM_EMU" --single-instance mpv --ytdl-format=bestaudio ytdl://ytsearch:"$clip" |
|||
;; |
|||
*) |
|||
printf 'Nope\n' |
|||
;; |
|||
esac |
|||
Loading…
Reference in new issue