diff options
Diffstat (limited to 'yt.sh')
-rwxr-xr-x | yt.sh | 84 |
1 files changed, 0 insertions, 84 deletions
@@ -1,84 +0,0 @@ -#!/bin/sh -## Do things with a YouTube URL. Assumes a valid YouTube URL. Doesn't do any -## grabbing or scraping, use urlview for that. - -## Config: -TERMINAL=alacritty -DOWNLOAD_DIR=~/videos/youtube - -## Exit codes -NO_URL=3 -NO_ACTION=4 - -## Get action for a single URL -get_action() { - action=$(dmenu -p "YouTube" << EOF -1. watch -2. video download -3. audio download -EOF - ) - echo "$action" | cut -d'.' -f1 -} - -## Get title, description, and duration of URL -toast_info() { - info=$(youtube-dl --get-title --get-description --get-duration "$1") - title=$(echo "$info" | head -n 1) - description=$(echo "$info" | sed '1d;$d') - duration=$(echo "$info" | tail -n 1) - notify-send "($duration) $title" "$description" -} - - -## Download video -video_download() { - mkdir -p "$DOWNLOAD_DIR" - youtube-dl \ - -q \ - --add-metadata \ - -o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \ - "$1" && notify-send "Video download done." & - notify-send "Downloading video:" -} - - -## Download audio -audio_download() { - mkdir -p "$DOWNLOAD_DIR" - youtube-dl \ - -q \ - --add-metadata \ - -o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \ - -x \ - --audio-format flac \ - --audio-quality 0 \ - "$1" && notify-send "Audio download done." & - notify-send "Downloading audio:" -} - - -## Play video -play() { - mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" "$1" & - notify-send "Playing:" -} - - -## Main -[ -n "$1" ] || exit NO_URL -toast_info "$1" & - -case "$(get_action)" in - 1) - play "$1" - ;; - 2) - video_download "$1" - ;; - 3) - audio_download "$1" - ;; - *) - exit $NO_ACTION -esac |