Skip to content

Instantly share code, notes, and snippets.

@pyokagan
Created October 19, 2012 08:46
Show Gist options
  • Select an option

  • Save pyokagan/3917017 to your computer and use it in GitHub Desktop.

Select an option

Save pyokagan/3917017 to your computer and use it in GitHub Desktop.
Prints URL of all videos in Youtube Playlist. Requires: curl, jshon
#! /bin/bash
if [ -z $1 ]; then
echo "usage: $0 URL" >&2
exit 1
fi
playlistid="$(sed -n 's|https://www\.youtube.com/playlist?list=PL\([A-Z0-9]*\)|\1|p' <<< $1)"
if [ -z "$playlistid" ]; then
echo "Invalid URL" >&2
exit 1
fi
startindex=1
while true; do
#BASH Y U NO ALLOW READ FROM PIPE
content=`curl -s "https://gdata.youtube.com/feeds/api/playlists/$playlistid?v=2&alt=jsonc&start-index=$startindex"`
vars="$(jshon -e data -e startIndex -u -p -e totalItems -u -p -e itemsPerPage -u <<< $content | tr "\n" " " )"
read curstartindex totalitems itemsperpage <<< $vars
jshon -e data -e items -a -e video -e player -e default -u <<< $content
if [ $(( curstartindex + itemsperpage )) -ge $totalitems ]; then
break
fi
((startindex += itemsperpage))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment