From b631dbae00e691e3089ff73980532bf8911b87b1 Mon Sep 17 00:00:00 2001 From: Hizkia Felix Winata Date: Mon, 22 May 2023 10:55:27 +0800 Subject: [PATCH] warn user on startup if ffmpeg is not available Closes #41 --- .gitignore | 2 ++ fc2_live_dl/FC2LiveDL.py | 12 ++++++++++++ fc2_live_dl/ffmpeg.py | 18 ++++++++++++++++++ setup.cfg | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e62193c..80a538f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ build/ *.egg-info .install-cache/ .vim/ +venv/ +.venv/ \ No newline at end of file diff --git a/fc2_live_dl/FC2LiveDL.py b/fc2_live_dl/FC2LiveDL.py index f50556d..580338f 100644 --- a/fc2_live_dl/FC2LiveDL.py +++ b/fc2_live_dl/FC2LiveDL.py @@ -87,6 +87,18 @@ async def __aexit__(self, *err): self._session = None async def download(self, channel_id): + # Check ffmpeg + if not await FFMpeg.is_available(): + if self.params["remux"]: + self._logger.error( + "ffmpeg not found in PATH, remuxing is not available" + ) + self._logger.error( + "please install ffmpeg or disable remuxing with --no-remux" + ) + raise FileNotFoundError(FFMpeg.FFMPEG_BIN) + + # Initialize self._logger = Logger("fc2 " + channel_id) tasks = [] fname_stream = None diff --git a/fc2_live_dl/ffmpeg.py b/fc2_live_dl/ffmpeg.py index 857488f..7566543 100644 --- a/fc2_live_dl/ffmpeg.py +++ b/fc2_live_dl/ffmpeg.py @@ -12,6 +12,24 @@ def __init__(self, flags): self._ffmpeg = None self._flags = flags + @classmethod + async def is_available(cls): + """ + Check if ffmpeg binary exists and is executable. + """ + + try: + proc = await asyncio.create_subprocess_exec( + cls.FFMPEG_BIN, + "-version", + stdout=asyncio.subprocess.DEVNULL, + stderr=asyncio.subprocess.DEVNULL, + ) + ret = await proc.wait() + return ret == 0 + except FileNotFoundError: + return False + async def __aenter__(self): self._loop = asyncio.get_running_loop() self._ffmpeg = await asyncio.create_subprocess_exec( diff --git a/setup.cfg b/setup.cfg index efb5f3a..c3b64ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = fc2-live-dl -version = 2.1.2 +version = 2.1.3 author = Hizkia Felix author_email = felix@hizkifw.me description = Download live streams from FC2