code organization and fix for comments
This commit is contained in:
parent
3e50582c10
commit
b83408a453
33
yt
33
yt
@ -22,7 +22,7 @@ add() { # adds a video to a playlist file
|
|||||||
while test -n "$2"; do
|
while test -n "$2"; do
|
||||||
if test -z "$(sed -n ";$1;p" "$2")"
|
if test -z "$(sed -n ";$1;p" "$2")"
|
||||||
then
|
then
|
||||||
printf "%s: %s: Video already in playlist.\n" "$argv0" "$1"
|
printf "%s: %s: %s: Video already in playlist.\n" "$argv0" "$2" "$1"
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
archive "$1"
|
archive "$1"
|
||||||
@ -35,14 +35,21 @@ add() { # adds a video to a playlist file
|
|||||||
|
|
||||||
archive() { # archives a video to the Wayback Machine
|
archive() { # archives a video to the Wayback Machine
|
||||||
while test -n "$1"; do
|
while test -n "$1"; do
|
||||||
|
if test -n "$(printf '%s\n' "$1" | grep -e 'web\.archive\.org')"
|
||||||
|
then
|
||||||
|
shift
|
||||||
|
continue
|
||||||
|
else
|
||||||
wayback_url="$(curl -s "$WBAPI$1" \
|
wayback_url="$(curl -s "$WBAPI$1" \
|
||||||
| 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
|
# skips archiving on the Wayback Machine if the video has a snapshot
|
||||||
|
if [ "$wayback_url" != "null" ]; then shift; continue; fi
|
||||||
|
|
||||||
printf "%s: %s: Saving video to the Wayback Machine.\n" "$argv0" "$1" 1>&2
|
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
|
||||||
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -58,15 +65,12 @@ 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"
|
verify "$2"
|
||||||
|
}
|
||||||
|
|
||||||
for line in "$(cat "$2")"; do # uuoc but necessary :3
|
lines() {
|
||||||
if test -n "$(printf '%s\n' "$line" \
|
while test -n "$1"; do
|
||||||
| grep -e 'web\.archive\.org' -e '^#')"
|
sed 's/#.*$//g' "$1"
|
||||||
then
|
shift
|
||||||
continue
|
|
||||||
else
|
|
||||||
archive "$line"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +85,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 # see ln 62
|
for line in $(lines "$1"); do
|
||||||
if test -n "$(printf '%s\n' "$line" | sed -n '/^\#/p')"
|
if test -n "$(printf '%s\n' "$line" | sed -n '/^\#/p')"
|
||||||
then
|
then
|
||||||
continue
|
continue
|
||||||
@ -121,9 +125,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 # see ln 62
|
for video in $(lines "$1"); do
|
||||||
if test -n "$(yt-dlp -s "$video" 2>&1 \
|
if test -n "$(yt-dlp -s "$video" 2>&1 \
|
||||||
| grep -i -e 'video unavailable.' -e 'private video')"
|
| grep -i -e 'video unavailable' -e 'private video' -e 'been removed')"
|
||||||
then
|
then
|
||||||
printf "%s: %s: Video unavailable.\n" "$argv0" "$video" 1>&2
|
printf "%s: %s: Video unavailable.\n" "$argv0" "$video" 1>&2
|
||||||
|
|
||||||
@ -137,7 +141,7 @@ verify() { # replaces videos with archived versions if they are not available
|
|||||||
printf "%s: %s: Video 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 file
|
# write the new content buffer to file
|
||||||
printf '%s\n' "$content" > "$1"
|
printf '%s\n' "$content" > "$1"
|
||||||
@ -152,6 +156,7 @@ verify() { # replaces videos with archived versions if they are not available
|
|||||||
else
|
else
|
||||||
printf '%s: %s: Video available.\n' "$argv0" "$video" 1>&2
|
printf '%s: %s: Video available.\n' "$argv0" "$video" 1>&2
|
||||||
cache "$video"
|
cache "$video"
|
||||||
|
archive "$video"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user