import gradio as gr import requests import random import yt_dlp def get_fresh_proxies(): """Mengambil daftar proxy HTTP gratis yang masih aktif secara otomatis""" try: # Mengambil list proxy gratis dari API Geonode / ProxyScrape url = "https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=all&ssl=all&anonymity=all" response = requests.get(url, timeout=5) if response.status_code == 200: # Memisahkan string berdasarkan baris baru menjadi sebuah list proxies = response.text.strip().split("\r\n") # Format menjadi http://ip:port return [f"http://{proxy}" for proxy in proxies if proxy] except Exception: pass return [] def download_video_with_proxy(url): ydl_opts = { 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', 'merge_output_format': 'mp4', 'quiet': True, } # Ambil list proxy segar active_proxies = get_fresh_proxies() if active_proxies: # Pilih 1 proxy acak dari ratusan proxy gratis yang didapat chosen_proxy = random.choice(active_proxies) ydl_opts['proxy'] = chosen_proxy print(f"[INFO] Menggunakan Proxy: {chosen_proxy}") try: with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=True) return "Sukses!", ydl.prepare_filename(info) except Exception as e: return f"Gagal menggunakan proxy ini. Error: {str(e)}", None # Membuat UI dengan Gradio with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown( """ # 🌐 All In One Downloader (Anti-Block) Unduh video dari YouTube, TikTok, Instagram, Twitter, Facebook, dan ratusan situs lainnya langsung dari Hugging Face Space. """ ) with gr.Row(): with gr.Column(): url_input = gr.Textbox( label="Masukkan URL Video", placeholder="https://www.youtube.com/watch?v=... atau https://tiktok.com/@..." ) download_btn = gr.Button("Unduh Sekarang", variant="primary") with gr.Column(): status_output = gr.Textbox(label="Status / Log", interactive=False) file_output = gr.File(label="Hasil Download (Klik untuk Simpan)") # Trigger tombol download_btn.click( fn=download_video, inputs=url_input, outputs=[status_output, file_output] ) # Jalankan aplikasi if __name__ == "__main__": # Buat folder khusus downloads jika belum ada os.makedirs("downloads", exist_ok=True) demo.launch(server_name="0.0.0.0", server_port=7860)