lanbogao commited on
Commit
c1eeef2
1 Parent(s): 5b4061c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -16,16 +16,16 @@ def get_subtitle(url, lang='en'):
16
  'subtitleslangs': [lang],
17
  'skip_download': True,
18
  }
19
- info_dict = yt_dlp.extract_info(url, download=True)
20
- video_id = info_dict.get("id", None)
21
- if video_id is None:
22
- return None
23
- subtitle_file = f"{video_id}.{lang}.vtt"
24
- if not os.path.exists(subtitle_file):
25
- return None
26
-
27
- subtitle_text = subprocess.check_output(['webvtt-to-text', subtitle_file]).decode('utf-8')
28
- return subtitle_text
29
 
30
  def download_audio(video_url, quality: str = '128', speed: float = None):
31
  ydl_opts = {
 
16
  'subtitleslangs': [lang],
17
  'skip_download': True,
18
  }
19
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
20
+ info_dict = ydl.extract_info(url, download=True)
21
+ video_id = info_dict.get("id", None)
22
+ if video_id is None:
23
+ return None
24
+ subtitle_file = f"{video_id}.{lang}.vtt"
25
+ if os.path.exists(subtitle_file):
26
+ subtitle_text = subprocess.check_output(['webvtt-to-text', subtitle_file]).decode('utf-8')
27
+ return subtitle_text
28
+ return None
29
 
30
  def download_audio(video_url, quality: str = '128', speed: float = None):
31
  ydl_opts = {