refactor(analyzer): rewrite analyze playability
This commit is contained in:
parent
04e5a7e404
commit
dc30d8836b
|
@ -1,4 +1,9 @@
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
|
||||||
|
from ._utils import run_
|
||||||
|
|
||||||
LIQUIDSOAP = getenv("LIQUIDSOAP_PATH", "liquidsoap")
|
LIQUIDSOAP = getenv("LIQUIDSOAP_PATH", "liquidsoap")
|
||||||
|
|
||||||
|
|
||||||
|
def _liquidsoap(*args, **kwargs):
|
||||||
|
return run_(LIQUIDSOAP, *args, **kwargs)
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
__author__ = "asantoni"
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
import subprocess
|
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from ._liquidsoap import LIQUIDSOAP
|
from ._liquidsoap import _liquidsoap
|
||||||
|
|
||||||
|
|
||||||
class UnplayableFileError(Exception):
|
class UnplayableFileError(Exception):
|
||||||
|
@ -13,31 +11,21 @@ class UnplayableFileError(Exception):
|
||||||
|
|
||||||
|
|
||||||
def analyze_playability(filename: str, metadata: Dict[str, Any]):
|
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
|
|
||||||
:param metadata: A metadata dictionary where the results will be put
|
|
||||||
:return: The metadata dictionary
|
|
||||||
"""
|
"""
|
||||||
command = [
|
Checks if a file can be played by Liquidsoap.
|
||||||
LIQUIDSOAP,
|
"""
|
||||||
"-v",
|
|
||||||
"-c",
|
|
||||||
"output.dummy(audio_to_stereo(single(argv(1))))",
|
|
||||||
"--",
|
|
||||||
filename,
|
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(command, stderr=subprocess.STDOUT, close_fds=True)
|
_liquidsoap(
|
||||||
|
"-v",
|
||||||
except OSError as exception: # liquidsoap was not found
|
*("-c", "output.dummy(audio_to_stereo(single(argv(1))))"),
|
||||||
logger.warning(
|
"--",
|
||||||
f"Failed to run: {command[0]} - {exception}. Is liquidsoap installed?"
|
filename,
|
||||||
)
|
)
|
||||||
except (
|
except CalledProcessError as exception:
|
||||||
subprocess.CalledProcessError,
|
|
||||||
Exception,
|
|
||||||
) as exception: # liquidsoap returned an error code
|
|
||||||
logger.warning(exception)
|
logger.warning(exception)
|
||||||
raise UnplayableFileError() from exception
|
raise UnplayableFileError() from exception
|
||||||
|
|
||||||
|
except OSError as exception: # liquidsoap was not found
|
||||||
|
logger.warning(f"Failed to run: {exception}. Is liquidsoap installed?")
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
Loading…
Reference in New Issue