Get a list of videos from a playlist
This commit is contained in:
parent
f0dbb580b2
commit
1f5eaa231a
@ -33,4 +33,16 @@ class YouTubeAPI(object):
|
||||
privacy = status['privacyStatus']
|
||||
return title, date, channel, channelId, description, tags, privacy
|
||||
|
||||
|
||||
def getPlaylist(self, id, pageToken=''):
|
||||
if(pageToken):
|
||||
pageToken = '&pageToken={}'.format(pageToken)
|
||||
return self.getRequest('playlistItems?part=snippet&maxResults=50&playlistId={}{}'.format(id,
|
||||
pageToken))
|
||||
|
||||
def getPlaylistVideos(self, id):
|
||||
playlist = self.getPlaylist(id)
|
||||
items = playlist['items']
|
||||
while 'nextPageToken' in playlist:
|
||||
playlist = self.getPlaylist(id, playlist['nextPageToken'])
|
||||
items.extend(playlist['items'])
|
||||
return items
|
||||
|
@ -3,15 +3,19 @@
|
||||
from youtube_api import YouTubeAPI
|
||||
import sys
|
||||
|
||||
# Read YouTube API Key
|
||||
# Read YouTube API Key.
|
||||
def getYouTubeAPIKey():
|
||||
return open('youtube.key', 'r').read()
|
||||
|
||||
# Print out information about a video.
|
||||
def printVideoInfo(info):
|
||||
title, date, channel, channelId, description, tags, privacy = info
|
||||
print('Title: ' + title)
|
||||
print('Date: ' + date)
|
||||
print('Channel: {} ({})'.format(channel, channelId) )
|
||||
print('Description: ' + description)
|
||||
print('Tags: ', tags)
|
||||
print('Privacy: ' + privacy)
|
||||
|
||||
api = YouTubeAPI(getYouTubeAPIKey())
|
||||
title, date, channel, channelId, description, tags, privacy = api.getVideoInfo(sys.argv[1])
|
||||
print('Title: ' + title)
|
||||
print('Date: ' + date)
|
||||
print('Channel: {} ({})'.format(channel, channelId) )
|
||||
print('Description: ' + description)
|
||||
print('Tags: ', tags)
|
||||
print('Privacy: ' + privacy)
|
||||
print(len(api.getPlaylistVideos(sys.argv[1])))
|
||||
|
Loading…
x
Reference in New Issue
Block a user