Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -119,27 +119,37 @@ async def get_best_available_transcript(video_id, max_retries=5, delay=10):
|
|
119 |
try:
|
120 |
transcript = await asyncio.to_thread(YouTubeTranscriptApi.get_transcript, video_id, languages=[language])
|
121 |
return transcript, language
|
|
|
|
|
|
|
122 |
except Exception as e:
|
123 |
logging.warning(f'{language} μλ§ κ°μ Έμ€κΈ° μ€λ₯: {e}')
|
124 |
return None, None
|
125 |
|
126 |
for attempt in range(max_retries):
|
|
|
127 |
ko_transcript, ko_lang = await fetch_transcript('ko')
|
128 |
if ko_transcript:
|
129 |
return ko_transcript, ko_lang
|
130 |
|
|
|
131 |
en_transcript, en_lang = await fetch_transcript('en')
|
132 |
if en_transcript:
|
133 |
return en_transcript, en_lang
|
134 |
|
135 |
try:
|
|
|
136 |
transcripts = await asyncio.to_thread(YouTubeTranscriptApi.list_transcripts, video_id)
|
137 |
-
|
|
|
|
|
138 |
transcript = await asyncio.to_thread(manual_transcript.fetch)
|
139 |
return transcript, manual_transcript.language_code
|
|
|
|
|
140 |
except Exception as e:
|
141 |
if attempt < max_retries - 1:
|
142 |
-
logging.error(f'
|
143 |
await asyncio.sleep(delay)
|
144 |
else:
|
145 |
logging.error(f'μ΅μ’
μλ§ κ°μ Έμ€κΈ° μ€ν¨: {e}')
|
@@ -148,6 +158,7 @@ async def get_best_available_transcript(video_id, max_retries=5, delay=10):
|
|
148 |
return None, None
|
149 |
|
150 |
|
|
|
151 |
async def get_video_comments(video_id):
|
152 |
comments = []
|
153 |
response = youtube_service.commentThreads().list(
|
|
|
119 |
try:
|
120 |
transcript = await asyncio.to_thread(YouTubeTranscriptApi.get_transcript, video_id, languages=[language])
|
121 |
return transcript, language
|
122 |
+
except (NoTranscriptFound, TranscriptsDisabled):
|
123 |
+
logging.warning(f'{language} μλ§μ΄ μ 곡λμ§ μμ.')
|
124 |
+
return None, None
|
125 |
except Exception as e:
|
126 |
logging.warning(f'{language} μλ§ κ°μ Έμ€κΈ° μ€λ₯: {e}')
|
127 |
return None, None
|
128 |
|
129 |
for attempt in range(max_retries):
|
130 |
+
# μ°μ νκ΅μ΄ μλ§μ μλ
|
131 |
ko_transcript, ko_lang = await fetch_transcript('ko')
|
132 |
if ko_transcript:
|
133 |
return ko_transcript, ko_lang
|
134 |
|
135 |
+
# μμ΄ μλ§ μλ
|
136 |
en_transcript, en_lang = await fetch_transcript('en')
|
137 |
if en_transcript:
|
138 |
return en_transcript, en_lang
|
139 |
|
140 |
try:
|
141 |
+
# λΉλμ€μ μλ§ λͺ©λ‘μ΄ μλμ§ νμΈ
|
142 |
transcripts = await asyncio.to_thread(YouTubeTranscriptApi.list_transcripts, video_id)
|
143 |
+
|
144 |
+
# μλμΌλ‘ μμ±λ μλ§μ΄ μλμ§ νμΈ
|
145 |
+
manual_transcript = transcripts.find_manually_created_transcript(['ko', 'en'])
|
146 |
transcript = await asyncio.to_thread(manual_transcript.fetch)
|
147 |
return transcript, manual_transcript.language_code
|
148 |
+
except (NoTranscriptFound, TranscriptsDisabled) as e:
|
149 |
+
logging.warning(f'μλ μλ§μ μ°Ύμ μ μμ: {e}')
|
150 |
except Exception as e:
|
151 |
if attempt < max_retries - 1:
|
152 |
+
logging.error(f'μλ§ κ°μ Έμ€κΈ° μ€ν¨ (μλ {attempt + 1}/{max_retries}): {e}')
|
153 |
await asyncio.sleep(delay)
|
154 |
else:
|
155 |
logging.error(f'μ΅μ’
μλ§ κ°μ Έμ€κΈ° μ€ν¨: {e}')
|
|
|
158 |
return None, None
|
159 |
|
160 |
|
161 |
+
|
162 |
async def get_video_comments(video_id):
|
163 |
comments = []
|
164 |
response = youtube_service.commentThreads().list(
|