44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""Cookies availability helpers.
|
|
|
|
This module is intentionally limited to cookie-file resolution used by yt-dlp.
|
|
Other service availability checks live in their owning store/provider objects.
|
|
"""
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
from typing import Any, Dict, Optional, Tuple
|
|
|
|
from SYS.logger import debug
|
|
|
|
# Global state for Cookies availability
|
|
_COOKIES_FILE_PATH: Optional[str] = None
|
|
|
|
|
|
def initialize_cookies_check(config: Optional[Dict[str, Any]] = None, emit_debug: bool = True) -> Tuple[bool, str]:
|
|
"""Resolve cookies file path from config, falling back to cookies.txt in app root.
|
|
|
|
Returns a tuple of (found, detail_message).
|
|
"""
|
|
global _COOKIES_FILE_PATH
|
|
|
|
try:
|
|
from config import resolve_cookies_path
|
|
cookies_path = resolve_cookies_path(config or {}, script_dir=Path(__file__).parent)
|
|
except Exception:
|
|
cookies_path = None
|
|
|
|
if cookies_path and cookies_path.exists():
|
|
_COOKIES_FILE_PATH = str(cookies_path)
|
|
if emit_debug:
|
|
debug(f"Cookies: ENABLED - Found cookies file", file=sys.stderr)
|
|
return True, str(cookies_path)
|
|
else:
|
|
_COOKIES_FILE_PATH = None
|
|
return False, "Not found"
|
|
|
|
|
|
def get_cookies_file_path() -> Optional[str]:
|
|
"""Get the path to the cookies.txt file if it exists."""
|
|
return _COOKIES_FILE_PATH
|