Files
Medios-Macina/hydrus_health_check.py

44 lines
1.3 KiB
Python
Raw Normal View History

2025-12-13 12:09:50 -08:00
"""Cookies availability helpers.
2025-11-25 20:09:33 -08:00
2025-12-13 12:09:50 -08:00
This module is intentionally limited to cookie-file resolution used by yt-dlp.
Other service availability checks live in their owning store/provider objects.
2025-11-25 20:09:33 -08:00
"""
import sys
from pathlib import Path
2025-12-13 12:09:50 -08:00
from typing import Any, Dict, Optional, Tuple
2025-11-25 20:09:33 -08:00
2025-12-13 12:09:50 -08:00
from SYS.logger import debug
2025-11-27 10:59:01 -08:00
2025-12-01 14:42:30 -08:00
# Global state for Cookies availability
_COOKIES_FILE_PATH: Optional[str] = None
2025-11-25 20:09:33 -08:00
2025-12-13 00:18:30 -08:00
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.
2025-12-11 12:47:30 -08:00
Returns a tuple of (found, detail_message).
"""
2025-12-01 14:42:30 -08:00
global _COOKIES_FILE_PATH
2025-12-13 00:18:30 -08:00
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():
2025-12-01 14:42:30 -08:00
_COOKIES_FILE_PATH = str(cookies_path)
2025-12-11 12:47:30 -08:00
if emit_debug:
2025-12-13 00:18:30 -08:00
debug(f"Cookies: ENABLED - Found cookies file", file=sys.stderr)
2025-12-11 12:47:30 -08:00
return True, str(cookies_path)
2025-12-01 14:42:30 -08:00
else:
_COOKIES_FILE_PATH = None
2025-12-11 12:47:30 -08:00
return False, "Not found"
2025-12-01 14:42:30 -08:00
def get_cookies_file_path() -> Optional[str]:
"""Get the path to the cookies.txt file if it exists."""
return _COOKIES_FILE_PATH