File size: 1,508 Bytes
285b466 e59ecdb 0e6fe67 e59ecdb c5dc168 e59ecdb c5dc168 e59ecdb 0e6fe67 e59ecdb 0e6fe67 e59ecdb 0e6fe67 e59ecdb 0e6fe67 c5dc168 e59ecdb 5019826 c5dc168 e59ecdb c5dc168 e59ecdb 285b466 e59ecdb |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import gradio as gr
import requests
import os
from urllib.parse import urlparse, unquote
def gradio_fn(url):
if not url:
return None
try:
api_url = f"https://eolithic-daniele-nonchivalrously.ngrok-free.app/dl?url={url}"
response = requests.get(api_url)
response.raise_for_status()
data = response.json()
mp3_url = data.get('download_link')
if not mp3_url:
return None
mp3_response = requests.get(mp3_url)
mp3_response.raise_for_status()
# π Ambil nama file dari URL
parsed_url = urlparse(mp3_url)
filename = unquote(os.path.basename(parsed_url.path))
if not filename or '.' not in filename:
filename = "audio.mp3"
# π Simpan ke /tmp β HF Spaces mengizinkan ini!
filepath = os.path.join("/tmp", filename)
with open(filepath, "wb") as f:
f.write(mp3_response.content)
return filepath
except Exception as e:
print(f"Error: {e}")
return None
with gr.Blocks(title="YT/YT-Music Downloader") as demo:
gr.Markdown("### Paste YouTube / YouTube-Music link β 320 k MP3 with tags")
with gr.Row():
inp = gr.Textbox(label="URL", placeholder=" https://www.youtube.com/watch?v=...")
btn = gr.Button("Download", variant="primary")
out = gr.File(label="MP3")
btn.click(gradio_fn, inputs=inp, outputs=out)
demo.launch() |