Skip to content

Instantly share code, notes, and snippets.

@kbl
Created February 28, 2013 09:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbl/5055402 to your computer and use it in GitHub Desktop.
Save kbl/5055402 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage() {
echo "Usage: $0 <playlist-id>"
exit 1
}
function download() {
local tempfile=`tempfile` || usage
local formated_tempfile=`tempfile` || usage
curl -s "https://gdata.youtube.com/feeds/api/playlists/$1?max-results=$2&start-index=$3" > $tempfile
xmllint --format $tempfile > $formated_tempfile
rm $tempfile
echo $formated_tempfile
}
function get_number_of_videos() {
number_of_videos=`grep totalResults $1 | sed -re "s/[^[:digit:]]*([[:digit:]]+)[^[:digit:]]*/\1/"`
declare -i number_of_videos
}
function parse_file() {
for line in `grep 'media:player' $1`; do
[ $line == '<media:player' ] && continue
echo `echo $line | cut -d '=' -f 3 | cut -d '&' -f 1`
done
rm $1
}
if [ $# != 1 ]; then usage; fi
max_results=50
index=1
part_one=`download $1 $max_results $index`
get_number_of_videos $part_one
i=1
while [ $index -le $number_of_videos ]
do
file=`download $1 $max_results $index`
for id in `parse_file $file`; do
echo "Downloading $i out of $number_of_videos ($id)"
youtube-dl $id -x --audio-format mp3 -c -i -t
let i+=1
done
let index+=$max_results
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment