chrome_zepra / app.py
avchd's picture
Upload app.py
b502193 verified
Raw
History Blame Contribute Delete
910 Bytes
import gradio as gr
from yt_dlp import YoutubeDL
import os
def download_video(url):
download_folder = "/tmp/downloads"
os.makedirs(download_folder, exist_ok=True)
ydl_opts = {
"outtmpl": os.path.join(download_folder, "%(id)s.%(ext)s"),
"format": "bestvideo+bestaudio/best",
}
try:
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
file_path = os.path.join(download_folder, f"{info['id']}.{info['ext']}")
return file_path if os.path.exists(file_path) else None
except Exception as e:
return str(e)
iface = gr.Interface(
fn=download_video,
inputs=gr.Textbox(label="Video-URL eingeben"),
outputs=gr.File(label="Heruntergeladenes Video"),
title="Video Downloader API",
description="Gib eine Video-URL ein und lade das Video herunter."
)
iface.launch(share=True)