Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp as youtube_dl
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return "모든 비디오가 다운로드 되었습니다."
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
)
|
26 |
|
27 |
if __name__ == "__main__":
|
28 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import yt_dlp as youtube_dl
|
3 |
|
4 |
+
def download_youtube_video(youtube_url):
|
5 |
+
"""Downloads a YouTube video using yt_dlp and returns the downloaded file path."""
|
6 |
+
try:
|
7 |
+
ydl_opts = {
|
8 |
+
'format': 'best',
|
9 |
+
'outtmpl': '%(title)s.%(ext)s',
|
10 |
+
}
|
11 |
|
12 |
+
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
13 |
+
result = ydl.extract_info(youtube_url, download=True)
|
14 |
+
video_title = result.get('title', None)
|
15 |
+
video_ext = result.get('ext', None)
|
16 |
+
downloaded_file = f"{video_title}.{video_ext}"
|
17 |
+
return downloaded_file
|
18 |
|
19 |
+
except Exception as e:
|
20 |
+
print("An error occurred:", e)
|
21 |
+
return None
|
|
|
22 |
|
23 |
+
def app(video_link):
|
24 |
+
video_path = download_youtube_video(video_link)
|
25 |
+
return video_path
|
26 |
+
|
27 |
+
interface = gr.Interface(
|
28 |
+
fn=app,
|
29 |
+
inputs=gr.Textbox(label="Enter YouTube link 🔗 To Download Video⬇️ "),
|
30 |
+
outputs=gr.Textbox(label="Downloaded Video Path")
|
31 |
)
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
+
interface.launch(debug=True)
|