Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def download_video(url):
|
5 |
-
ydl_opts
|
6 |
-
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4',
|
7 |
-
'outtmpl': '%(id)s.%(ext)s',
|
8 |
-
}
|
9 |
-
|
10 |
-
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
11 |
-
ydl.download([url])
|
12 |
info_dict = ydl.extract_info(url, download=False)
|
|
|
13 |
filename = ydl.prepare_filename(info_dict)
|
14 |
-
|
15 |
|
|
|
16 |
iface = gr.Interface(
|
17 |
-
fn=download_video,
|
18 |
-
inputs=gr.Textbox(placeholder="Enter YouTube URL here..."),
|
19 |
-
outputs=
|
20 |
title="YouTube Video Downloader",
|
21 |
description="Enter a YouTube URL to download it as an MP4 file."
|
22 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
from yt_dlp import YoutubeDL
|
3 |
+
|
4 |
+
# yt-dlpμ μ΅μ
μ€μ
|
5 |
+
ydl_opts = {
|
6 |
+
'format': 'bestvideo+bestaudio/best',
|
7 |
+
'outtmpl': '%(id)s.%(ext)s', # λ€μ΄λ‘λλ νμΌμ μ΄λ¦ νμμ μ§μ
|
8 |
+
'postprocessors': [{ # λΉλμ€μ μ€λμ€λ₯Ό ν©μΉλ μμ
|
9 |
+
'key': 'FFmpegMerger',
|
10 |
+
'preferredcodec': 'mp4',
|
11 |
+
}],
|
12 |
+
'noplaylist': True, # νλ μ΄λ¦¬μ€νΈμ 첫 λΉλμ€λ§ λ€μ΄λ‘λ
|
13 |
+
}
|
14 |
|
15 |
def download_video(url):
|
16 |
+
with YoutubeDL(ydl_opts) as ydl:
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
info_dict = ydl.extract_info(url, download=False)
|
18 |
+
ydl.download([url])
|
19 |
filename = ydl.prepare_filename(info_dict)
|
20 |
+
return filename
|
21 |
|
22 |
+
# Gradio μΈν°νμ΄μ€ μ€μ
|
23 |
iface = gr.Interface(
|
24 |
+
fn=download_video,
|
25 |
+
inputs=gr.Textbox(placeholder="Enter YouTube URL here..."),
|
26 |
+
outputs='text',
|
27 |
title="YouTube Video Downloader",
|
28 |
description="Enter a YouTube URL to download it as an MP4 file."
|
29 |
)
|