#!/bin/sh set -eu export DEFAULT_PLAYLIST_END=15 export DEFAULT_INC_STEP=10 export YT_TEMPLATE="${HOME}/Downloads/yt-dl/%(uploader)s/%(upload_date)s %(title)s.%(ext)s" download() { youtube-dl "$1" \ --download-archive ~/archive/youtube-dl-seen.conf \ --prefer-free-formats \ --playlist-end "$2" \ --write-description \ --output "$YT_TEMPLATE" } download_user() { download "https://www.youtube.com/user/$1" "${2-$DEFAULT_PLAYLIST_END}" } download_channel() { download "https://www.youtube.com/channel/$1" "${2-$DEFAULT_PLAYLIST_END}" } download_playlist() { download "https://www.youtube.com/playlist?list=$1" "${2-$DEFAULT_PLAYLIST_END}" } inc_download() { fn="$1" id="$2" step="${3-$DEFAULT_INC_STEP}" file="$HOME/.yt-db/$id" mkdir -p "$HOME/.yt-db" cat "$file" 2> /dev/null n_count="$(cat "$file" 2> /dev/null || printf 10)" n_count_new="$((n_count + step))" echo "$n_count_new" > "$file" "$fn" "$id" "$n_count" } # Always downloads video, doesn't look at the download-archive URL_OR_PATH="${1:-}" [ -z "${URL_OR_PATH}" ] && { # shellcheck disable=2016 echo 'Input "$URL_OR_PATH" is undefined.' > /dev/stderr exit 2 } if [ -f "${URL_OR_PATH}" ]; then echo "File '${URL_OR_PATH}' exists, loading URLs from it..." > /dev/stderr youtube-dl --batch-file "${URL_OR_PATH}" \ --format best \ --output "${YT_TEMPLATE}" \ --write-description \ 1>&2 FILES="$(youtube-dl --batch-file "${URL_OR_PATH}" \ --output "${YT_TEMPLATE}" \ --format best \ --get-filename)" else echo "File '${URL_OR_PATH}' doesn't exist, treating it as an URL..." > /dev/stderr youtube-dl "${URL_OR_PATH}" \ --output "${YT_TEMPLATE}" \ --format best \ --write-description \ 1>&2 FILES="$(youtube-dl "${URL_OR_PATH}" \ --output "${YT_TEMPLATE}" \ --format best \ --get-filename)" fi for f in $FILES; do vlc "$f" done