File size: 978 Bytes
f231b32
0c15909
 
 
 
 
 
 
 
 
 
 
 
f231b32
 
0c15909
f231b32
0c15909
f231b32
0c15909
f231b32
0c15909
f231b32
0c15909
 
 
f231b32
 
 
 
 
 
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
import gradio as gr
from yt_dlp import YoutubeDL

# yt-dlp의 μ˜΅μ…˜ μ„€μ •
ydl_opts = {
    'format': 'bestvideo+bestaudio/best',
    'outtmpl': '%(id)s.%(ext)s',  # λ‹€μš΄λ‘œλ“œλœ 파일의 이름 ν˜•μ‹μ„ μ§€μ •
    'postprocessors': [{  # λΉ„λ””μ˜€μ™€ μ˜€λ””μ˜€λ₯Ό ν•©μΉ˜λŠ” μž‘μ—…
        'key': 'FFmpegMerger',
        'preferredcodec': 'mp4',
    }],
    'noplaylist': True,  # ν”Œλ ˆμ΄λ¦¬μŠ€νŠΈμ˜ 첫 λΉ„λ””μ˜€λ§Œ λ‹€μš΄λ‘œλ“œ
}

def download_video(url):
    with YoutubeDL(ydl_opts) as ydl:
        info_dict = ydl.extract_info(url, download=False)
        ydl.download([url])
        filename = ydl.prepare_filename(info_dict)
    return filename

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
iface = gr.Interface(
    fn=download_video,
    inputs=gr.Textbox(placeholder="Enter YouTube URL here..."),
    outputs='text',
    title="YouTube Video Downloader",
    description="Enter a YouTube URL to download it as an MP4 file."
)

if __name__ == "__main__":
    iface.launch()