From 04e5a7e4043e2d9516429f0a404822bab53041ff Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 9 Aug 2022 15:54:58 +0200 Subject: [PATCH] feat(analyzer): override paths using env variables Allow overriding FFMPEG, FFPROBE, or LIQUIDSOAP paths using env variables. --- analyzer/libretime_analyzer/pipeline/_ffmpeg.py | 8 ++++++-- analyzer/libretime_analyzer/pipeline/_liquidsoap.py | 4 ++++ .../libretime_analyzer/pipeline/analyze_playability.py | 7 +++---- analyzer/tests/pipeline/analyze_playability_test.py | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 analyzer/libretime_analyzer/pipeline/_liquidsoap.py diff --git a/analyzer/libretime_analyzer/pipeline/_ffmpeg.py b/analyzer/libretime_analyzer/pipeline/_ffmpeg.py index 35dafdb73..5fe0381ca 100644 --- a/analyzer/libretime_analyzer/pipeline/_ffmpeg.py +++ b/analyzer/libretime_analyzer/pipeline/_ffmpeg.py @@ -1,14 +1,18 @@ import re from math import inf +from os import getenv from pathlib import Path from typing import List, Optional, Tuple from ._utils import run_ +FFPROBE = getenv("FFPROBE_PATH", "ffprobe") +FFMPEG = getenv("FFMPEG_PATH", "ffmpeg") + def _ffmpeg(*args, **kwargs): return run_( - "ffmpeg", + FFMPEG, *args, "-f", "null", @@ -20,7 +24,7 @@ def _ffmpeg(*args, **kwargs): def _ffprobe(*args, **kwargs): - return run_("ffprobe", *args, **kwargs) + return run_(FFPROBE, *args, **kwargs) _PROBE_REPLAYGAIN_RE = re.compile( diff --git a/analyzer/libretime_analyzer/pipeline/_liquidsoap.py b/analyzer/libretime_analyzer/pipeline/_liquidsoap.py new file mode 100644 index 000000000..0b9d27131 --- /dev/null +++ b/analyzer/libretime_analyzer/pipeline/_liquidsoap.py @@ -0,0 +1,4 @@ +from os import getenv + + +LIQUIDSOAP = getenv("LIQUIDSOAP_PATH", "liquidsoap") diff --git a/analyzer/libretime_analyzer/pipeline/analyze_playability.py b/analyzer/libretime_analyzer/pipeline/analyze_playability.py index 537f6705d..d157061ad 100644 --- a/analyzer/libretime_analyzer/pipeline/analyze_playability.py +++ b/analyzer/libretime_analyzer/pipeline/analyze_playability.py @@ -5,14 +5,13 @@ from typing import Any, Dict from loguru import logger +from ._liquidsoap import LIQUIDSOAP + class UnplayableFileError(Exception): pass -LIQUIDSOAP_EXECUTABLE = "liquidsoap" - - def analyze_playability(filename: str, metadata: Dict[str, Any]): """Checks if a file can be played by Liquidsoap. :param filename: The full path to the file to analyzer @@ -20,7 +19,7 @@ def analyze_playability(filename: str, metadata: Dict[str, Any]): :return: The metadata dictionary """ command = [ - LIQUIDSOAP_EXECUTABLE, + LIQUIDSOAP, "-v", "-c", "output.dummy(audio_to_stereo(single(argv(1))))", diff --git a/analyzer/tests/pipeline/analyze_playability_test.py b/analyzer/tests/pipeline/analyze_playability_test.py index 89b4b1c45..e41fc2eb2 100644 --- a/analyzer/tests/pipeline/analyze_playability_test.py +++ b/analyzer/tests/pipeline/analyze_playability_test.py @@ -21,7 +21,7 @@ def test_analyze_playability(filepath): def test_analyze_playability_missing_liquidsoap(): with patch( - "libretime_analyzer.pipeline.analyze_playability.LIQUIDSOAP_EXECUTABLE", + "libretime_analyzer.pipeline._liquidsoap.LIQUIDSOAP", "foobar", ): analyze_playability(str(FILES[0].path), {})