From 45f61ff80062ec9137c0d77f3b732bc1a4f59179 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Sun, 20 Dec 2020 16:32:59 -0500 Subject: updated url handler, started merging with yt.sh; merged screen modes, locker into dockd for automatic docking display swap --- yt.sh | 67 +++++-------------------------------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) (limited to 'yt.sh') diff --git a/yt.sh b/yt.sh index 8fcf8c5..f270bc6 100755 --- a/yt.sh +++ b/yt.sh @@ -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 ;; -- cgit v1.2.3