From a8c5a3c7d59f6b3f23759bbbfac788595f19d697 Mon Sep 17 00:00:00 2001 From: mazezen Date: Mon, 25 May 2026 13:48:39 +0800 Subject: [PATCH] fix[click download: Access denied by the platform] --- app.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 703f435f..127f2fe2 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,15 @@ DOWNLOAD_DIR = os.path.join(os.path.dirname(__file__), "downloads") os.makedirs(DOWNLOAD_DIR, exist_ok=True) +# Path to yt-dlp (use Homebrew version which has YouTube fixes) +YT_DLP_PATH = os.environ.get("YT_DLP_PATH", "/opt/homebrew/bin/yt-dlp") + +# Browser for yt-dlp cookie extraction (set to empty string to disable) +COOKIES_BROWSER = os.environ.get("COOKIES_BROWSER", "brave") + +# Build --cookies-from-browser args if configured +COOKIE_ARGS = ["--cookies-from-browser", COOKIES_BROWSER] if COOKIES_BROWSER else [] + jobs = {} @@ -17,7 +26,9 @@ def run_download(job_id, url, format_choice, format_id): job = jobs[job_id] out_template = os.path.join(DOWNLOAD_DIR, f"{job_id}.%(ext)s") - cmd = ["yt-dlp", "--no-playlist", "-o", out_template] + cmd = [YT_DLP_PATH, "--no-playlist", "-o", out_template] + cmd += COOKIE_ARGS + cmd += ["--extractor-retries", "3", "--retries", "5"] if format_choice == "audio": cmd += ["-x", "--audio-format", "mp3"] @@ -85,7 +96,7 @@ def get_info(): if not url: return jsonify({"error": "No URL provided"}), 400 - cmd = ["yt-dlp", "--no-playlist", "-j", url] + cmd = [YT_DLP_PATH, "--no-playlist"] + COOKIE_ARGS + ["-j", url] try: result = subprocess.run(cmd, capture_output=True, text=True, timeout=60) if result.returncode != 0: