mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-26 04:33:00 -05:00
First commit - Bring everything from dev cog minus NSFW support
This commit is contained in:
@@ -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']}"
|
||||
|
||||
Reference in New Issue
Block a user