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 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-02-09 18:39:35 +00:00
parent c5505417a5
commit be3b1ca706
1 changed files with 7 additions and 1 deletions

View File

@ -2,7 +2,9 @@
import os import os
import re import re
import shutil
import logging import logging
import tempfile
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional from typing import Optional
@ -38,7 +40,11 @@ def extract_video_id(url: str) -> Optional[str]:
def _base_opts() -> dict: def _base_opts() -> dict:
opts = {"quiet": True, "no_warnings": True} opts = {"quiet": True, "no_warnings": True}
if COOKIES_FILE and os.path.exists(COOKIES_FILE): 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 return opts