diff --git a/youtube_api.py b/youtube_api.py index 0dfbf60..54964eb 100644 --- a/youtube_api.py +++ b/youtube_api.py @@ -29,7 +29,10 @@ 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 diff --git a/yt-unlist-saver.py b/yt-unlist-saver.py index cae6554..cf7f29e 100644 --- a/yt-unlist-saver.py +++ b/yt-unlist-saver.py @@ -2,11 +2,21 @@ from youtube_api import YouTubeAPI import sys +import youtube_dl # 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 @@ -18,4 +28,10 @@ def printVideoInfo(info): print('Privacy: ' + privacy) api = YouTubeAPI(getYouTubeAPIKey()) -print(len(api.getPlaylistVideos(sys.argv[1]))) +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))