combine all 3 youtube API queries in to one (for speed!)
This commit is contained in:
parent
0d4ddb709e
commit
d8ea5e9ce8
1 changed files with 9 additions and 9 deletions
|
@ -27,8 +27,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
def on_load(self):
|
||||||
self.exports.add("search-youtube", self._search_youtube)
|
self.exports.add("search-youtube", self._search_youtube)
|
||||||
|
|
||||||
def get_video_page(self, video_id, part):
|
def get_video_page(self, video_id):
|
||||||
return utils.http.request(URL_YOUTUBEVIDEO, get_params={"part": part,
|
return utils.http.request(URL_YOUTUBEVIDEO, get_params={
|
||||||
|
"part": "contentDetails,snippet,statistics",
|
||||||
"id": video_id, "key": self.bot.config["google-api-key"]},
|
"id": video_id, "key": self.bot.config["google-api-key"]},
|
||||||
json=True)
|
json=True)
|
||||||
|
|
||||||
|
@ -37,13 +38,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
return "{:,}".format(int(n))
|
return "{:,}".format(int(n))
|
||||||
|
|
||||||
def video_details(self, video_id):
|
def video_details(self, video_id):
|
||||||
snippet = self.get_video_page(video_id, "snippet")
|
page = self.get_video_page(video_id)
|
||||||
if snippet.data["items"]:
|
if page.data["items"]:
|
||||||
snippet = snippet.data["items"][0]["snippet"]
|
item = page.data["items"][0]
|
||||||
statistics = self.get_video_page(video_id, "statistics").data[
|
snippet = item["snippet"]
|
||||||
"items"][0]["statistics"]
|
statistics = item["statistics"]
|
||||||
content = self.get_video_page(video_id, "contentDetails").data[
|
content = item["contentDetails"]
|
||||||
"items"][0]["contentDetails"]
|
|
||||||
|
|
||||||
video_uploaded_at = utils.datetime.iso8601_parse(
|
video_uploaded_at = utils.datetime.iso8601_parse(
|
||||||
snippet["publishedAt"], microseconds=True)
|
snippet["publishedAt"], microseconds=True)
|
||||||
|
|
Loading…
Reference in a new issue