comparison tools/get_vids.py @ 60:a0d3bc630ebd

For issue #8, create a videos application to randomize videos in the playlist. This commit now adds a dependency to the Google Python GData library. The admin enters a playlist URL in the admin. Then the admin uses an admin action to synchronize the playlist with YouTube. This reads the playlist title and retrieves the video list from YouTube. The view function reads all the playlist objects to get the complete list of videos, then shuffles them up. The template generates Javascript to create a YouTube player with the shuffled list. A fixture is included for convenience and for the tests. I also committed a test tool I wrote to prove out this idea in case it is useful for future enhancements or experimentation.
author Brian Neal <bgneal@gmail.com>
date Sat, 19 Nov 2011 14:19:00 -0600
parents
children
comparison
equal deleted inserted replaced
59:f8858447adda 60:a0d3bc630ebd
1 """
2 Quick & dirty Python script to retrieve the video IDs of all the videos in a
3 playlist on YouTube.
4
5 """
6 import urlparse
7
8 from gdata.youtube.service import YouTubeService
9
10
11 PLAYLIST_ID = '26E22C14D94D323F'
12
13 yt = YouTubeService()
14 feed = yt.GetYouTubePlaylistVideoFeed(playlist_id=PLAYLIST_ID)
15
16 print "Feed contains %s videos" % feed.total_results.text
17
18 vids = []
19 while True:
20 vids.extend(feed.entry)
21 next_link = feed.GetNextLink()
22 if not next_link:
23 break
24 feed = yt.Query(next_link.href)
25
26 print "Got %d videos" % len(vids)
27
28 vid_ids = []
29 problems = []
30 for vid in vids:
31 for link in vid.link:
32 url_data = urlparse.urlparse(link.href)
33 query = urlparse.parse_qs(url_data.query)
34 if 'v' in query:
35 vid_ids.append(query['v'][0])
36 break
37 else:
38 print "Video id not found for %s" % vid.title.text
39
40 video_id = vid_ids[0]
41 playlist = vid_ids[1:]
42
43 print "videoId: '%s'," % video_id
44 print "playerVars: { playlist: [ %s ] }," % ','.join("'%s'" % v for v in
45 playlist)