diff options
| author | 2019-11-18 10:55:18 +0000 | |
|---|---|---|
| committer | 2019-11-18 10:55:18 +0000 | |
| commit | d1c8357f97855b4e2e7b88844b986d07ddc4566e (patch) | |
| tree | bb013aa5a463e2e2544f49e16468a5dc00c68cd3 | |
| parent | handle a youtube video having no reported views (diff) | |
| signature | ||
combine both youtube API queries for playlists in to 1 query
| -rw-r--r-- | modules/youtube.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/modules/youtube.py b/modules/youtube.py index 57ca98a6..cf3f7d04 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -85,17 +85,18 @@ class Module(ModuleManager.BaseModule): video_views_str, video_opinions), url return None - def get_playlist_page(self, playlist_id, part): + def get_playlist_page(self, playlist_id): return utils.http.request(URL_YOUTUBEPLAYLIST, get_params={ - "part": part, "id": playlist_id, + "part": "contentDetails,snippet", "id": playlist_id, "key": self.bot.config["google-api-key"]}, json=True) def playlist_details(self, playlist_id): - snippet = self.get_playlist_page(playlist_id, "snippet") - if snippet.data["items"]: - snippet = snippet.data["items"][0]["snippet"] + page = self.get_playlist_page(playlist_id) + if page.data["items"]: + item = page.data["items"][0] + snippet = item["snippet"] + content = item["contentDetails"] - content = self.get_playlist_page(playlist_id, "contentDetails") - count = content.data["items"][0]["contentDetails"]["itemCount"] + count = content["itemCount"] return "%s - %s (%s %s)" % (snippet["channelTitle"], snippet["title"], count, "video" if count == 1 else "videos" |
