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