summaryrefslogblamecommitdiff
path: root/yt-player.sh
blob: a5f21b8b429a8116c56b8b4c3faf9ccde4957ba0 (plain) (tree)
1
2

         



















































                                                                              














                                                                          
#!/bin/sh

## Do things with a YouTube URL.

## Config
terminal=alacritty


## Notify the title and description of the URL
notify_info() {
	url="$1"
	info=$(youtube-dl --get-title --get-description --get-duration "$url")
	title=$(echo "$info" | head -n 1)
	description=$(echo "$info" | sed '1d;$d')
	duration=$(echo "$info" | tail -n 1)
	notify-send "$title : $duration" "$description"
}


## Main
notify_info "$1" && exit
option="$1"
case $option in
	'-c')
		url="$(xclip -o -selection clipboard)"
		[ -z "$url" ] && exit $NO_URL_IN_CLIPBOARD
		;;
	'-p')
		url="$(xclip -o)"
		[ -z "$url" ] && exit $NO_URL_IN_PRIMARY
		;;
	'-u')
		url="$2"
		[ -z "$url" ] && exit $NO_URL_IN_SECOND_ARG
		;;
	'-a')
		$terminal -e mpv --no-video "$url"
		;;
	'-da')
		youtube-dl -x --audio-format flac --audio-quality 0 "$url"
		;;
	'-v')
		mpv --no-terminal "$url"
		;;
	'-dv')
		youtube-dl --add-metadata "$url"
		;;
	*)
		exit
		;;
esac


case $choice in
	"Watch")
		mpv "$url" --no-terminal &
		;;
	"Listen")
		mpv "$url" --no-terminal --no-video &
		;;
	"Download Video")
		youtube-dl "$url" --add-metadata
		;;
	"Download Audio")
		youtube-dl "$url" -x --audio-format flac --audio-quality 0
		;;
	*)
		exit
esac