flyboytarantino14 commited on
Commit
4cdb27e
·
1 Parent(s): 48755cb

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import yt_dlp
4
+ import base64
5
+
6
+ def youtube2video(url):
7
+ URL = url
8
+ ydl_opts = {
9
+ 'format': 'bestaudio/best',
10
+ 'outtmpl': 'audio',
11
+ 'postprocessors': [{
12
+ 'key': 'FFmpegExtractAudio',
13
+ 'preferredcodec': 'mp3',
14
+ 'preferredquality': '192',
15
+ }]
16
+ }
17
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
18
+ ydl.download([URL])
19
+ with open('audio.mp3', 'rb') as file:
20
+ mp3 = file.read()
21
+ base64_mp3 = base64.b64encode(mp3).decode('utf-8')
22
+ return base64_mp3
23
+
24
+ input_url = gr.Textbox()
25
+ output_base64 = gr.Textbox()
26
+
27
+ interface = gr.Interface(
28
+ fn=youtube2video,
29
+ inputs=input_url,
30
+ outputs=output_base64,
31
+ )
32
+
33
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ yt-dlp