goversetv commited on
Commit
a06ea64
β€’
1 Parent(s): 09c6ba6

Create youtube.app

Browse files
Files changed (1) hide show
  1. 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()