diff options
| author | 2019-11-18 10:52:01 +0000 | |
|---|---|---|
| committer | 2019-11-18 10:52:01 +0000 | |
| commit | d8ea5e9ce838a9b6e8e35e7458108255f0514c96 (patch) | |
| tree | 17f8613d8d6deb508e5962bbedf334ea74f530b5 /modules | |
| parent | from_pretty_time was moved to utils.datetime (diff) | |
| signature | ||
combine all 3 youtube API queries in to one (for speed!)
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/youtube.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/modules/youtube.py b/modules/youtube.py index 6d25c3e8..ac15f11e 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -27,8 +27,9 @@ class Module(ModuleManager.BaseModule): def on_load(self): self.exports.add("search-youtube", self._search_youtube) - def get_video_page(self, video_id, part): - return utils.http.request(URL_YOUTUBEVIDEO, get_params={"part": part, + def get_video_page(self, video_id): + return utils.http.request(URL_YOUTUBEVIDEO, get_params={ + "part": "contentDetails,snippet,statistics", "id": video_id, "key": self.bot.config["google-api-key"]}, json=True) @@ -37,13 +38,12 @@ class Module(ModuleManager.BaseModule): return "{:,}".format(int(n)) def video_details(self, video_id): - snippet = self.get_video_page(video_id, "snippet") - if snippet.data["items"]: - snippet = snippet.data["items"][0]["snippet"] - statistics = self.get_video_page(video_id, "statistics").data[ - "items"][0]["statistics"] - content = self.get_video_page(video_id, "contentDetails").data[ - "items"][0]["contentDetails"] + page = self.get_video_page(video_id) + if page.data["items"]: + item = page.data["items"][0] + snippet = item["snippet"] + statistics = item["statistics"] + content = item["contentDetails"] video_uploaded_at = utils.datetime.iso8601_parse( snippet["publishedAt"], microseconds=True) |
