"""This module contains utils methods for extraction audio metadata.""" from constants import errors # noqa from constants import transcoding_types # noqa def get_lossless_flag(codec, mime_type): """Get lossless flag for m4a or flac mime types and codecs. Args: codec (str): Short codec name. mime_type (str): MIME type of input file object. Returns: bool: True if it's lossless. """ file_is_wav_pcm = ((mime_type in transcoding_types.WAV_MIME_TYPES) and ( codec == transcoding_types.PCM_CODEC_NAME)) file_is_flac = mime_type in transcoding_types.FLAC_MIME_TYPES file_is_m4a_alac = ((mime_type in transcoding_types.MP4_MIME_TYPES) and ( codec == transcoding_types.ALAC_CODEC_NAME)) if any([file_is_flac, file_is_m4a_alac, file_is_wav_pcm]): return True return False def get_channel_mode(channels): """Get channel mode for count of channels. Args: channels (int): count of channels. Returns: str: 'mono', 'stereo' or throw ValueError. Raises: ValueError: Invalid number of channels. """ if channels not in transcoding_types.AVAILABLE_CHANNELS_MODE: error_message = errors.CHANNEL_MODE_ERROR.format(channels=channels) raise ValueError(error_message) return transcoding_types.AVAILABLE_CHANNELS_MODE[channels]