Spaces:
Sleeping
Sleeping
File size: 732 Bytes
4cdb27e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import os
import gradio as gr
import yt_dlp
import base64
def youtube2video(url):
URL = url
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': 'audio',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([URL])
with open('audio.mp3', 'rb') as file:
mp3 = file.read()
base64_mp3 = base64.b64encode(mp3).decode('utf-8')
return base64_mp3
input_url = gr.Textbox()
output_base64 = gr.Textbox()
interface = gr.Interface(
fn=youtube2video,
inputs=input_url,
outputs=output_base64,
)
interface.launch() |