"""This module is responsible for extraction information about audio files.""" from common_config import logger # noqa from constants import transcoding_types # noqa def _get_codec_for_mutagen_object(mutagen_descriptor, mime_type): """Get codec from mutagen.flac.Flac or mutagen.m4a.M4a. Args: mutagen_descriptor (mutagen.File): Audio file descriptor. mime_type (str): Mime type of file object. Returns: str: flac, alac or throw ValueError Raises: AttributeError: Unexpected mutagen descriptor object. """ try: codec = '' if mime_type in transcoding_types.FLAC_MIME_TYPES: codec = transcoding_types.FLAC_CODEC_NAME elif mime_type in transcoding_types.MP4_MIME_TYPES: codec = mutagen_descriptor.info.codec return codec except AttributeError as e: logger.exception(str(e)) raise