File size: 1,224 Bytes
141329f
546719c
 
141329f
 
 
546719c
141329f
 
 
 
 
546719c
141329f
546719c
141329f
546719c
141329f
546719c
 
 
141329f
546719c
141329f
 
 
 
 
546719c
 
141329f
546719c
 
141329f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import yt_dlp
import gradio as gr

# Function to download YouTube subtitles
def download_subs(url, lang="en"):
    # Define options for yt-dlp
    opts = {
        "skip_download": True,  # Do not download the video
        "writesubtitles": True,  # Download subtitles
        "subtitleslangs": lang,  # Language for subtitles
        "outtmpl": "%(title)s.%(ext)s",  # Output file template
        "cookiefile": "cookies.txt",  # Path to cookies if required
    }

    try:
        with yt_dlp.YoutubeDL(opts) as yt:
            yt.download([url])
        return "Subtitles downloaded successfully. Check the output directory."
    except Exception as e:
        return f"An error occurred: {e}"

# Create Gradio interface
interface = gr.Interface(
    fn=download_subs,
    inputs=[
        gr.Textbox(label="YouTube Video URL", placeholder="Enter the video URL"),
        gr.Textbox(label="Subtitle Language", placeholder="Enter language code (e.g., 'en')", value="en"),
    ],
    outputs="text",
    title="YouTube Subtitle Downloader",
    description="Enter a YouTube video URL and a subtitle language (e.g., 'en') to download subtitles.",
)

# Launch the interface
if __name__ == "__main__":
    interface.launch()