JUNGU commited on
Commit
088f881
·
verified ·
1 Parent(s): 3c3d02e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -1,28 +1,34 @@
1
  import gradio as gr
2
  import yt_dlp as youtube_dl
3
 
4
- def download_youtube_videos(urls):
5
- ydl_opts = {
6
- 'format': 'best',
7
- 'outtmpl': '%(title)s.%(ext)s',
8
- }
 
 
9
 
10
- with youtube_dl.YoutubeDL(ydl_opts) as ydl:
11
- ydl.download(urls)
12
- return "다운로드 완료!"
 
 
 
13
 
14
- def start_download(urls):
15
- url_list = urls.split('\n')
16
- download_youtube_videos(url_list)
17
- return "모든 비디오가 다운로드 되었습니다."
18
 
19
- iface = gr.Interface(
20
- fn=start_download,
21
- inputs=gr.Textbox(lines=10, placeholder="여기에 YouTube 링크를 입력하세요 (각 링크를 줄바꿈으로 구분)"),
22
- outputs=gr.Textbox(),
23
- title="YouTube 비디오 다운로드",
24
- description="여러 YouTube 비디오 링크를 입력하고 다운로드 버튼을 눌러 비디오를 다운로드하세요."
 
 
25
  )
26
 
27
  if __name__ == "__main__":
28
- iface.launch()
 
1
  import gradio as gr
2
  import yt_dlp as youtube_dl
3
 
4
+ def download_youtube_video(youtube_url):
5
+ """Downloads a YouTube video using yt_dlp and returns the downloaded file path."""
6
+ try:
7
+ ydl_opts = {
8
+ 'format': 'best',
9
+ 'outtmpl': '%(title)s.%(ext)s',
10
+ }
11
 
12
+ with youtube_dl.YoutubeDL(ydl_opts) as ydl:
13
+ result = ydl.extract_info(youtube_url, download=True)
14
+ video_title = result.get('title', None)
15
+ video_ext = result.get('ext', None)
16
+ downloaded_file = f"{video_title}.{video_ext}"
17
+ return downloaded_file
18
 
19
+ except Exception as e:
20
+ print("An error occurred:", e)
21
+ return None
 
22
 
23
+ def app(video_link):
24
+ video_path = download_youtube_video(video_link)
25
+ return video_path
26
+
27
+ interface = gr.Interface(
28
+ fn=app,
29
+ inputs=gr.Textbox(label="Enter YouTube link 🔗 To Download Video⬇️ "),
30
+ outputs=gr.Textbox(label="Downloaded Video Path")
31
  )
32
 
33
  if __name__ == "__main__":
34
+ interface.launch(debug=True)