diff --git a/youtube_api.py b/youtube_api.py index 54964eb..4f84326 100644 --- a/youtube_api.py +++ b/youtube_api.py @@ -19,9 +19,9 @@ class YouTubeAPI(object): def getVideo(self, part, id): return self.getRequest('videos?part={}&id={}'.format(part, id)) - def getVideoInfo(self, tag): - snippet = self.getVideo('snippet', tag) - status = self.getVideo('status', tag) + def getVideoInfo(self, id): + snippet = self.getVideo('snippet', id) + status = self.getVideo('status', id) snippet = snippet['items'][0]['snippet'] status = status['items'][0]['status'] title = snippet['title'] @@ -34,7 +34,7 @@ class YouTubeAPI(object): except: tags = '' privacy = status['privacyStatus'] - return title, date, channel, channelId, description, tags, privacy + return title, date, channel, channelId, description, tags, privacy, id def getPlaylist(self, id, pageToken=''): if(pageToken): diff --git a/yt-unlist-saver.py b/yt-unlist-saver.py index cf7f29e..7900548 100644 --- a/yt-unlist-saver.py +++ b/yt-unlist-saver.py @@ -17,6 +17,9 @@ def getYear(info): def getPrivacy(info): return info[6] +def getId(info): + return info[7] + # Print out information about a video. def printVideoInfo(info): title, date, channel, channelId, description, tags, privacy = info @@ -33,5 +36,8 @@ 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] +ydl_opts = {} for v in filteredVideos: - print(getYear(v)) + print(getYear(v), getId(v)) + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + ydl.download(['https://www.youtube.com/watch?v='+getId(v)])