DeeeeeeM
commited on
Commit
·
b1818a4
1
Parent(s):
f85a311
added srt downloader for yt videos
Browse files
app.py
CHANGED
@@ -10,6 +10,9 @@ import time
|
|
10 |
from yt_dlp import YoutubeDL
|
11 |
import csv
|
12 |
import os
|
|
|
|
|
|
|
13 |
|
14 |
def process_media(
|
15 |
model_size, source_lang, upload, model_type,
|
@@ -197,6 +200,35 @@ def extract_playlist_to_csv(playlist_url):
|
|
197 |
except Exception as e:
|
198 |
return None
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
WHISPER_LANGUAGES = [
|
201 |
("Afrikaans", "af"),
|
202 |
("Albanian", "sq"),
|
@@ -479,5 +511,16 @@ with gr.Blocks() as interface:
|
|
479 |
outputs=csv_output
|
480 |
)
|
481 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
482 |
|
483 |
interface.launch(share=True)
|
|
|
10 |
from yt_dlp import YoutubeDL
|
11 |
import csv
|
12 |
import os
|
13 |
+
import subprocess
|
14 |
+
import glob
|
15 |
+
import shutil
|
16 |
|
17 |
def process_media(
|
18 |
model_size, source_lang, upload, model_type,
|
|
|
200 |
except Exception as e:
|
201 |
return None
|
202 |
|
203 |
+
def download_srt(video_url):
|
204 |
+
try:
|
205 |
+
temp_dir = tempfile.mkdtemp()
|
206 |
+
output_template = os.path.join(temp_dir, "%(id)s.%(ext)s")
|
207 |
+
cmd = [
|
208 |
+
"yt-dlp",
|
209 |
+
"--write-subs",
|
210 |
+
"--write-auto-subs",
|
211 |
+
"--sub-lang", "en-US",
|
212 |
+
"--skip-download",
|
213 |
+
"--convert-subs", "srt",
|
214 |
+
"-o", output_template,
|
215 |
+
video_url
|
216 |
+
]
|
217 |
+
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
218 |
+
print(result.stdout)
|
219 |
+
print(result.stderr)
|
220 |
+
srt_files = glob.glob(os.path.join(temp_dir, "*.srt"))
|
221 |
+
if srt_files:
|
222 |
+
return srt_files[0]
|
223 |
+
else:
|
224 |
+
vtt_files = glob.glob(os.path.join(temp_dir, "*.vtt"))
|
225 |
+
if vtt_files:
|
226 |
+
return vtt_files[0]
|
227 |
+
return None
|
228 |
+
except Exception as e:
|
229 |
+
print("SRT download error:", e)
|
230 |
+
return None
|
231 |
+
|
232 |
WHISPER_LANGUAGES = [
|
233 |
("Afrikaans", "af"),
|
234 |
("Albanian", "sq"),
|
|
|
511 |
outputs=csv_output
|
512 |
)
|
513 |
|
514 |
+
with gr.TabItem(".srt Downloader"):
|
515 |
+
gr.Markdown("### Download English subtitles (.srt) from a YouTube video.")
|
516 |
+
srt_url = gr.Textbox(label="YouTube Video URL", placeholder="Paste video URL here")
|
517 |
+
srt_btn = gr.Button("Process")
|
518 |
+
srt_file = gr.File(label="Download SRT")
|
519 |
+
srt_btn.click(
|
520 |
+
download_srt,
|
521 |
+
inputs=srt_url,
|
522 |
+
outputs=srt_file
|
523 |
+
)
|
524 |
+
|
525 |
|
526 |
interface.launch(share=True)
|