diff --git a/src/dlhdhr/config.py b/src/dlhdhr/config.py index ef39016..f3b59ec 100644 --- a/src/dlhdhr/config.py +++ b/src/dlhdhr/config.py @@ -11,6 +11,7 @@ def _set_or_none(name: str) -> set[str] | None: HOST = os.getenv("DLHDHR_HOST", "127.0.0.1") PORT: int = int(os.getenv("DLHDHR_PORT", 8000)) +DEBUG: bool = os.getenv("DLHDHR_DEBUG", "0").lower() in ("1", "true") DLHD_BASE_URL = os.getenv("DLHD_BASE_URL", "https://dlhd.sx/") DLHD_INDEX_M3U8_PATTERN = os.getenv( diff --git a/src/dlhdhr/ffmpeg.py b/src/dlhdhr/ffmpeg.py index 612f4c2..e601e11 100644 --- a/src/dlhdhr/ffmpeg.py +++ b/src/dlhdhr/ffmpeg.py @@ -1,5 +1,7 @@ import asyncio +from dlhdhr import config + class FFMpegNotStartedError(Exception): pass @@ -11,6 +13,10 @@ class FFMpegProcess: _process: asyncio.subprocess.Process | None = None def __init__(self, playlist_url: str): + log_level = "quiet" + if config.DEBUG: + log_level = "debug" + self._ffmpeg_command = " ".join( [ "ffmpeg", @@ -27,7 +33,7 @@ class FFMpegProcess: "-f", "mpegts", "-loglevel", - "quiet", + log_level, "pipe:1", ] ) @@ -53,10 +59,16 @@ class FFMpegProcess: async def _start(self) -> None: if not self._process: + stderr = asyncio.subprocess.DEVNULL + if config.DEBUG: + # When debugging let ffmpeg write to normal stderr + # do we see the logs in the application stderr + stderr = None + self._process = await asyncio.subprocess.create_subprocess_shell( self._ffmpeg_command, stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.DEVNULL, + stderr=stderr, ) def _stop(self) -> None: