aaaaaa comments cant have spaces anymore because shell expansion

This commit is contained in:
Emma Tebibyte 2023-11-03 20:10:28 -06:00
parent bc80cdbbe6
commit 3e50582c10
Signed by: emma
GPG Key ID: 6D661C738815E7DD

35
yt
View File

@ -39,8 +39,9 @@ archive() { # archives a video to the Wayback Machine
| jq .archived_snapshots.closest.url \ | jq .archived_snapshots.closest.url \
| tr -d '"' | sed 's/^http:/https:/g')" | 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 curl -s -d "url=$1" https://web.archive.org/{url} >/dev/null
shift shift
done done
@ -56,16 +57,14 @@ cache() { # cache the video title for faster retrieval
clone() { # clones a YouTube playlist to a file clone() { # clones a YouTube playlist to a file
yt-dlp --flat-playlist "$1" --print url > "$2" yt-dlp --flat-playlist "$1" --print url > "$2"
verify "$2.m3u" verify "$2"
for line in $(cat "$2.m3u") for line in "$(cat "$2")"; do # uuoc but necessary :3
do
if test -n "$(printf '%s\n' "$line" \ if test -n "$(printf '%s\n' "$line" \
| sed -n -e '/web\.archive\.org/p' -e '/^\#/p')" | grep -e 'web\.archive\.org' -e '^#')"
then then
continue continue
fi else
printf "%s: %s: Saving video to the Wayback Machine.\n" "$argv0" "$1" 1>&2
archive "$line" archive "$line"
fi fi
done 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 pick() { # Pick a video to play from a list of videos
while test -n "$1"; do 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')" if test -n "$(printf '%s\n' "$line" | sed -n '/^\#/p')"
then then
continue continue
@ -122,10 +121,9 @@ usage() {
verify() { # replaces videos with archived versions if they are not available verify() { # replaces videos with archived versions if they are not available
while test -n "$1"; do while test -n "$1"; do
for video in $(cat "$1"); do for video in $(cat "$1"); do # see ln 62
# test for unavailability
if test -n "$(yt-dlp -s "$video" 2>&1 \ 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 then
printf "%s: %s: Video unavailable.\n" "$argv0" "$video" 1>&2 printf "%s: %s: Video unavailable.\n" "$argv0" "$video" 1>&2
@ -134,24 +132,25 @@ verify() { # replaces videos with archived versions if they are not available
| sed 's/^http:/https:/g')" | sed 's/^http:/https:/g')"
if [ "$wayback_url" = "null" ] \ 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 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 "$argv0" "$video" 1>&2
# replace the video link with a comment containing link # 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" printf '%s\n' "$content" > "$1"
else else
printf "%s: %s: Replacing link with Wayback link.\n" \ printf "%s: %s: Replacing link with Wayback link.\n" \
"$argv0" "$video" 1>&2 "$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" printf '%s\n' "$content" >"$1"
cache "$wayback_url" cache "$wayback_url"
fi fi
else else
printf '%s: %s: Video available.\n' "$argv0" "$video" 1>&2
cache "$video" cache "$video"
fi fi
done done
@ -167,6 +166,10 @@ cachefile="$XDG_CACHE_HOME/yt.cache"
FMT='%(title)s %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]' FMT='%(title)s %(channel)s (%(duration>%H:%M:%S)s) [%(webpage_url)s]'
WBAPI='https://archive.org/wayback/available?url=' WBAPI='https://archive.org/wayback/available?url='
if test -n "$DEBUG"; then
set -x
fi
for dep in \ for dep in \
curl \ curl \
fzf \ fzf \