Skip to content

Instantly share code, notes, and snippets.

@cxbig
Last active October 19, 2020 02:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cxbig/9be30a906b4f3ad810b564003d14e36c to your computer and use it in GitHub Desktop.
Save cxbig/9be30a906b4f3ad810b564003d14e36c to your computer and use it in GitHub Desktop.
Simultaneous downloading YouTube video list
function youtube-dl-list {
if [[ -z $1 ]]; then
echo 'Please provide list key'
return 1
fi
local simultaneous=5
local list_url="https://www.youtube.com/playlist?list=$1"
for item in `youtube-dl -F $list_url | grep -E '\[youtube\].*Downloading webpage' | sed -E 's/[^ ]* ([^\:]*):.*/\1/'`; do
while [[ "$((`ps aux | grep 'no-warning' | wc -l`))" -gt $simultaneous ]]; do
sleep 5
done
local video_url="https://www.youtube.com/watch?v=$item"
youtube-dl -q -i --no-warnings --ffmpeg-location 'youtube-dl -d $*' -o '%(id)s.%(ext)s' $video_url &
done
}
@cxbig
Copy link
Author

cxbig commented Sep 20, 2016

How to use:

  1. Source this file OR put this function in somewhere could be preload by bash
  2. Run this command to download youtube video list
youtube-dl-list LIST_KEY

Sample:

# one list link : https://www.youtube.com/playlist?list=PLLnpHn493BHFfs3Uj5tvx17mXk4B4ws4p
youtube-dl-list PLLnpHn493BHFfs3Uj5tvx17mXk4B4ws4p

PS: you can change the concurrent task amount in L:7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment