Last active
September 9, 2020 14:46
-
-
Save ChronoMonochrome/3816cfd4d8c274d45e9feb4a985f79d2 to your computer and use it in GitHub Desktop.
Script to synchronize all youtube playlists to a disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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