Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Commit
โข
1e3100b
1
Parent(s):
7fb25b8
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import discord
|
2 |
import logging
|
3 |
-
import os
|
4 |
import re
|
5 |
import asyncio
|
6 |
import subprocess
|
7 |
from huggingface_hub import InferenceClient
|
8 |
-
from googleapiclient.discovery import build
|
9 |
-
from google.oauth2.credentials import Credentials
|
10 |
-
from google_auth_oauthlib.flow import InstalledAppFlow
|
11 |
-
from google.auth.transport.requests import Request
|
12 |
from youtube_transcript_api import YouTubeTranscriptApi
|
13 |
from youtube_transcript_api.formatters import TextFormatter
|
14 |
from dotenv import load_dotenv
|
@@ -19,6 +19,7 @@ load_dotenv()
|
|
19 |
# JSON_TOKEN.json ํ์ผ์ ๊ฒฝ๋ก
|
20 |
credentials_path = 'JSON_TOKEN.json'
|
21 |
token_path = 'token.json'
|
|
|
22 |
|
23 |
# ๋ก๊น
์ค์
|
24 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
|
@@ -38,33 +39,45 @@ SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
|
38 |
creds = None
|
39 |
|
40 |
def authorize():
|
41 |
-
flow = InstalledAppFlow.from_client_secrets_file(
|
|
|
42 |
auth_url, _ = flow.authorization_url(prompt='consent')
|
43 |
print('Please go to this URL and finish the authentication: {}'.format(auth_url))
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
|
48 |
flow.fetch_token(code=code)
|
49 |
creds = flow.credentials
|
|
|
50 |
with open(token_path, 'w') as token:
|
51 |
token.write(creds.to_json())
|
|
|
52 |
return creds
|
53 |
|
|
|
54 |
if os.path.exists(token_path):
|
55 |
creds = Credentials.from_authorized_user_file(token_path, SCOPES)
|
56 |
else:
|
57 |
creds = authorize()
|
58 |
|
|
|
59 |
if not creds or not creds.valid:
|
60 |
if creds and creds.expired and creds.refresh_token:
|
61 |
creds.refresh(Request())
|
62 |
else:
|
63 |
creds = authorize()
|
64 |
|
|
|
65 |
youtube_service = build('youtube', 'v3', credentials=creds)
|
66 |
|
67 |
-
#
|
68 |
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
69 |
|
70 |
class MyClient(discord.Client):
|
|
|
1 |
+
import os
|
2 |
+
import google_auth_oauthlib.flow
|
3 |
+
from google.oauth2.credentials import Credentials
|
4 |
+
from googleapiclient.discovery import build
|
5 |
+
from google.auth.transport.requests import Request
|
6 |
import discord
|
7 |
import logging
|
|
|
8 |
import re
|
9 |
import asyncio
|
10 |
import subprocess
|
11 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
12 |
from youtube_transcript_api import YouTubeTranscriptApi
|
13 |
from youtube_transcript_api.formatters import TextFormatter
|
14 |
from dotenv import load_dotenv
|
|
|
19 |
# JSON_TOKEN.json ํ์ผ์ ๊ฒฝ๋ก
|
20 |
credentials_path = 'JSON_TOKEN.json'
|
21 |
token_path = 'token.json'
|
22 |
+
auth_code_path = 'auth_code.txt' # ์ธ์ฆ ์ฝ๋๋ฅผ ์ ์ฅํ ํ์ผ ๊ฒฝ๋ก
|
23 |
|
24 |
# ๋ก๊น
์ค์
|
25 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
|
|
|
39 |
creds = None
|
40 |
|
41 |
def authorize():
|
42 |
+
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
|
43 |
+
credentials_path, SCOPES)
|
44 |
auth_url, _ = flow.authorization_url(prompt='consent')
|
45 |
print('Please go to this URL and finish the authentication: {}'.format(auth_url))
|
46 |
+
|
47 |
+
print(f'Enter the authorization code in the file {auth_code_path} and press Enter')
|
48 |
+
input('Press Enter after saving the authorization code...')
|
49 |
+
|
50 |
+
if not os.path.exists(auth_code_path):
|
51 |
+
raise FileNotFoundError(f"'{auth_code_path}' ํ์ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค.")
|
52 |
|
53 |
+
with open(auth_code_path, 'r') as file:
|
54 |
+
code = file.read().strip()
|
55 |
|
56 |
flow.fetch_token(code=code)
|
57 |
creds = flow.credentials
|
58 |
+
|
59 |
with open(token_path, 'w') as token:
|
60 |
token.write(creds.to_json())
|
61 |
+
|
62 |
return creds
|
63 |
|
64 |
+
# ๊ธฐ์กด ํ ํฐ์ ๋ก๋ํ๊ฑฐ๋ ์๋ก ์ธ์ฆ
|
65 |
if os.path.exists(token_path):
|
66 |
creds = Credentials.from_authorized_user_file(token_path, SCOPES)
|
67 |
else:
|
68 |
creds = authorize()
|
69 |
|
70 |
+
# ํ ํฐ ๊ฐฑ์ ๋๋ ์ฌ์ธ์ฆ
|
71 |
if not creds or not creds.valid:
|
72 |
if creds and creds.expired and creds.refresh_token:
|
73 |
creds.refresh(Request())
|
74 |
else:
|
75 |
creds = authorize()
|
76 |
|
77 |
+
# YouTube API ํด๋ผ์ด์ธํธ ์์ฑ
|
78 |
youtube_service = build('youtube', 'v3', credentials=creds)
|
79 |
|
80 |
+
# ๋์ค์ฝ๋ ๋ด ์ค์
|
81 |
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
82 |
|
83 |
class MyClient(discord.Client):
|