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

37
yt
View File

@ -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 \