Upload app.py
Browse files7 unmodified lines8910111112131454 unmodified lines69707172727374757677787980818283847576778586878889909192939495969798991001011021034 unmodified lines10810911088111112113114115116117118119911201211221231241251261271281291301311321331341351361371381391401417 unmodified lines# --- DNS BYPASS PATCH START ---BYPASS_DOMAINS = [ "youtube.com", "googlevideo.com", "youtu.be", "vimeocdn.com", "vimeo.com", "vimeocdn.com", "dailymotion.com", "dmcdn.net", "twitch.tv", "ttvnw.net", "facebook.com", "fbcdn.net",54 unmodified lines return jsonify({"error": "URL is missing"}), 400 url = data['url'] try: ydl_opts = {'quiet': True, 'noplaylist': True, 'skip_download': True, 'simulate': True, 'force_formats': True, 'cache_dir': '/tmp/.yt-dlp-cache', 'force_ipv4': True} # 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) formats = info.get('formats', []) best = next((f for f in formats if f.get('ext') == 'mp4' and f.get('acodec') != 'none'), formats[-1] if formats else None) return jsonify({"status": "ok", "download_url": best.get('url') if best else None, "title": info.get('title'), "thumbnail": info.get('thumbnail')}) # 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
4 unmodified lines return jsonify({"error": "M3U8 URL is missing"}), 400 m3u8_url = data['url'] try: ydl_opts = {'quiet': True, 'skip_download': True, 'force_ipv4': True, 'format': 'best'} # For HLS, we want to find the best quality variant manifest ydl_opts = { 'quiet': True, 'skip_download': True, 'force_ipv4': True, 'format': 'best' } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(m3u8_url, download=False) return jsonify({"status": "ok", "download_url": info.get('url'), "title": info.get('title', 'HLS Stream'), "protocol": info.get('protocol'), "ext": info.get('ext')}) # If it's a master manifest, yt-dlp extracts sub-manifests into 'formats' formats = info.get('formats', []) if formats: # The formats list is usually sorted by quality (worst to best) best_format = formats[-1] download_url = best_format.get('url') else: # Direct stream or single-variant manifest download_url = info.get('url')
return jsonify({ "status": "ok", "download_url": download_url, "title": info.get('title', 'HLS Stream'), "protocol": info.get('protocol'), "ext": info.get('ext'), "is_variant": len(formats) > 0 }) except Exception as e: return jsonify({"error": str(e)}), 500
app.py+54-7