From bf3da174824d8fd1ae4d8055cfdd04f4cc6b066e Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 19 Nov 2023 15:08:16 -0700 Subject: [PATCH] closes #1 --- yt | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/yt b/yt index 889d715..77407b8 100755 --- a/yt +++ b/yt @@ -18,6 +18,15 @@ set -e +test -z "$DEBUG" || set -x + +argv0="$0" +com="$1" + +cachefile="$XDG_CACHE_HOME/yt.cache" +FMT='%(title)s – %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]' +WBAPI='https://archive.org/wayback/available?url=' + add() { # adds a video to a playlist file while test -n "$2"; do if test -n "$(grep -e "$1" "$2")" @@ -56,6 +65,12 @@ archive() { # archives a video to the Wayback Machine } cache() { # cache the video title for faster retrieval + if test -z "$XDG_CACHE_HOME"; then + printf "%s: unable to create title cachefile: \$XDG_CACHE_HOME unset." \ + "$argv0" 2>&1 + exit 69 # sysexits.h(3) EX_UNAVAILABLE + fi + while test -n "$1"; do grep "$1" "$cachefile" 2>/dev/null 1>&2 || printf '%s\n' \ "$(yt-dlp -s "$1" --print "$FMT")" >>"$cachefile" @@ -85,6 +100,11 @@ music() { # downloads a video, splitting by chapter and only saving the audio } pick() { # Pick a video to play from a list of videos + if test -z "$YTPICK"; then + printf "%s: Please set \$YTPICK to your preferred picking tool." "$argv0" 1>&2 + exit 78 # sysexits.h(3) EX_CONFIG + fi + while test -n "$1"; do for line in $(lines "$1"); do if test -n "$(printf '%s\n' "$line" | sed -n '/^\#/p')" @@ -165,22 +185,6 @@ verify() { # replaces videos with archived versions if they are not available done } -argv0="$0" -com="$1" - -cachefile="$XDG_CACHE_HOME/yt.cache" -FMT='%(title)s – %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]' -WBAPI='https://archive.org/wayback/available?url=' - -if test -z "$YTPICK"; then - printf "%s: Please set \$YTPICK to your preferred picking tool." "$argv0" 1>&2 - exit 78 # sysexits.h(3) EX_CONFIG -fi - -if test -n "$DEBUG"; then - set -x -fi - for dep in \ curl \ jq \