Delete app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import socketimport sysimport osfrom flask import Flask, request, jsonifyimport yt_dlpfrom yt_dlp.utils import DownloadError
# --- DNS BYPASS PATCH START ---BYPASS_DOMAINS = [ "youtube.com", "googlevideo.com", "youtu.be", "vimeo.com", "vimeocdn.com", "dailymotion.com", "dmcdn.net", "twitch.tv", "ttvnw.net", "facebook.com", "fbcdn.net", "instagram.com", "tiktok.com", "bilibili.com", "biliapi.net"]
try: import dns.resolver _original_getaddrinfo = socket.getaddrinfo
def patched_getaddrinfo(host, port, family=0, type=0, proto=0, flags=0): if host and any(domain in host for domain in BYPASS_DOMAINS): try: res = dns.resolver.Resolver() res.nameservers = ['8.8.8.8', '1.1.1.1'] answers = res.resolve(host, 'A') ip_address = answers[0].to_text() return [(socket.AF_INET, type, proto, '', (ip_address, port))] except Exception: return _original_getaddrinfo(host, port, family, type, proto, flags) return _original_getaddrinfo(host, port, family, type, proto, flags)
socket.getaddrinfo = patched_getaddrinfo print(f"[INIT] DNS Bypass installed for {len(BYPASS_DOMAINS)} domains.", file=sys.stderr)except ImportError: print("❌ CRITICAL: dnspython not installed. DNS Bypass failed.", file=sys.stderr)# --- DNS BYPASS PATCH END ---
app = Flask(__name__)
def log(msg): print(f"[DEBUG] {msg}", file=sys.stderr)
@app.route('/')def index(): return "api is running."
@app.route('/info', methods=['POST'])def get_info(): data = request.get_json() if not data or 'url' not in data: return jsonify({"error": "URL is missing"}), 400 url = data['url'] try: ydl_opts = {'quiet': True, 'noplaylist': True, 'skip_download': True, 'force_ipv4': True, 'cache_dir': '/tmp/.yt-dlp-cache'} with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=False) sanitized_info = ydl.sanitize_info(info) return jsonify({"status": "ok", "info": sanitized_info}) except Exception as e: return jsonify({"error": str(e)}), 500
@app.route('/get_link', methods=['POST'])def get_link(): data = request.get_json() if not data or 'url' not in data: return jsonify({"error": "URL is missing"}), 400 url = data['url'] try: # Improved format selection for better quality ydl_opts = { 'quiet': True, 'noplaylist': True, 'skip_download': True, 'simulate': True, 'force_formats': True, 'cache_dir': '/tmp/.yt-dlp-cache', 'force_ipv4': True, 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=False) # yt-dlp with the above format string will put the best direct link in 'url' # but we also provide a fallback check in formats download_url = info.get('url') if not download_url and info.get('formats'): # Fallback to manual selection if 'url' is missing formats = info.get('formats', []) best = next((f for f in reversed(formats) if f.get('ext') == 'mp4' and f.get('acodec') != 'none'), formats[-1]) download_url = best.get('url')
return jsonify({ "status": "ok", "download_url": download_url, "title": info.get('title'), "thumbnail": info.get('thumbnail') }) except Exception as e: return jsonify({"error": str(e)}), 500
if __name__ == "__main__": port = int(os.environ.get("PORT", 7860)) app.run(host='0.0.0.0', port=port)app.pyDeleted-108