JUNGU commited on
Commit
0c15909
Β·
1 Parent(s): e45b985

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -1,22 +1,29 @@
1
  import gradio as gr
2
- import youtube_dl
 
 
 
 
 
 
 
 
 
 
 
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
- return filename
15
 
 
16
  iface = gr.Interface(
17
- fn=download_video,
18
- inputs=gr.Textbox(placeholder="Enter YouTube URL here..."),
19
- outputs="text",
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
  )