-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dff8f54
commit 3e117f5
Showing
3 changed files
with
34 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
from json import loads as json_loads | ||
from os import getenv | ||
|
||
import google_auth_oauthlib.flow | ||
import googleapiclient.discovery | ||
import requests | ||
|
||
|
||
def create_youtube() -> googleapiclient.discovery: | ||
flow = google_auth_oauthlib.flow.InstalledAppFlow. \ | ||
from_client_secrets_file( | ||
getenv('YOUTUBE_CLIENT_SECRET_FILE'), | ||
['https://www.googleapis.com/auth/youtube.force-ssl'] | ||
) | ||
credentials = flow.run_local_server() | ||
youtube = googleapiclient.discovery.build( | ||
'youtube', | ||
'v3', | ||
credentials=credentials | ||
def find_youtube_id(query: str) -> [bool, str]: | ||
yt_r = requests.get( | ||
'https://www.googleapis.com/youtube/v3/search' | ||
'?key={}' | ||
'&part=snippet' | ||
'&maxResults=1' | ||
'&q={}'.format( | ||
# getenv('YOUTUBE_API_KEY'), | ||
'', | ||
query | ||
) | ||
) | ||
return youtube | ||
|
||
|
||
def search_youtube(youtube: googleapiclient.discovery, query: str) -> str: | ||
yt_req = youtube.search().list( | ||
part='snippet', | ||
maxResults=1, | ||
q=query, | ||
type='video' | ||
) | ||
yt_res = yt_req.execute() | ||
return yt_res['items'][0]['id']['videoId'] | ||
content = json_loads(yt_r.content) | ||
breakpoint() | ||
if (error_code := content['error']['code']) == 200: | ||
data = content['items'][0]['id']['videoId'] | ||
elif error_code == 403: | ||
data = 'Bot is not set properly.' \ | ||
' Ask the bot owner for further information.' | ||
else: | ||
data = content['error']['message'] | ||
return [error_code == 200, data] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
discord.py | ||
requests | ||
google-api-python-client | ||
google-auth-oauthlib | ||
google-auth-httplib2 | ||
spotipy |