Update app.py
Browse files1 unmodified line234567891011121314151617184 unmodified lines232425262728293031321 unmodified line3435363738394041424344454647484950515253545556575859606162634 unmodified lines686970717273744 unmodified lines7980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341353 unmodified lines1391401411421431441453 unmodified lines14915015115215315415515613 unmodified lines1701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052063 unmodified lines2102112122132142152161 unmodified lineimport yt_dlpimport osimport uuidapp = Flask(__name__)# --- PROFESSIONAL ANIMATED UI ---HTML_CODE = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Neon Downloader Pro</title><script src="https://cdn.tailwindcss.com"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"><style>4 unmodified lines/* Animated Background */.bg-animate {position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);background-size: 400% 400%;animation: gradientBG 15s ease infinite;opacity: 0.2;}@keyframes gradientBG {0% { background-position: 0% 50%; }1 unmodified line100% { background-position: 0% 50%; }}/* Glass Card */.glass {background: rgba(20, 20, 20, 0.7);backdrop-filter: blur(16px);-webkit-backdrop-filter: blur(16px);border: 1px solid rgba(255, 255, 255, 0.1);box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);}/* Input Glow */.input-glow:focus {box-shadow: 0 0 20px rgba(0, 242, 234, 0.3);border-color: #00f2ea;}/* Button Animation */.btn-grad {background-image: linear-gradient(to right, #FF512F 0%, #DD2476 51%, #FF512F 100%);transition: 0.5s;background-size: 200% auto;}.btn-grad:hover { background-position: right center; transform: scale(1.02); }/* Loading Spinner */.loader {border: 3px solid rgba(255,255,255,0.3);border-radius: 50%;4 unmodified lines}@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }/* List Item Animation */.fade-in-up { animation: fadeInUp 0.5s ease-out forwards; opacity: 0; transform: translateY(20px); }@keyframes fadeInUp { to { opacity: 1; transform: translateY(0); } }</style>4 unmodified lines<div class="glass w-full max-w-lg rounded-3xl p-8 relative overflow-hidden"><div class="absolute -top-10 -right-10 w-32 h-32 bg-blue-500 rounded-full blur-[80px] opacity-40"></div><div class="absolute -bottom-10 -left-10 w-32 h-32 bg-pink-500 rounded-full blur-[80px] opacity-40"></div><div class="text-center mb-8 relative z-10"><h1 class="text-4xl font-bold mb-1 tracking-tight"><span class="text-transparent bg-clip-text bg-gradient-to-r from-cyan-400 to-blue-500">Video</span><span class="text-white">Hunter</span></h1><p class="text-gray-400 text-sm">Ultra HD • No Watermark • Fast</p></div><form method="POST" action="/fetch" onsubmit="showLoader()" class="space-y-5 relative z-10"><div class="relative"><i class="fa-solid fa-link absolute left-4 top-4 text-gray-400"></i><input type="text" name="url"class="input-glow w-full bg-black/40 border border-gray-700 rounded-xl py-3.5 pl-12 pr-4 text-white placeholder-gray-500 focus:outline-none transition-all duration-300"placeholder="Paste TikTok/Reel Link here..." required></div><button type="submit" id="searchBtn" class="btn-grad w-full py-4 rounded-xl font-bold text-lg shadow-lg flex justify-center items-center gap-2"><span>ANALYZE VIDEO</span><div class="loader" id="spinner"></div></button></form>{% if formats %}<div class="mt-8 space-y-3 relative z-10"><div class="flex items-center gap-2 mb-4"><div class="h-px bg-gray-700 flex-1"></div><span class="text-xs text-gray-400 uppercase tracking-widest">Select Quality</span><div class="h-px bg-gray-700 flex-1"></div></div>{% for f in formats %}<div class="fade-in-up" style="animation-delay: {{ loop.index0 * 100 }}ms"><form method="POST" action="/download" onsubmit="showDownloadLoader(this)"><input type="hidden" name="url" value="{{ url }}"><input type="hidden" name="format_id" value="{{ f.id }}"><button type="submit" class="group w-full bg-gray-800/50 hover:bg-gray-800 border border-gray-700/50 hover:border-blue-500/50 p-4 rounded-xl transition-all duration-300 flex justify-between items-center"><div class="text-left"><div class="flex items-center gap-2"><span class="font-bold text-white group-hover:text-blue-400 transition-colors">{{ f.label }}</span>{% if 'HD' in f.label or '1080' in f.label %}<span class="bg-blue-500/20 text-blue-300 text-[10px] px-2 py-0.5 rounded font-bold">HQ</span>{% endif %}</div><div class="text-xs text-gray-500 mt-1">{{ f.size }} • MP4</div></div><div class="w-10 h-10 rounded-full bg-gray-700 group-hover:bg-blue-600 flex items-center justify-center transition-all"><i class="fa-solid fa-download text-sm text-gray-300 group-hover:text-white"></i></div></button></form>3 unmodified lines{% endif %}{% if error %}<div class="mt-6 p-4 bg-red-500/10 border border-red-500/50 rounded-xl flex items-start gap-3 fade-in-up"><i class="fa-solid fa-circle-exclamation text-red-500 mt-1"></i><div class="text-red-200 text-sm">{{ error }}</div></div>3 unmodified lines<script>function showLoader() {document.getElementById('searchBtn').style.opacity = '0.8';document.getElementById('searchBtn').innerHTML = 'Processing... <div class="loader" style="display:inline-block"></div>';}function showDownloadLoader(form) {const btn = form.querySelector('button');13 unmodified linesdef fetch():url = request.form.get("url")try:# Optimized for Cloudopts = {'quiet': True, 'nocheckcertificate': True, 'user_agent': 'Mozilla/5.0'}with yt_dlp.YoutubeDL(opts) as ydl:info = ydl.extract_info(url, download=False)formats = []seen = set()for f in info.get('formats', []):if f.get('vcodec') != 'none' and f.get('ext') == 'mp4':h = f.get('height', 0)if h >= 1080: label = "1080p Full HD"elif h >= 720: label = "720p HD"else: label = f"{h}p SD"if label not in seen:size = f.get('filesize') or f.get('filesize_approx') or 0formats.append({'id': f['format_id'], 'label': label, 'size': f"{round(size/1e6,1)} MB", 'h': h})seen.add(label)formats.sort(key=lambda x: x['h'], reverse=True)return render_template_string(HTML_CODE, formats=formats, url=url)except Exception as e:return render_template_string(HTML_CODE, error=str(e))@app.route("/download", methods=["POST"])def dl():url = request.form.get("url")fid = request.form.get("format_id")name = f"VidHunter_{uuid.uuid4().hex[:5]}.mp4"try:opts = {'format': f'{fid}+bestaudio/best', 'outtmpl': name, 'merge_output_format': 'mp4'}with yt_dlp.YoutubeDL(opts) as ydl:ydl.download([url])3 unmodified linesreturn rreturn send_file(name, as_attachment=True)except Exception as e:return str(e)if __name__ == "__main__":app.run(host='0.0.0.0', port=7860)1 unmodified line23456789101112131415161718194 unmodified lines242526272829303132331 unmodified line35363738394041424344454647484950515253545556575859604 unmodified lines6566676869704 unmodified lines757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361373 unmodified lines1411421431441451461473 unmodified lines15115215315415515615715815913 unmodified lines1731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442453 unmodified lines2492502512522532542552561 unmodified lineimport yt_dlpimport osimport uuidimport reapp = Flask(__name__)# --- UNIVERSAL DOWNLOADER UI ---HTML_CODE = """<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Universal Video Downloader</title><script src="https://cdn.tailwindcss.com"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"><style>4 unmodified lines/* Animated Background */.bg-animate {position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;background: linear-gradient(-45deg, #ff0000, #2b2b2b, #00f2ea, #000000);background-size: 400% 400%;animation: gradientBG 15s ease infinite;opacity: 0.3;}@keyframes gradientBG {0% { background-position: 0% 50%; }1 unmodified line100% { background-position: 0% 50%; }}.glass {background: rgba(15, 15, 15, 0.8);backdrop-filter: blur(20px);border: 1px solid rgba(255, 255, 255, 0.1);box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);}.input-glow:focus {box-shadow: 0 0 25px rgba(255, 0, 0, 0.4);border-color: #ff0000;}/* Universal Button Gradient */.btn-grad {background-image: linear-gradient(to right, #E50914 0%, #DB4437 51%, #E50914 100%); /* YouTube Red Colors */transition: 0.5s;background-size: 200% auto;}.btn-grad:hover { background-position: right center; transform: scale(1.02); }.loader {border: 3px solid rgba(255,255,255,0.3);border-radius: 50%;4 unmodified lines}@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }.fade-in-up { animation: fadeInUp 0.5s ease-out forwards; opacity: 0; transform: translateY(20px); }@keyframes fadeInUp { to { opacity: 1; transform: translateY(0); } }</style>4 unmodified lines<div class="glass w-full max-w-lg rounded-3xl p-8 relative overflow-hidden"><div class="absolute top-4 right-4 flex gap-3 opacity-50"><i class="fa-brands fa-youtube text-2xl text-red-500"></i><i class="fa-brands fa-tiktok text-2xl text-pink-500"></i><i class="fa-brands fa-instagram text-2xl text-purple-500"></i></div><div class="text-center mb-8 relative z-10"><h1 class="text-4xl font-bold mb-1 tracking-tight"><span class="text-white">Uni</span><span class="text-red-500">Loader</span></h1><p class="text-gray-400 text-sm">YouTube • TikTok • Instagram • Shorts</p></div><form method="POST" action="/fetch" onsubmit="showLoader()" class="space-y-5 relative z-10"><div class="relative"><i class="fa-solid fa-link absolute left-4 top-4 text-gray-400"></i><input type="text" name="url"class="input-glow w-full bg-black/50 border border-gray-700 rounded-xl py-3.5 pl-12 pr-4 text-white placeholder-gray-500 focus:outline-none transition-all duration-300"placeholder="Paste YouTube or TikTok Link..." required></div><button type="submit" id="searchBtn" class="btn-grad w-full py-4 rounded-xl font-bold text-lg shadow-lg flex justify-center items-center gap-2"><span>FETCH VIDEO</span><div class="loader" id="spinner"></div></button></form>{% if title %}<div class="mt-6 p-4 bg-gray-800/50 rounded-xl border border-gray-700 fade-in-up"><div class="text-sm text-gray-400 mb-1">Video Found:</div><div class="font-bold text-white truncate">{{ title }}</div><div class="text-xs text-blue-400 mt-1"><i class="fa-solid fa-clock"></i> {{ duration }}</div></div>{% endif %}{% if formats %}<div class="mt-6 space-y-3 relative z-10"><div class="text-xs text-gray-400 uppercase tracking-widest text-center mb-4">Select Quality</div>{% for f in formats %}<div class="fade-in-up" style="animation-delay: {{ loop.index0 * 50 }}ms"><form method="POST" action="/download" onsubmit="showDownloadLoader(this)"><input type="hidden" name="url" value="{{ url }}"><input type="hidden" name="format_id" value="{{ f.id }}"><button type="submit" class="group w-full bg-gray-900/80 hover:bg-gray-800 border border-gray-700 hover:border-red-500 p-4 rounded-xl transition-all duration-300 flex justify-between items-center"><div class="text-left"><div class="flex items-center gap-2"><span class="font-bold text-xl text-white">{{ f.label }}</span>{% if '4K' in f.label or '1080' in f.label %}<span class="bg-red-600 text-white text-[10px] px-2 py-0.5 rounded font-bold">HD</span>{% endif %}</div><div class="text-xs text-gray-500 mt-1">{{ f.ext }} • {{ f.size }}</div></div><div class="w-10 h-10 rounded-full bg-gray-800 group-hover:bg-red-600 flex items-center justify-center transition-all"><i class="fa-solid fa-download text-sm text-gray-400 group-hover:text-white"></i></div></button></form>3 unmodified lines{% endif %}{% if error %}<div class="mt-6 p-4 bg-red-900/30 border border-red-500 rounded-xl flex items-start gap-3 fade-in-up"><i class="fa-solid fa-circle-exclamation text-red-500 mt-1"></i><div class="text-red-200 text-sm">{{ error }}</div></div>3 unmodified lines<script>function showLoader() {const btn = document.getElementById('searchBtn');btn.style.opacity = '0.8';btn.innerHTML = 'Analyzing... <div class="loader" style="display:inline-block"></div>';}function showDownloadLoader(form) {const btn = form.querySelector('button');13 unmodified linesdef fetch():url = request.form.get("url")try:# Options optimized for YouTube & TikTokopts = {'quiet': True,'nocheckcertificate': True,'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',}with yt_dlp.YoutubeDL(opts) as ydl:info = ydl.extract_info(url, download=False)formats = []seen = set()# Metadatavideo_title = info.get('title', 'Unknown Video')duration = info.get('duration_string', 'Unknown')for f in info.get('formats', []):# Filter for Video streamsif f.get('vcodec') != 'none':h = f.get('height', 0)if not h: continue# Smart Labelingif h >= 2160: label = "4K Ultra HD"elif h >= 1440: label = "2K Quad HD"elif h >= 1080: label = "1080p Full HD"elif h >= 720: label = "720p HD"elif h >= 480: label = "480p SD"else: label = f"{h}p Low"# Avoid duplicatesif label not in seen:size = f.get('filesize') or f.get('filesize_approx') or 0size_str = f"{round(size/1e6,1)} MB" if size > 0 else "N/A"formats.append({'id': f['format_id'],'label': label,'size': size_str,'h': h,'ext': f['ext'].upper()})seen.add(label)# Sort highest quality firstformats.sort(key=lambda x: x['h'], reverse=True)return render_template_string(HTML_CODE, formats=formats, url=url, title=video_title, duration=duration)except Exception as e:return render_template_string(HTML_CODE, error=f"Error: {str(e)}")@app.route("/download", methods=["POST"])def dl():url = request.form.get("url")fid = request.form.get("format_id")# Clean filenamename = f"Video_{uuid.uuid4().hex[:5]}.mp4"try:# YouTube Logic: Download Video+Audio separately and Mergeopts = {'format': f'{fid}+bestaudio/best', # This magic line handles 4K YouTube audio merging'outtmpl': name,'merge_output_format': 'mp4','nocheckcertificate': True,}with yt_dlp.YoutubeDL(opts) as ydl:ydl.download([url])3 unmodified linesreturn rreturn send_file(name, as_attachment=True)except Exception as e:return f"Download Failed: {str(e)}"if __name__ == "__main__":app.run(host='0.0.0.0', port=7860)
app.py+92-52