Spaces:
Sleeping
Sleeping
File size: 1,735 Bytes
f1e5fbb | 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 49 50 51 | import os
import gradio as gr
from yt_dlp import YoutubeDL
from urllib.parse import urlparse
def check_video(url):
ydl_opts = {
'quiet': True,
'no_warnings': True,
'simulate': True
}
try:
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
return "Video wurde gefunden" if info else "Kein Video wurde gefunden"
except Exception:
return "Kein Video wurde gefunden"
def sanitize_filename(title):
return "".join(c if c.isalnum() or c in (' ', '.', '_') else '_' for c in title)[:100]
def download_video(url):
download_folder = "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:
return None
def process_link(url):
message = check_video(url)
file_path = download_video(url) if message == "Video wurde gefunden" else None
return message, file_path
iface = gr.Interface(
fn=process_link,
inputs=gr.Textbox(label="Video-Link einfügen"),
outputs=[gr.Text(label="Status"), gr.File(label="Heruntergeladenes Video")],
live=True,
title="Video Downloader",
description="Füge einen Video-Link von Instagram oder TikTok ein und lade das Video direkt herunter. Funktioniert NICHT mit Stories!"
)
iface.launch() |