bgneal@60: """ bgneal@60: Quick & dirty Python script to retrieve the video IDs of all the videos in a bgneal@60: playlist on YouTube. bgneal@60: bgneal@60: """ bgneal@60: import urlparse bgneal@60: bgneal@60: from gdata.youtube.service import YouTubeService bgneal@60: bgneal@60: bgneal@60: PLAYLIST_ID = '26E22C14D94D323F' bgneal@60: bgneal@60: yt = YouTubeService() bgneal@60: feed = yt.GetYouTubePlaylistVideoFeed(playlist_id=PLAYLIST_ID) bgneal@60: bgneal@60: print "Feed contains %s videos" % feed.total_results.text bgneal@60: bgneal@60: vids = [] bgneal@60: while True: bgneal@60: vids.extend(feed.entry) bgneal@60: next_link = feed.GetNextLink() bgneal@60: if not next_link: bgneal@60: break bgneal@60: feed = yt.Query(next_link.href) bgneal@60: bgneal@60: print "Got %d videos" % len(vids) bgneal@60: bgneal@60: vid_ids = [] bgneal@60: problems = [] bgneal@60: for vid in vids: bgneal@60: for link in vid.link: bgneal@60: url_data = urlparse.urlparse(link.href) bgneal@60: query = urlparse.parse_qs(url_data.query) bgneal@60: if 'v' in query: bgneal@60: vid_ids.append(query['v'][0]) bgneal@60: break bgneal@60: else: bgneal@60: print "Video id not found for %s" % vid.title.text bgneal@60: bgneal@60: video_id = vid_ids[0] bgneal@60: playlist = vid_ids[1:] bgneal@60: bgneal@60: print "videoId: '%s'," % video_id bgneal@60: print "playerVars: { playlist: [ %s ] }," % ','.join("'%s'" % v for v in bgneal@60: playlist)