combine both youtube API queries for playlists in to 1 query
This commit is contained in:
parent
15e5d7d9bc
commit
d1c8357f97
1 changed files with 8 additions and 7 deletions
|
@ -85,17 +85,18 @@ class Module(ModuleManager.BaseModule):
|
||||||
video_views_str, video_opinions), url
|
video_views_str, video_opinions), url
|
||||||
return None
|
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={
|
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)
|
"key": self.bot.config["google-api-key"]}, json=True)
|
||||||
def playlist_details(self, playlist_id):
|
def playlist_details(self, playlist_id):
|
||||||
snippet = self.get_playlist_page(playlist_id, "snippet")
|
page = self.get_playlist_page(playlist_id)
|
||||||
if snippet.data["items"]:
|
if page.data["items"]:
|
||||||
snippet = snippet.data["items"][0]["snippet"]
|
item = page.data["items"][0]
|
||||||
|
snippet = item["snippet"]
|
||||||
|
content = item["contentDetails"]
|
||||||
|
|
||||||
content = self.get_playlist_page(playlist_id, "contentDetails")
|
count = content["itemCount"]
|
||||||
count = content.data["items"][0]["contentDetails"]["itemCount"]
|
|
||||||
|
|
||||||
return "%s - %s (%s %s)" % (snippet["channelTitle"],
|
return "%s - %s (%s %s)" % (snippet["channelTitle"],
|
||||||
snippet["title"], count, "video" if count == 1 else "videos"
|
snippet["title"], count, "video" if count == 1 else "videos"
|
||||||
|
|
Loading…
Reference in a new issue