libretime/analyzer/libretime_analyzer/pipeline/analyze_playability.py

33 lines
807 B
Python
Raw Permalink Normal View History

2023-02-26 01:27:00 +01:00
import logging
from subprocess import CalledProcessError
from typing import Any, Dict
from ._liquidsoap import _liquidsoap
2023-02-26 01:27:00 +01:00
logger = logging.getLogger(__name__)
2021-05-27 16:23:02 +02:00
class UnplayableFileError(Exception):
pass
2021-05-27 16:23:02 +02:00
def analyze_playability(filename: str, metadata: Dict[str, Any]):
"""
Checks if a file can be played by Liquidsoap.
"""
try:
_liquidsoap(
"-v",
*("-c", "output.dummy(audio_to_stereo(single(argv(1))))"),
"--",
filename,
)
except CalledProcessError as exception:
logger.warning(exception)
raise UnplayableFileError() from exception
except OSError as exception: # liquidsoap was not found
logger.warning("Failed to run: %s. Is liquidsoap installed?", exception)
return metadata