Blane187 commited on
Commit
c0a1d1d
·
verified ·
1 Parent(s): 5ba500a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -1,28 +1,45 @@
1
  import yt_dlp
2
  import gradio as gr
3
 
4
- def download_youtube_wav(url, custom_name):
 
 
 
 
 
5
  ydl_opts = {
6
  'format': 'bestaudio/best',
7
  'postprocessors': [{
8
  'key': 'FFmpegExtractAudio',
9
- 'preferredcodec': 'wav',
10
- 'preferredquality': '192',
11
  }],
12
- 'outtmpl': f'{custom_name}.%(ext)s',
13
  }
14
 
15
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
16
- ydl.download([url])
17
-
18
- return f'Download complete! File saved as: {custom_name}.wav'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
 
21
- with gr.Blocks() as demo:
22
- url = gr.Textbox(label="url video")
23
- custom_name = gr.Textbox(label="custom_name")
24
- output = gr.Audio(label="output")
25
- download_youtube_wav_btn = gr.Button("Greet")
26
- download_youtube_wav_btn.click(fn=download_youtube_wav, inputs=url, custom_name, outputs=output)
27
 
28
- demo.launch()
 
1
  import yt_dlp
2
  import gradio as gr
3
 
4
+ import os
5
+ import yt_dlp
6
+ import gradio as gr
7
+
8
+ def downloader(video_url, save_folder, audio_format, audio_name):
9
+ save_path = os.path.join(save_folder, audio_name)
10
  ydl_opts = {
11
  'format': 'bestaudio/best',
12
  'postprocessors': [{
13
  'key': 'FFmpegExtractAudio',
14
+ 'preferredcodec': audio_format,
 
15
  }],
16
+ 'outtmpl': save_path,
17
  }
18
 
19
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
20
+ ydl.download([video_url])
21
+ return f"Audio downloaded successfully to {save_path}"
22
+
23
+ inputs = [
24
+ gr.inputs.Textbox(label="YouTube video link", default="https://youtu.be/L3P0LgwuPPo?si=3dLDS6WIGM2Lk9gf"),
25
+ gr.inputs.Textbox(label="Audio name", default="Harenchi"),
26
+ gr.inputs.Textbox(label="Output path for downloaded audio files", default="/content/drive/MyDrive/Separar"),
27
+ gr.inputs.Radio(["wav", "flac", "mp3"], label="Select the output format", default="wav")
28
+ ]
29
+
30
+ output = gr.outputs.Textbox(label="Output")
31
+
32
+ title = "YouTube Audio Downloader"
33
+ description = "Download audio from YouTube videos"
34
+
35
+ gr.Interface(
36
+ fn=downloader,
37
+ inputs=inputs,
38
+ outputs=output,
39
+ title=title,
40
+ description=description,
41
+ theme="light"
42
+ ).launch()
43
 
44
 
 
 
 
 
 
 
45