Compare commits

...

2 Commits

2 changed files with 45 additions and 10 deletions

@ -29,8 +29,23 @@ class YouTubeAPI(object):
channel = snippet['channelTitle']
channelId = snippet['channelId']
description = snippet['description']
tags = snippet['tags']
try:
tags = snippet['tags']
except:
tags = ''
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

@ -2,16 +2,36 @@
from youtube_api import YouTubeAPI
import sys
import youtube_dl
# Read YouTube API Key
# Read YouTube API Key.
def getYouTubeAPIKey():
return open('youtube.key', 'r').read()
def getUploadTime(info):
return info[1]
def getYear(info):
return int(getUploadTime(info)[:4])
def getPrivacy(info):
return info[6]
# 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)
videos = api.getPlaylistVideos(sys.argv[1])
videoInfo = [api.getVideoInfo(video['snippet']['resourceId']['videoId']) for video in videos]
filteredVideos = [video for video in videoInfo if getPrivacy(video) == 'unlisted' and getYear(video) <= 2017]
for v in filteredVideos:
print(getYear(v))