Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
'''
|
2 |
-
Copyright 2023-
|
3 |
All Rights Reserved.
|
4 |
LangBridge Restricted
|
5 |
'''
|
@@ -17,7 +17,7 @@ import torch
|
|
17 |
import whisperx
|
18 |
from moviepy import afx
|
19 |
from moviepy.audio.AudioClip import AudioArrayClip
|
20 |
-
|
21 |
from TTS.api import TTS
|
22 |
|
23 |
|
@@ -282,13 +282,28 @@ def check_video_duration(video_path):
|
|
282 |
return duration > 180
|
283 |
|
284 |
def download_youtube_video(url):
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
def translation_limit():
|
294 |
translator = deepl.Translator(DEEPL_TOKEN)
|
|
|
1 |
'''
|
2 |
+
Copyright 2023-2025 LangBridge Inc.
|
3 |
All Rights Reserved.
|
4 |
LangBridge Restricted
|
5 |
'''
|
|
|
17 |
import whisperx
|
18 |
from moviepy import afx
|
19 |
from moviepy.audio.AudioClip import AudioArrayClip
|
20 |
+
import yt_dlp
|
21 |
from TTS.api import TTS
|
22 |
|
23 |
|
|
|
282 |
return duration > 180
|
283 |
|
284 |
def download_youtube_video(url):
|
285 |
+
ydl_opts = {
|
286 |
+
"format": "mp4/best[ext=mp4]", # Prefer mp4 format
|
287 |
+
"outtmpl": "%(title)s.%(ext)s", # Output filename template
|
288 |
+
}
|
289 |
+
|
290 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
291 |
+
try:
|
292 |
+
info = ydl.extract_info(url, download=False)
|
293 |
+
|
294 |
+
if info.get("age_limit", 0) > 0:
|
295 |
+
gr.Warning(
|
296 |
+
"The Youtube video you are trying to translate is age restricted. Manually download it using the following link(https://en.savefrom.net/) and use file upload, as yt-dlp may not support restricted videos download."
|
297 |
+
)
|
298 |
+
return None
|
299 |
+
|
300 |
+
ydl.download([url])
|
301 |
+
|
302 |
+
return ydl.prepare_filename(info)
|
303 |
+
|
304 |
+
except Exception as e:
|
305 |
+
gr.Error(f"An error occurred while downloading the video: {e}")
|
306 |
+
return None
|
307 |
|
308 |
def translation_limit():
|
309 |
translator = deepl.Translator(DEEPL_TOKEN)
|