2023-02-26 01:27:00 +01:00
|
|
|
import logging
|
2022-08-09 15:56:52 +02:00
|
|
|
from subprocess import CalledProcessError
|
2022-01-17 20:31:43 +01:00
|
|
|
from typing import Any, Dict
|
2021-06-03 15:20:39 +02:00
|
|
|
|
2022-08-09 15:56:52 +02:00
|
|
|
from ._liquidsoap import _liquidsoap
|
2022-08-09 15:54:58 +02:00
|
|
|
|
2023-02-26 01:27:00 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2014-12-11 21:45:45 +01:00
|
|
|
class UnplayableFileError(Exception):
|
|
|
|
pass
|
|
|
|
|
2021-05-27 16:23:02 +02:00
|
|
|
|
2022-01-17 20:31:43 +01:00
|
|
|
def analyze_playability(filename: str, metadata: Dict[str, Any]):
|
|
|
|
"""
|
2022-08-09 15:56:52 +02:00
|
|
|
Checks if a file can be played by Liquidsoap.
|
|
|
|
"""
|
2022-01-17 20:31:43 +01:00
|
|
|
try:
|
2022-08-09 15:56:52 +02:00
|
|
|
_liquidsoap(
|
|
|
|
"-v",
|
|
|
|
*("-c", "output.dummy(audio_to_stereo(single(argv(1))))"),
|
|
|
|
"--",
|
|
|
|
filename,
|
2022-01-17 20:31:43 +01:00
|
|
|
)
|
2022-08-09 15:56:52 +02:00
|
|
|
except CalledProcessError as exception:
|
2022-08-09 20:49:04 +02:00
|
|
|
logger.warning(exception)
|
|
|
|
raise UnplayableFileError() from exception
|
2022-01-17 20:31:43 +01:00
|
|
|
|
2022-08-09 15:56:52 +02:00
|
|
|
except OSError as exception: # liquidsoap was not found
|
2023-02-26 12:01:59 +01:00
|
|
|
logger.warning("Failed to run: %s. Is liquidsoap installed?", exception)
|
2022-08-09 15:56:52 +02:00
|
|
|
|
2022-01-17 20:31:43 +01:00
|
|
|
return metadata
|