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']
|
privacy = status['privacyStatus']
|
||||||
return title, date, channel, channelId, description, tags, privacy
|
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
|
from youtube_api import YouTubeAPI
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Read YouTube API Key
|
# Read YouTube API Key.
|
||||||
def getYouTubeAPIKey():
|
def getYouTubeAPIKey():
|
||||||
return open('youtube.key', 'r').read()
|
return open('youtube.key', 'r').read()
|
||||||
|
|
||||||
api = YouTubeAPI(getYouTubeAPIKey())
|
# Print out information about a video.
|
||||||
title, date, channel, channelId, description, tags, privacy = api.getVideoInfo(sys.argv[1])
|
def printVideoInfo(info):
|
||||||
|
title, date, channel, channelId, description, tags, privacy = info
|
||||||
print('Title: ' + title)
|
print('Title: ' + title)
|
||||||
print('Date: ' + date)
|
print('Date: ' + date)
|
||||||
print('Channel: {} ({})'.format(channel, channelId) )
|
print('Channel: {} ({})'.format(channel, channelId) )
|
||||||
print('Description: ' + description)
|
print('Description: ' + description)
|
||||||
print('Tags: ', tags)
|
print('Tags: ', tags)
|
||||||
print('Privacy: ' + privacy)
|
print('Privacy: ' + privacy)
|
||||||
|
|
||||||
|
api = YouTubeAPI(getYouTubeAPIKey())
|
||||||
|
print(len(api.getPlaylistVideos(sys.argv[1])))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user