Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,36 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import youtube_dl
|
3 |
|
4 |
-
|
|
|
|
|
5 |
opts = {
|
6 |
-
"skip_download": True,
|
7 |
-
"writesubtitles":
|
8 |
-
"
|
|
|
|
|
9 |
}
|
|
|
10 |
try:
|
11 |
-
with
|
12 |
yt.download([url])
|
13 |
-
return "Subtitles downloaded successfully."
|
14 |
except Exception as e:
|
15 |
return f"An error occurred: {e}"
|
16 |
|
|
|
17 |
interface = gr.Interface(
|
18 |
-
fn=
|
19 |
-
inputs=[
|
|
|
|
|
|
|
20 |
outputs="text",
|
21 |
title="YouTube Subtitle Downloader",
|
22 |
-
description="Enter a YouTube video URL and a subtitle language (e.g., 'en')."
|
23 |
)
|
24 |
|
25 |
-
interface
|
|
|
|
|
|
1 |
+
import yt_dlp
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# Function to download YouTube subtitles
|
5 |
+
def download_subs(url, lang="en"):
|
6 |
+
# Define options for yt-dlp
|
7 |
opts = {
|
8 |
+
"skip_download": True, # Do not download the video
|
9 |
+
"writesubtitles": True, # Download subtitles
|
10 |
+
"subtitleslangs": lang, # Language for subtitles
|
11 |
+
"outtmpl": "%(title)s.%(ext)s", # Output file template
|
12 |
+
"cookiefile": "cookies.txt", # Path to cookies if required
|
13 |
}
|
14 |
+
|
15 |
try:
|
16 |
+
with yt_dlp.YoutubeDL(opts) as yt:
|
17 |
yt.download([url])
|
18 |
+
return "Subtitles downloaded successfully. Check the output directory."
|
19 |
except Exception as e:
|
20 |
return f"An error occurred: {e}"
|
21 |
|
22 |
+
# Create Gradio interface
|
23 |
interface = gr.Interface(
|
24 |
+
fn=download_subs,
|
25 |
+
inputs=[
|
26 |
+
gr.Textbox(label="YouTube Video URL", placeholder="Enter the video URL"),
|
27 |
+
gr.Textbox(label="Subtitle Language", placeholder="Enter language code (e.g., 'en')", value="en"),
|
28 |
+
],
|
29 |
outputs="text",
|
30 |
title="YouTube Subtitle Downloader",
|
31 |
+
description="Enter a YouTube video URL and a subtitle language (e.g., 'en') to download subtitles.",
|
32 |
)
|
33 |
|
34 |
+
# Launch the interface
|
35 |
+
if __name__ == "__main__":
|
36 |
+
interface.launch()
|