Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,14 @@
|
|
| 1 |
-
# ---
|
| 2 |
import socket
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# Paksa pakai Google DNS (8.8.8.8) untuk tembus blokir jaringan
|
| 6 |
def custom_dns_lookup(host, port=0, family=0, type=0, proto=0, flags=0):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
resolver = dns.resolver.Resolver()
|
| 10 |
-
resolver.nameservers = ['8.8.8.8', '8.8.4.4']
|
| 11 |
-
answers = resolver.resolve(host, 'A')
|
| 12 |
-
ip = answers[0].to_text()
|
| 13 |
-
return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (ip, port))]
|
| 14 |
-
except:
|
| 15 |
-
pass
|
| 16 |
return socket.getaddrinfo_original(host, port, family, type, proto, flags)
|
| 17 |
|
| 18 |
socket.getaddrinfo_original = socket.getaddrinfo
|
| 19 |
socket.getaddrinfo = custom_dns_lookup
|
| 20 |
-
# --------------------
|
| 21 |
|
| 22 |
from flask import Flask, render_template, request, send_file
|
| 23 |
import yt_dlp
|
|
@@ -51,7 +42,7 @@ def download():
|
|
| 51 |
|
| 52 |
output_template = os.path.join(DOWNLOAD_FOLDER, "%(title)s.%(ext)s")
|
| 53 |
|
| 54 |
-
# KONFIGURASI
|
| 55 |
ydl_opts = {
|
| 56 |
"outtmpl": output_template,
|
| 57 |
"format": f"bestvideo[height<={quality}]+bestaudio/best" if format_type == "mp4" else "bestaudio/best",
|
|
@@ -59,17 +50,9 @@ def download():
|
|
| 59 |
"nocheckcertificate": True,
|
| 60 |
"quiet": True,
|
| 61 |
"no_warnings": True,
|
| 62 |
-
#
|
| 63 |
-
|
| 64 |
-
"
|
| 65 |
-
"youtube": {
|
| 66 |
-
"player_client": ["ios", "android", "web"],
|
| 67 |
-
"player_skip": ["webpage", "configs", "js"],
|
| 68 |
-
}
|
| 69 |
-
},
|
| 70 |
-
"http_headers": {
|
| 71 |
-
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1",
|
| 72 |
-
}
|
| 73 |
}
|
| 74 |
|
| 75 |
if format_type == "mp3":
|
|
@@ -89,13 +72,12 @@ def download():
|
|
| 89 |
time.sleep(1)
|
| 90 |
list_of_files = glob.glob(os.path.join(DOWNLOAD_FOLDER, "*"))
|
| 91 |
if not list_of_files:
|
| 92 |
-
return "Gagal: Video tidak ditemukan
|
| 93 |
|
| 94 |
latest_file = max(list_of_files, key=os.path.getctime)
|
| 95 |
return send_file(latest_file, as_attachment=True)
|
| 96 |
|
| 97 |
except Exception as e:
|
| 98 |
-
# Tampilkan error spesifik agar kita tahu jika butuh cookies
|
| 99 |
return f"Error: {str(e)}"
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
# --- SYSTEM PATCH ---
|
| 2 |
import socket
|
| 3 |
+
# Bypass DNS standar
|
|
|
|
|
|
|
| 4 |
def custom_dns_lookup(host, port=0, family=0, type=0, proto=0, flags=0):
|
| 5 |
+
# Biarkan sistem memilih jalur terbaik (IPv4/IPv6) secara alami
|
| 6 |
+
# Karena kita akan pakai Cookies, biasanya IP tidak dipermasalahkan lagi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
return socket.getaddrinfo_original(host, port, family, type, proto, flags)
|
| 8 |
|
| 9 |
socket.getaddrinfo_original = socket.getaddrinfo
|
| 10 |
socket.getaddrinfo = custom_dns_lookup
|
| 11 |
+
# --------------------
|
| 12 |
|
| 13 |
from flask import Flask, render_template, request, send_file
|
| 14 |
import yt_dlp
|
|
|
|
| 42 |
|
| 43 |
output_template = os.path.join(DOWNLOAD_FOLDER, "%(title)s.%(ext)s")
|
| 44 |
|
| 45 |
+
# KONFIGURASI DENGAN COOKIES (SOLUSI FINAL "SIGN IN")
|
| 46 |
ydl_opts = {
|
| 47 |
"outtmpl": output_template,
|
| 48 |
"format": f"bestvideo[height<={quality}]+bestaudio/best" if format_type == "mp4" else "bestaudio/best",
|
|
|
|
| 50 |
"nocheckcertificate": True,
|
| 51 |
"quiet": True,
|
| 52 |
"no_warnings": True,
|
| 53 |
+
# INI KUNCINYA: Membaca file cookies.txt yang Anda upload
|
| 54 |
+
"cookiefile": "cookies.txt",
|
| 55 |
+
"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",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
if format_type == "mp3":
|
|
|
|
| 72 |
time.sleep(1)
|
| 73 |
list_of_files = glob.glob(os.path.join(DOWNLOAD_FOLDER, "*"))
|
| 74 |
if not list_of_files:
|
| 75 |
+
return "Gagal: Video tidak ditemukan."
|
| 76 |
|
| 77 |
latest_file = max(list_of_files, key=os.path.getctime)
|
| 78 |
return send_file(latest_file, as_attachment=True)
|
| 79 |
|
| 80 |
except Exception as e:
|
|
|
|
| 81 |
return f"Error: {str(e)}"
|
| 82 |
|
| 83 |
if __name__ == "__main__":
|