#!/usr/bin/env bash
# Desc: Download YouTube videos
# Usage: $ ./bkytpldl-generic
-# Version: 4.0.0
-
-# Adjust me
-dir_out="~/Videos/";
-url_playlist1="https://www.youtube.com/playlist?list=PLxxx";
-url_playlist2="https://www.youtube.com/playlist?list=PLxxx";
-url_playlist3="https://www.youtube.com/playlist?list=PLxxx";
+# Version: 4.1.1
declare -a args; # array for yt-dlp arguments
declare -a urls urls_rand; # array for YouTube playlist URLs
+# Settings
+dir_out="~/Videos/";
+urls+=("https://www.youtube.com/playlist?list=PLxxx"); # Adjust me. YouTube playlist URL goes here
+urls+=("https://www.youtube.com/playlist?list=PLxxx"); # Adjust me. YouTube playlist URL goes here
+urls+=("https://www.youtube.com/playlist?list=PLxxx"); # Adjust me. YouTube playlist URL goes here
+
yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
# Check directories
if [[ ! -d $dir_out ]]; then mkdir -p "$dir_out"; fi;
-# == Download Video ==
+# == Assemble options ==
# yt-dlp output options
## Restrict file name character set
args+=("-S" "res:1080");
## Specify playlist URLs to download
-urls+=("$url_playlist1");
-urls+=("$url_playlist2");
-urls+=("$url_playlist3");
### Shuffle playlist download order
mapfile -t urls_rand < <(printf "%s\n" "${urls[@]}" | shuf);
for url in "${urls_rand[@]}"; do
# Change working directory to output dir
pushd "$dir_out" || die "FATAL:Failed to change pwd to:dir_out:$dir_out";
-# Download videos
+# == Download videos ==
+
#yell "DEBUG:args:$(declare -p args)"; # debug command
must yt-dlp "${args[@]}"; # execute command
popd || die "FATAL:Failed to return from dir_out:$dir_out";