Skip to content

Instantly share code, notes, and snippets.

@zamnuts
Created November 27, 2021 06:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zamnuts/c53ba6225164bd5d482945ca7f27a498 to your computer and use it in GitHub Desktop.
Save zamnuts/c53ba6225164bd5d482945ca7f27a498 to your computer and use it in GitHub Desktop.
yt-dlp playlist concurrent downloader
#!/usr/bin/env zsh
playlistUrl="$1";
numParallelDownloads="${2:-5}";
numParallelFragments="${3:-5}";
[[ -z "$playlistUrl" ]] && echo 'i need a url to a yt playlist please.' >&2 && exit 1;
[[ "$numParallelDownloads" =~ '^[^0-9]+$' ]] && echo "expected parameter 2 to be the number of parallel downloads, got '$numParallelDownloads'." >&2 && exit 1;
[[ "$numParallelFragments" =~ '^[^0-9]+$' ]] && echo "expected parameter 3 to be the number of parallel fragments, got '$numParallelFragments'." >&2 && exit 1;
echo "Reading playlist, this could take a while depending on the number of items...";
echo "URL: $playlistUrl";
echo "Num Parallel Downloads: $numParallelDownloads";
echo "Num Parallel Fragments: $numParallelFragments";
echo ;
yt-dlp \
--yes-playlist \
--skip-download \
--quiet \
--print '%(id)s' \
"$playlistUrl" \
| xargs \
-I '{}' \
-P "$numParallelDownloads" \
yt-dlp \
--newline \
--embed-metadata \
--write-subs \
--convert-subs srt \
--concurrent-fragments "$numParallelFragments" \
--format 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' \
'{}';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment