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