Spaces:
Sleeping
Sleeping
| 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() |