Blane187 commited on
Commit
29ded09
·
verified ·
1 Parent(s): 863c552

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -39
app.py CHANGED
@@ -1,44 +1,28 @@
1
- import yt_dlp
2
- import gradio as gr
3
- import os
4
- import time
5
 
6
 
7
- def downloader(video_url, audio_name, audio_format, progress=gr.Progress()):
8
- path_file = f"audios/{audio_name}.{audio_format}"
9
- progress(0, desc="Initializing download...")
10
- time.sleep(1)
11
-
12
  ydl_opts = {
13
- 'format': 'bestaudio/best',
14
- 'postprocessors': [{
15
- 'key': 'FFmpegExtractAudio',
16
- 'preferredcodec': audio_format,
17
- }],
18
- 'outtmpl': path_file,
19
- 'progress_hooks': [lambda d: progress(d['downloaded_bytes'] / d['total_bytes']) if d['status'] == 'downloading' else None]
20
  }
21
-
22
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
23
- ydl.download([video_url])
24
-
25
- return path_file
26
-
27
- inputs = [
28
- gr.Textbox(label="YouTube video link"),
29
- gr.Textbox(label="Audio name"),
30
- gr.Radio(["wav", "flac", "mp3"], label="Select the output format")
31
- ]
32
-
33
- output = gr.Audio(label="Output")
34
-
35
- title = "yt_dlp"
36
- description = "This space was made by [Blane187](https://huggingface.co/Blane187). Please credit me if you use this thing :D"
37
-
38
- gr.Interface(
39
- fn=downloader,
40
- inputs=inputs,
41
- outputs=output,
42
- title=title,
43
- description=description,
44
- ).launch()
 
 
 
 
 
1
 
2
 
3
+ import gradio as gr
4
+ import yt_dlp
5
+
6
+ def download_video(url):
 
7
  ydl_opts = {
8
+ 'format': 'best',
9
+ 'outtmpl': 'downloaded_videos/%(title)s.%(ext)s',
 
 
 
 
 
10
  }
 
11
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
12
+ info_dict = ydl.extract_info(url, download=True)
13
+ video_title = info_dict.get('title', None)
14
+ return f"Video '{video_title}' downloaded successfully!"
15
+
16
+ iface = gr.Interface(
17
+ fn=download_video,
18
+ inputs=gr.Textbox(label="YouTube URL"),
19
+ outputs=gr.Textbox(label="Download Status"),
20
+ title = "yt_dlp",
21
+ description = "This space was made by [Blane187](https://huggingface.co/Blane187). Please credit me if you use this thing :D"
22
+
23
+ )
24
+
25
+ iface.launch()
26
+
27
+
28
+