First commit - Bring everything from dev cog minus NSFW support

This commit is contained in:
Drapersniper
2020-09-25 16:58:31 +01:00
parent a6ff5b8e9c
commit 8e70b4cd59
39 changed files with 1321 additions and 243 deletions

View File

@@ -1,5 +1,7 @@
import json
import logging
from typing import Mapping, Optional, TYPE_CHECKING, Union
from typing import TYPE_CHECKING, Mapping, Optional, Union
import aiohttp
@@ -33,15 +35,17 @@ class YouTubeWrapper:
def update_token(self, new_token: Mapping[str, str]):
self._token = new_token
async def _get_api_key(self) -> str:
"""Get the stored youtube token"""
async def _get_api_key(
self,
) -> str:
"""Get the stored youtube token."""
if not self._token:
self._token = await self.bot.get_shared_api_tokens("youtube")
self.api_key = self._token.get("api_key", "")
return self.api_key if self.api_key is not None else ""
async def get_call(self, query: str) -> Optional[str]:
"""Make a Get call to youtube data api"""
"""Make a Get call to youtube data api."""
params = {
"q": query,
"part": "id",
@@ -57,7 +61,7 @@ class YouTubeWrapper:
raise YouTubeApiError("Your YouTube Data API quota has been reached.")
return None
else:
search_response = await r.json()
search_response = await r.json(loads=json.loads)
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
return f"https://www.youtube.com/watch?v={search_result['id']['videoId']}"