From affd72aca04eadc3045e18465ab0fa86734b2698 Mon Sep 17 00:00:00 2001 From: Andrew Gioia Date: Fri, 3 Feb 2023 15:41:10 +0000 Subject: [PATCH] Creates first version of playlists.sh bash file that downloads new videos from set YouTube playlists Requires yt-dlp and will check (and update) playlists.archive to make sure it doesn't download duplicates. Make sure to update the arrays with playlist labels and YouTube hash IDs. --- Shell/playlists.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Shell/playlists.sh diff --git a/Shell/playlists.sh b/Shell/playlists.sh new file mode 100644 index 0000000..95142a1 --- /dev/null +++ b/Shell/playlists.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +NOW=`date +"%Y-%m-%d %T"` + +# move to NAS temp directory +cd "/mnt/media/tmp" + +# count existing MP4 files +EXISTING=$(find ./ -maxdepth 1 -type f -name "*.mp4" -printf x | wc -c) + +# download playlist updates +declare -a LABELS=("..." "..." "...") +declare -a LISTS=("Hash1" "Hash2" "Hash3") +length=${#LISTS[@]} + +for (( i=0; i<${length}; i++ )); do + echo "Checking ${LABELS[$i]} (${LISTS[$i]}) for new videos..." >> downloads.log + yt-dlp "${LISTS[$i]}" --no-flat-playlist --force-download-archive --download-archive playlists.archive --throttled-rate 2M --embed-thumbnail --write-thumbnail --convert-thumbnails png -o "%(channel)s - %(title)s [%(upload_date)s] [%(id)s].%(ext)s" -f bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/bv*+ba/b >>ytdlp.log 2>&1 + echo "Done checking ${LABELS[$i]} for new videos." >> downloads.log +done +echo "Finished running yt-dlp" + +# convert any WEBP thumbs that didn't make it to PNG +for FILE in *.webp; do + if [ "$FILE" ]; then + break + fi + dwebp "$FILE" -o "${FILE%.*}".png; +done + +# count new total of MP4 files and get difference +TOTAL=$(find ./ -maxdepth 1 -type f -name "*.mp4" -printf x | wc -c) +ADDED=$((TOTAL-EXISTING)) + +# write results to log +printf '[%s] %s videos downloaded\n' "$NOW" "$ADDED" >> downloads.log \ No newline at end of file