diff options
| author | Adam T. Carpenter <atc@53hor.net> | 2020-12-20 16:32:59 -0500 | 
|---|---|---|
| committer | Adam T. Carpenter <atc@53hor.net> | 2020-12-20 16:32:59 -0500 | 
| commit | 45f61ff80062ec9137c0d77f3b732bc1a4f59179 (patch) | |
| tree | b0e3978e43ec918e196aece2f89efadc85eff328 /yt.sh | |
| parent | 8a4cbf34f6e9509ed42b54dd15b9b506184274e7 (diff) | |
| download | scripts-45f61ff80062ec9137c0d77f3b732bc1a4f59179.tar.xz scripts-45f61ff80062ec9137c0d77f3b732bc1a4f59179.zip | |
updated url handler, started merging with yt.sh; merged screen modes,
locker into dockd for automatic docking display swap
Diffstat (limited to 'yt.sh')
| -rwxr-xr-x | yt.sh | 67 | 
1 files changed, 5 insertions, 62 deletions
| @@ -3,8 +3,6 @@  ## Config:  TERMINAL=alacritty  DOWNLOAD_DIR=~/videos/youtube -PAGER="rofi -location 2 -width 41 -e" -YOUTUBE_REGEX=".*((https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+)$"  ## Exit codes @@ -19,56 +17,14 @@ get_action_single() {  2. listen in player  3. download video  4. download audio -5. print info  EOF  	)  	echo "$action" | cut -d'.' -f1  } - -## Get action for multiple URLs -get_action_multi() { -	# TODO: implement -} - - -## Check if url is a youtube url -check_if_youtube() { -	url="$1" -	echo $url | grep -qE "$YOUTUBE_REGEX" && return 0 || return 1 -} - - -## Prompts user for URL -prompt_url() { -	dmenu -p "YouTube URL" -} - - -## Grab url from clipboard/primary selection, else get via prompt -grab_url() { -	if url="$1" && check_if_youtube $url; then -	elif url=$(xclip -o -selection clipboard 2>/dev/null || echo) && check_if_youtube $url; then -	elif url=$(xclip -o 2>/dev/null || echo) && check_if_youtube $url; then -	elif url=$(grab_url_stdin) && check_if_youtube $url; then -	elif url=$(prompt_url) && check_if_youtube $url; then -	else -		exit $NO_YOUTUBE_URL -	fi - -	echo $url -} - - -## Extract URL from stdin -grab_url_stdin() { -	sed -nE "s/$YOUTUBE_REGEX/\1/p" -} - -  ## Get title, description, and duration of URL  get_info() { -	url="$1" +	url=$1  	info=$(youtube-dl --get-title --get-description --get-duration $url)  	title=$(echo "$info" | head -n 1)  	description=$(echo "$info" | sed '1d;$d') @@ -79,7 +35,7 @@ get_info() {  ## Download video  download_video() { -	url="$1" +	url=$1  	info=$(get_info $url)  	notify-send "Downloading video..." "$info" &  	youtube-dl \ @@ -92,7 +48,7 @@ download_video() {  ## Download audio  download_audio() { -	url="$1" +	url=$1  	info=$(get_info $url)  	notify-send "Downloading audio..." "$info"  	youtube-dl \ @@ -108,7 +64,7 @@ download_audio() {  ## Play video  play_video() { -	url="$1" +	url=$1  	notify-send "Playing video..." "$(get_info $url)" &  	mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" $url &  } @@ -116,28 +72,15 @@ play_video() {  ## Play audio  play_audio() { -	url="$1" +	url=$1  	notify-send "Playing audio..." "$(get_info $url)" &  	$TERMINAL -t "Streaming from YouTube" -e mpv --no-video $url &  } - -## Print info with specified pager -print_info() { -	url="$1" -	info=$(get_info $url) -	$PAGER "$info" -} - -  ## Main  mkdir -p "$DOWNLOAD_DIR" -url=$(grab_url "$1")  case "$(get_action_single)" in -	5) -		print_info $url -		;;  	1)  		play_video $url  		;; |