Hev832 commited on
Commit
25c7df7
1 Parent(s): 0a1013e

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +9 -11
run.py CHANGED
@@ -1,9 +1,8 @@
1
  import gradio as gr
2
  import os
3
- import subprocess
4
 
5
  def get_video_title(url):
6
-
7
  result = subprocess.run(["yt-dlp", "--get-title", url], capture_output=True, text=True)
8
  if result.returncode == 0:
9
  return result.stdout.strip()
@@ -12,22 +11,23 @@ def get_video_title(url):
12
 
13
  def fetch(url, custom_name, ext):
14
  title = get_video_title(url)
15
- #
16
- max_length = 50 #
17
  truncated_title = title[:max_length].strip()
18
 
19
  filename = f"{custom_name}.{ext}" if custom_name else f"{truncated_title}.{ext}"
20
  opts = {
21
- "mp3": ["-f", "ba", "-x", "--audio-format", "mp3"],
22
  "wav": ["-f", "ba", "-x", "--audio-format", "wav"],
23
-
24
  }[ext]
25
  command = ["yt-dlp"] + opts + [url, "-o", filename]
26
  subprocess.run(command)
27
 
28
  return filename
29
 
30
-
 
 
 
31
 
32
  app = gr.Interface(
33
  theme='Hev832/EasyAndCool',
@@ -37,10 +37,8 @@ app = gr.Interface(
37
  gr.Textbox(label="File name", placeholder="Defaults to video title"),
38
  gr.Dropdown(value="wav", label="Format")
39
  ],
40
- outputs=[
41
- gr.Audio(label="otputs"),
42
  description="<div style='font-size:30px; text-align:center;'>YouTube Audio Player</div>"
43
-
44
  )
45
 
46
- app.launch(debug=True, share=True)
 
1
  import gradio as gr
2
  import os
3
+
4
 
5
  def get_video_title(url):
 
6
  result = subprocess.run(["yt-dlp", "--get-title", url], capture_output=True, text=True)
7
  if result.returncode == 0:
8
  return result.stdout.strip()
 
11
 
12
  def fetch(url, custom_name, ext):
13
  title = get_video_title(url)
14
+ max_length = 50
 
15
  truncated_title = title[:max_length].strip()
16
 
17
  filename = f"{custom_name}.{ext}" if custom_name else f"{truncated_title}.{ext}"
18
  opts = {
 
19
  "wav": ["-f", "ba", "-x", "--audio-format", "wav"],
20
+ "mp4": ["-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"],
21
  }[ext]
22
  command = ["yt-dlp"] + opts + [url, "-o", filename]
23
  subprocess.run(command)
24
 
25
  return filename
26
 
27
+ def play_audio(output_audio):
28
+ audio = AudioSegment.from_file(output_audio)
29
+ audio.export("output.wav", format="wav")
30
+ gr.Interface(fn=None, live=False, outputs="audio").play("output.wav")
31
 
32
  app = gr.Interface(
33
  theme='Hev832/EasyAndCool',
 
37
  gr.Textbox(label="File name", placeholder="Defaults to video title"),
38
  gr.Dropdown(value="wav", label="Format")
39
  ],
40
+ outputs=None,
 
41
  description="<div style='font-size:30px; text-align:center;'>YouTube Audio Player</div>"
 
42
  )
43
 
44
+ app.launch(debug=True, share=True)