view tools/get_vids.py @ 64:aaac975df679

Tweaking the bxslider's pager CSS. Before, with the images, the numbers > 9 were not centered on their circles. Made an attempt to create circles with CSS instead. The higher numbered ones have kind of a flattened top. Not sure how to fix that right now.
author Brian Neal <bgneal@gmail.com>
date Sat, 19 Nov 2011 16:32:28 -0600
parents a0d3bc630ebd
children
line wrap: on
line source
"""
Quick & dirty Python script to retrieve the video IDs of all the videos in a
playlist on YouTube.

"""
import urlparse

from gdata.youtube.service import YouTubeService


PLAYLIST_ID = '26E22C14D94D323F'

yt = YouTubeService()
feed = yt.GetYouTubePlaylistVideoFeed(playlist_id=PLAYLIST_ID)

print "Feed contains %s videos" % feed.total_results.text

vids = []
while True:
    vids.extend(feed.entry)
    next_link = feed.GetNextLink()
    if not next_link:
        break
    feed = yt.Query(next_link.href)

print "Got %d videos" % len(vids)

vid_ids = []
problems = []
for vid in vids:
    for link in vid.link:
        url_data = urlparse.urlparse(link.href)
        query = urlparse.parse_qs(url_data.query)
        if 'v' in query:
            vid_ids.append(query['v'][0])
            break
    else:
        print "Video id not found for %s" % vid.title.text

video_id = vid_ids[0]
playlist = vid_ids[1:]

print "videoId: '%s'," % video_id
print "playerVars: { playlist: [ %s ] }," % ','.join("'%s'" % v for v in
        playlist)