Rivalcoder commited on
Commit
c6f2536
·
1 Parent(s): 68a5aec
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import yt_dlp
2
+ import gradio as gr
3
+
4
+ def get_captions(video_url, lang='en'):
5
+ ydl_opts = {
6
+ 'skip_download': True,
7
+ 'writesubtitles': True,
8
+ 'subtitleslangs': [lang],
9
+ 'writeautomaticsub': True,
10
+ 'quiet': True,
11
+ 'forcejson': True
12
+ }
13
+
14
+ try:
15
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
16
+ info = ydl.extract_info(video_url, download=False)
17
+ subtitles = info.get('subtitles') or info.get('automatic_captions')
18
+ if subtitles and lang in subtitles:
19
+ subtitle_url = subtitles[lang][0]['url']
20
+ return f"✅ Captions Found:\n{subtitle_url}"
21
+ return "⚠️ No captions found for this language."
22
+ except Exception as e:
23
+ return f"❌ Error: {str(e)}"
24
+
25
+ gr.Interface(
26
+ fn=get_captions,
27
+ inputs=[
28
+ gr.Textbox(label="YouTube Video URL"),
29
+ gr.Textbox(value="en", label="Language Code (e.g., en, es, fr)")
30
+ ],
31
+ outputs="text",
32
+ title="YouTube Caption Extractor",
33
+ description="Paste a YouTube video URL and get the direct link to the captions (auto or uploaded)."
34
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ yt-dlp