From 3e50582c1000359ae217b8fa5c38fea6a8c829e0 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 3 Nov 2023 20:10:28 -0600 Subject: [PATCH] aaaaaa comments cant have spaces anymore because shell expansion --- yt | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/yt b/yt index 5c2f0da..ff09de3 100755 --- a/yt +++ b/yt @@ -39,8 +39,9 @@ archive() { # archives a video to the Wayback Machine | jq .archived_snapshots.closest.url \ | tr -d '"' | sed 's/^http:/https:/g')" - if [ "$wayback_url" != "null" ]; then continue fi + if [ "$wayback_url" != "null" ]; then continue; fi + printf "%s: %s: Saving video to the Wayback Machine.\n" "$argv0" "$1" 1>&2 curl -s -d "url=$1" https://web.archive.org/{url} >/dev/null shift done @@ -56,16 +57,14 @@ cache() { # cache the video title for faster retrieval clone() { # clones a YouTube playlist to a file yt-dlp --flat-playlist "$1" --print url > "$2" - verify "$2.m3u" + verify "$2" - for line in $(cat "$2.m3u") - do + for line in "$(cat "$2")"; do # uuoc but necessary :3 if test -n "$(printf '%s\n' "$line" \ - | sed -n -e '/web\.archive\.org/p' -e '/^\#/p')" + | grep -e 'web\.archive\.org' -e '^#')" then continue - fi - printf "%s: %s: Saving video to the Wayback Machine.\n" "$argv0" "$1" 1>&2 + else archive "$line" fi done @@ -82,7 +81,7 @@ music() { # downloads a video, splitting by chapter and only saving the audio pick() { # Pick a video to play from a list of videos while test -n "$1"; do - for line in $(cat "$1"); do + for line in $(cat "$1"); do # see ln 62 if test -n "$(printf '%s\n' "$line" | sed -n '/^\#/p')" then continue @@ -122,10 +121,9 @@ usage() { verify() { # replaces videos with archived versions if they are not available while test -n "$1"; do - for video in $(cat "$1"); do - # test for unavailability + for video in $(cat "$1"); do # see ln 62 if test -n "$(yt-dlp -s "$video" 2>&1 \ - | sed -n -e '/Video unavailable/p' -e '/Private video/p' )" + | grep -i -e 'video unavailable.' -e 'private video')" then printf "%s: %s: Video unavailable.\n" "$argv0" "$video" 1>&2 @@ -134,28 +132,29 @@ verify() { # replaces videos with archived versions if they are not available | sed 's/^http:/https:/g')" if [ "$wayback_url" = "null" ] \ - && test -n "$(yt-dlp -s "$wayback_url" 2>&1 | grep -e 'not archived')" + || test -n "$(yt-dlp -s "$wayback_url" 2>&1 | grep -e 'not archived')" then - printf "%s: %s is not available on the Wayback Machine.\n" \ + printf "%s: %s: Video not available on the Wayback Machine.\n" \ "$argv0" "$video" 1>&2 # replace the video link with a comment containing link - content="$(sed "s;^$video;\# $video;g" "$1")" + content="$(sed "s;^$video;\#$video;g" "$1")" - # write the new content buffer to the file + # write the new content buffer to file printf '%s\n' "$content" > "$1" else printf "%s: %s: Replacing link with Wayback link.\n" \ "$argv0" "$video" 1>&2 - content="$(sed "s;$video;$wayback_url;g" "$1")" + content="$(sed "s;^$video;$wayback_url;g" "$1")" printf '%s\n' "$content" >"$1" cache "$wayback_url" fi else + printf '%s: %s: Video available.\n' "$argv0" "$video" 1>&2 cache "$video" fi done - + shift done } @@ -167,6 +166,10 @@ 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 -n "$DEBUG"; then + set -x +fi + for dep in \ curl \ fzf \