Spaces:
Running
Running
import yt_dlp | |
import gradio as gr | |
def get_captions(video_url, lang='en'): | |
ydl_opts = { | |
'skip_download': True, | |
'writesubtitles': True, | |
'subtitleslangs': [lang], | |
'writeautomaticsub': True, | |
'quiet': True, | |
'forcejson': True | |
} | |
try: | |
with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
info = ydl.extract_info(video_url, download=False) | |
subtitles = info.get('subtitles') or info.get('automatic_captions') | |
if subtitles and lang in subtitles: | |
subtitle_url = subtitles[lang][0]['url'] | |
return f"β Captions Found:\n{subtitle_url}" | |
return "β οΈ No captions found for this language." | |
except Exception as e: | |
return f"β Error: {str(e)}" | |
gr.Interface( | |
fn=get_captions, | |
inputs=[ | |
gr.Textbox(label="YouTube Video URL"), | |
gr.Textbox(value="en", label="Language Code (e.g., en, es, fr)") | |
], | |
outputs="text", | |
title="YouTube Caption Extractor", | |
description="Paste a YouTube video URL and get the direct link to the captions (auto or uploaded)." | |
).launch() | |