Rivalcoder
Add
c6f2536
raw
history blame
1.13 kB
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()