Spaces:
Sleeping
Sleeping
Create youtube.app
Browse files- youtube.app +40 -0
youtube.app
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from googleapiclient.discovery import build
|
3 |
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
4 |
+
from google.oauth2.credentials import Credentials
|
5 |
+
import os
|
6 |
+
|
7 |
+
# YouTube API μ€μ½ν λ° νμν μΈμ¦ μ 보 μ€μ
|
8 |
+
SCOPES = ['https://www.googleapis.com/auth/youtube.force-ssl']
|
9 |
+
|
10 |
+
def update_video_descriptions(additional_text):
|
11 |
+
creds = None
|
12 |
+
# μΈμ¦ νλ‘μΈμ€
|
13 |
+
flow = InstalledAppFlow.from_client_secrets_file(
|
14 |
+
os.environ['CLIENT_SECRETS_FILE'], SCOPES)
|
15 |
+
creds = flow.run_local_server(port=0)
|
16 |
+
youtube = build('youtube', 'v3', credentials=creds)
|
17 |
+
|
18 |
+
# μ¬μ©μμ YouTube μ±λ λμμ λͺ©λ‘ κ°μ Έμ€κΈ°
|
19 |
+
request = youtube.videos().list(part='snippet', mine=True)
|
20 |
+
response = request.execute()
|
21 |
+
|
22 |
+
for video in response.get('items', []):
|
23 |
+
video_id = video['id']
|
24 |
+
snippet = video['snippet']
|
25 |
+
original_description = snippet['description']
|
26 |
+
|
27 |
+
# μ€λͺ
λ μ
λ°μ΄νΈ
|
28 |
+
updated_description = f"{original_description}\n\n{additional_text}"
|
29 |
+
snippet['description'] = updated_description
|
30 |
+
|
31 |
+
update_request = youtube.videos().update(part='snippet', body={'id': video_id, 'snippet': snippet})
|
32 |
+
update_request.execute()
|
33 |
+
|
34 |
+
return f"Updated descriptions for {len(response.get('items', []))} videos."
|
35 |
+
|
36 |
+
def add_text_to_videos(text):
|
37 |
+
return update_video_descriptions(text)
|
38 |
+
|
39 |
+
interface = gr.Interface(fn=add_text_to_videos, inputs="text", outputs="text", title="Update YouTube Video Descriptions")
|
40 |
+
interface.launch()
|