From 209f38200a1c71f1440f607e857a869627c62622 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 3 Nov 2023 15:31:56 -0600 Subject: [PATCH] stop rate limiting me web archive >:( --- README | 5 ++++- yt | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README b/README index 9e78727..a3ba27b 100644 --- a/README +++ b/README @@ -9,11 +9,14 @@ Dependencies: - yt-dlp(1) Usage: -yt add | clone | music | pick | play | verify +yt add | archive | cache | clone | music | pick | play | queue | verify add uri file - Adds a video by URI to a playlist +archive uri... +- Archives a video on the Wayback Machine + cache uri... - Caches a video title diff --git a/yt b/yt index ab8d572..82fccf2 100755 --- a/yt +++ b/yt @@ -35,6 +35,12 @@ add() { # adds a video to a playlist file archive() { # archives a video to the Wayback Machine while test -n "$1"; do + wayback_url="$(curl -s "$WBAPI$1" \ + | jq .archived_snapshots.closest.url \ + | tr -d '"' | sed 's/^http:/https:/g')" + + if [ "$wayback_url" != "null" ]; then continue fi + curl -s -d "url=$1" https://web.archive.org/{url} >/dev/null shift done @@ -58,7 +64,8 @@ clone() { # clones a YouTube playlist in m3u format | sed -n -e '/web\.archive\.org/p' -e '/^\#/p')" then continue - else + fi + printf "%s: %s: Saving video to the Wayback Machine.\n" "$argv0" "$1" 1>&2 archive "$line" fi done @@ -177,6 +184,10 @@ case "$com" in shift 2>/dev/null || usage 'add uri file' add "$@" ;; + archive) + shift 2>/dev/null || usage 'archive uri...' + archive "$@" + ;; cache) shift 2>/dev/null || usage 'cache uri...' cache "$@"