Skip to content

Instantly share code, notes, and snippets.

@ChronoMonochrome
Last active September 9, 2020 14:46
Show Gist options
  • Save ChronoMonochrome/3816cfd4d8c274d45e9feb4a985f79d2 to your computer and use it in GitHub Desktop.
Save ChronoMonochrome/3816cfd4d8c274d45e9feb4a985f79d2 to your computer and use it in GitHub Desktop.
Script to synchronize all youtube playlists to a disk
#/usr/bin/bash
OLDIFS=$IFS
IFS=$'\n'
NR_MAX_JOBS=4
#https://stackoverflow.com/questions/1537956/bash-limit-the-number-of-concurrent-jobs
waitforjobs() {
while test $(jobs -p | wc -w) -ge "$1"; do wait -n; done
}
for line in $(grep "playlist?list" playlists.html); do
name=$(echo $line | cut -d "\"" -f 10);
list="https://www.youtube.com$(echo $line | cut -d "\"" -f 12)";
waitforjobs $NR_MAX_JOBS
{
echo $name;
mkdir -p "$name"
cd "$name"
youtube-dl -f bestvideo+bestaudio -i "$list"
cd ..
} &
done
IFS=$OLDIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment