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