Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import yt_dlp
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
# --- KONFIGURASI HALAMAN ---
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="VDown | Video Downloader",
|
| 9 |
+
page_icon="⚡",
|
| 10 |
+
layout="centered"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# --- CSS COSTUM UNTUK TAMPILAN MENARIK ---
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<style>
|
| 16 |
+
.stApp {
|
| 17 |
+
background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
|
| 18 |
+
background-size: 400% 400%;
|
| 19 |
+
animation: gradient 15s ease infinite;
|
| 20 |
+
}
|
| 21 |
+
@keyframes gradient {
|
| 22 |
+
0% { background-position: 0% 50%; }
|
| 23 |
+
50% { background-position: 100% 50%; }
|
| 24 |
+
100% { background-position: 0% 50%; }
|
| 25 |
+
}
|
| 26 |
+
.main-card {
|
| 27 |
+
background-color: rgba(255, 255, 255, 0.95);
|
| 28 |
+
padding: 2rem;
|
| 29 |
+
border-radius: 20px;
|
| 30 |
+
box-shadow: 0 10px 25px rgba(0,0,0,0.2);
|
| 31 |
+
text-align: center;
|
| 32 |
+
}
|
| 33 |
+
h1 { color: #1f2937; }
|
| 34 |
+
p { color: #4b5563; }
|
| 35 |
+
</style>
|
| 36 |
+
""", unsafe_allow_html=True)
|
| 37 |
+
|
| 38 |
+
# --- UI UTAMA ---
|
| 39 |
+
st.markdown('<div class="main-card">', unsafe_allow_html=True)
|
| 40 |
+
st.title("⚡ VDown")
|
| 41 |
+
st.write("Download video YouTube, TikTok, & IG tanpa ribet.")
|
| 42 |
+
|
| 43 |
+
url = st.text_input("Paste Link Video di sini:", placeholder="https://youtube.com/watch?v=...")
|
| 44 |
+
|
| 45 |
+
if st.button("🚀 Proses Video", type="primary"):
|
| 46 |
+
if not url:
|
| 47 |
+
st.error("Mohon masukkan URL video!")
|
| 48 |
+
else:
|
| 49 |
+
status_text = st.empty()
|
| 50 |
+
progress_bar = st.progress(0)
|
| 51 |
+
|
| 52 |
+
status_text.info("Sedang menghubungi server...")
|
| 53 |
+
progress_bar.progress(20)
|
| 54 |
+
|
| 55 |
+
# --- LOGIKA DOWNLOADER ---
|
| 56 |
+
try:
|
| 57 |
+
# Konfigurasi yt-dlp
|
| 58 |
+
ydl_opts = {
|
| 59 |
+
'format': 'best',
|
| 60 |
+
'quiet': True,
|
| 61 |
+
'no_warnings': True,
|
| 62 |
+
# Opsi jaringan untuk menembus blokir
|
| 63 |
+
'nocheckcertificate': True,
|
| 64 |
+
'force_ipv4': True,
|
| 65 |
+
'socket_timeout': 30,
|
| 66 |
+
'http_headers': {'User-Agent': 'Mozilla/5.0'}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 70 |
+
status_text.info("Mengambil data video...")
|
| 71 |
+
progress_bar.progress(50)
|
| 72 |
+
|
| 73 |
+
# 1. Ambil Info
|
| 74 |
+
info = ydl.extract_info(url, download=False)
|
| 75 |
+
|
| 76 |
+
# Tampilkan Hasil
|
| 77 |
+
progress_bar.progress(100)
|
| 78 |
+
status_text.success("Berhasil!")
|
| 79 |
+
time.sleep(0.5)
|
| 80 |
+
progress_bar.empty()
|
| 81 |
+
status_text.empty()
|
| 82 |
+
|
| 83 |
+
# Tampilan Kartu Video
|
| 84 |
+
col1, col2 = st.columns([1, 2])
|
| 85 |
+
with col1:
|
| 86 |
+
st.image(info.get('thumbnail'), use_container_width=True)
|
| 87 |
+
with col2:
|
| 88 |
+
st.subheader(info.get('title'))
|
| 89 |
+
st.caption(f"Durasi: {info.get('duration_string')} | Platform: {info.get('extractor_key')}")
|
| 90 |
+
|
| 91 |
+
# LINK DOWNLOAD LANGSUNG (Direct URL)
|
| 92 |
+
# Streamlit tidak perlu proxy server rumit, kita bisa kasih link asli
|
| 93 |
+
# atau stream link yang didapat yt-dlp
|
| 94 |
+
download_url = info.get('url')
|
| 95 |
+
|
| 96 |
+
st.link_button("⬇️ Download Video", download_url)
|
| 97 |
+
|
| 98 |
+
except Exception as e:
|
| 99 |
+
progress_bar.empty()
|
| 100 |
+
st.error(f"Gagal memproses video: {e}")
|
| 101 |
+
st.warning("Jika error berlanjut, kemungkinan server sedang diblokir oleh YouTube.")
|
| 102 |
+
|
| 103 |
+
st.markdown('</div>', unsafe_allow_html=True)
|