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()