diff --git a/requirements.txt b/requirements.txt index 88c9e51..973bdba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,10 +13,10 @@ pycairo==1.26.0 Pygments==2.18.0 PyGObject==3.48.2 pyradios==2.1.0 -python-mpv==1.0.6 python-vlc==3.0.20123 setuptools==70.0.0 sniffio==1.3.1 streamscrobbler3==0.0.4 tinydb==4.8.0 wcwidth==0.2.13 +mpv==1.0.7 diff --git a/xradios/__init__.py b/xradios/__init__.py index 6330707..9e48b46 100644 --- a/xradios/__init__.py +++ b/xradios/__init__.py @@ -1,5 +1,7 @@ import os import logging +import logging.config +from logging.handlers import RotatingFileHandler from appdirs import user_log_dir from appdirs import user_data_dir @@ -13,22 +15,29 @@ xradios_config_dir = Path(user_config_dir(appname=app_name)) xradios_config_dir.mkdir(parents=True, exist_ok=True) - xradios_data_dir = Path(user_data_dir(appname=app_name)) xradios_data_dir.mkdir(parents=True, exist_ok=True) - xradios_log_dir = Path(user_log_dir(appname=app_name)) xradios_log_dir.mkdir(parents=True, exist_ok=True) log_level = getattr(logging, os.environ.get("XRADIOS_LOG_LEVEL", "INFO")) if log_level == logging.DEBUG: - log_format = "%(levelname)s - %(name)s - %(module)s - %(funcName)s - %(message)s" + log_format = "%(levelname)s - %(name)s - %(filename)s -%(module)s - %(funcName)s - %(message)s" else: log_format = "%(levelname)s - %(name)s - %(message)s" log_file = "xradios.log" - -logging.basicConfig( - filename=xradios_log_dir / log_file, level=log_level, format=log_format +# logging.config.dictConfig(config={"level": log_level, "handlers": [], "version": 1}) +logging.basicConfig(level=log_level, format=log_format) + +logging.getLogger().handlers = [] +handler = RotatingFileHandler( + filename=xradios_log_dir / log_file, + maxBytes=5 * 1024 * 1024, + backupCount=2 ) +# handler.setLevel(log_level) +# handler.setFormatter(logging.Formatter(log_format)) +logging.getLogger("xradiosd").addHandler(handler) +logging.getLogger("xradios").addHandler(handler) diff --git a/xradios/core/player.py b/xradios/core/player.py index ac3da61..43b8122 100644 --- a/xradios/core/player.py +++ b/xradios/core/player.py @@ -11,7 +11,6 @@ class PlayerBase(ABC): - state = False @abstractmethod @@ -35,9 +34,24 @@ def playing(self): return self.state -class MPVPlayer(PlayerBase): +def log_handler(level, prefix, message): + func = getattr(log, level.lower(), log.info) # getattr default -> log.info + func(f"{prefix}: {message}") - player = MPV() + +class MPVPlayer(PlayerBase): + extra_mpv_opts = { + "cache": True, + "cache_secs": 10, + } + + player = MPV( + log_handler=log_handler, + loglevel=logging.getLevelName(log.root.level).lower(), + **extra_mpv_opts, + ) + log.debug(f"mpv --cache ---> {player['cache']}") + log.debug(f"mpv --cache-secs ---> {player.cache_secs}") def play(self, stationuuid): url = self._click_counter(stationuuid) diff --git a/xradios/tui/buffers/display.py b/xradios/tui/buffers/display.py index 318cda2..429a5d7 100644 --- a/xradios/tui/buffers/display.py +++ b/xradios/tui/buffers/display.py @@ -41,7 +41,7 @@ async def run(self): except Exception: pass else: - if all(result.values()): + if result and all(result.values()): self.metadata = result await asyncio.sleep(30)