From be3b1ca7068dd99dccd9501e154a989b20270b45 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Mon, 9 Feb 2026 18:39:35 +0000 Subject: [PATCH] fix: copy cookies to temp file so yt-dlp doesn't overwrite originals yt-dlp saves rotated cookies back on exit, destroying fresh exports. Co-Authored-By: Claude Opus 4.6 --- backend/app/services/download.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/app/services/download.py b/backend/app/services/download.py index 485e3b4..c28afe4 100644 --- a/backend/app/services/download.py +++ b/backend/app/services/download.py @@ -2,7 +2,9 @@ import os import re +import shutil import logging +import tempfile from dataclasses import dataclass from typing import Optional @@ -38,7 +40,11 @@ def extract_video_id(url: str) -> Optional[str]: def _base_opts() -> dict: opts = {"quiet": True, "no_warnings": True} if COOKIES_FILE and os.path.exists(COOKIES_FILE): - opts["cookiefile"] = COOKIES_FILE + # Copy cookies to a temp file so yt-dlp doesn't overwrite the original + tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".txt") + shutil.copy2(COOKIES_FILE, tmp.name) + tmp.close() + opts["cookiefile"] = tmp.name return opts