""" libmpv availability probe ========================= python-mpv is a ctypes binding: importing it raises OSError when the libmpv shared library is missing from the system. All player code must import mpv through probe_player() so the rest of the app (search, browse, downloads) keeps working without libmpv installed. """ from typing import Optional, Tuple from ..utils.ytsage_constants import OS_NAME from ..utils.ytsage_logger import logger _probe_result: Optional[Tuple[bool, str]] = None def probe_player() -> Tuple[bool, str]: """Return (available, hint). hint explains how to install libmpv when absent.""" global _probe_result if _probe_result is not None: return _probe_result try: import mpv # noqa: F401 _probe_result = (True, "") except (ImportError, OSError, AttributeError) as e: logger.warning(f"libmpv unavailable, watch features disabled: {e}") if OS_NAME == "Windows": hint = "Place libmpv-2.dll next to the application, or install mpv and add it to PATH." elif OS_NAME == "Darwin": hint = "Install mpv with Homebrew: brew install mpv" else: hint = "Install mpv with your package manager, e.g. sudo pacman -S mpv or sudo apt install libmpv2" _probe_result = (False, hint) return _probe_result