File size: 2,714 Bytes
6adf498
4bc4c10
3af03c3
 
 
4bc4c10
 
 
 
 
 
 
 
 
 
 
 
 
 
3af03c3
4bc4c10
3af03c3
 
 
 
 
4bc4c10
 
 
 
 
 
 
 
 
3af03c3
 
 
 
4bc4c10
3af03c3
4bc4c10
3af03c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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)