vitaliy-sharandin commited on
Commit
526ad41
·
verified ·
1 Parent(s): f23d3ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -1,5 +1,5 @@
1
  '''
2
- Copyright 2023-2024 LangBridge Inc.
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
- from pytube import YouTube
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
- yt = YouTube(url)
286
- if yt.age_restricted:
287
- gr.Warning("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 pytube library doesn't support restricted videos download.")
288
- return None
289
- stream = yt.streams.filter(file_extension='mp4').first()
290
- output_path = stream.download()
291
- return output_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)