File size: 3,445 Bytes
f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 a4ebadd 5750f08 f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 f25e6b2 f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 f348d61 5750f08 |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
from flask import Flask, render_template_string, request, send_file, after_this_request
import yt_dlp
import os
import uuid
app = Flask(__name__)
# ---------------- HTML 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>
body { background:#0f172a; color:white; font-family:sans-serif; }
.glass { background:rgba(30,41,59,.85); backdrop-filter:blur(12px);
border-radius:16px; border:1px solid rgba(255,255,255,.1); }
.loader { border:3px solid #f3f3f3; border-top:3px solid #3498db;
border-radius:50%; width:18px; height:18px;
animation:spin 1s linear infinite; display:none; }
@keyframes spin {100%{transform:rotate(360deg)}}
</style>
</head>
<body class="flex items-center justify-center min-h-screen p-4">
<div class="glass w-full max-w-md p-6">
<h1 class="text-3xl text-center font-bold text-blue-400 mb-6">
UniLoader <span class="text-xs text-gray-400">HF Edition</span>
</h1>
<form method="POST" action="/download"
onsubmit="document.getElementById('sp').style.display='inline-block'"
class="space-y-4">
<input name="url" required
class="w-full bg-gray-900 border border-gray-700 p-3 rounded-lg"
placeholder="Paste YouTube / TikTok link">
<button class="w-full bg-blue-600 hover:bg-blue-700 p-3 rounded-lg
font-bold flex items-center justify-center gap-2">
Download Best Quality
<div id="sp" class="loader"></div>
</button>
</form>
{% if error %}
<div class="mt-4 bg-red-900/50 p-3 rounded text-center text-sm">
{{ error }}
</div>
{% endif %}
<p class="text-xs text-gray-400 mt-4 text-center">
Note: TikTok HD on Hugging Face is limited by platform.
</p>
</div>
</body>
</html>
"""
# ---------------- ROUTES ----------------
@app.route("/", methods=["GET"])
def index():
return render_template_string(HTML_CODE)
@app.route("/download", methods=["POST"])
def download():
url = request.form.get("url")
filename = f"video_{uuid.uuid4().hex[:6]}.mp4"
try:
ydl_opts = {
# 🔥 BEST POSSIBLE FORMAT (HF SAFE)
"format": (
"bv*[ext=mp4][height<=720]/"
"bv*[height<=720]/"
"best[height<=720]/best"
),
"outtmpl": filename,
"merge_output_format": "mp4",
# 🔥 Browser-like headers (slight quality improvement)
"http_headers": {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Accept-Language": "en-US,en;q=0.9",
},
"quiet": True,
"no_warnings": True,
"nocheckcertificate": True,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
@after_this_request
def cleanup(resp):
try:
if os.path.exists(filename):
os.remove(filename)
except:
pass
return resp
return send_file(filename, as_attachment=True)
except Exception as e:
return render_template_string(HTML_CODE, error=str(e))
# ---------------- RUN ----------------
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860) |