"""Trafaret schemas for meta information of audio files.""" import trafaret as t from trafaret.keys import KeysSubset from src import config from src import custom_validators from src.constants import validation_const """For any changes that are made to audio metadata requirements, please update: https://github.com/theorchard/frontend-distribution/blob/b0f7ea92b0a2df8df145777abdb1b04b2c59c547/src/selectors/track-audio-validation-errors.js """ # noqa: E501 def get_schema() -> t.Dict: """Get trafaret schema for audio metadata validation.""" return t.Dict({ t.Key(validation_const.FILE_SIZE_BYTES): t.Int, t.Key(validation_const.MIME_TYPE): t.Or(*( t.Atom(mime_type) for mime_type in validation_const.ALLOWED_MIME_TYPES )), t.Key(validation_const.CONTAINER): t.Or(*( t.Atom(container) for container in validation_const.ALLOWED_CONTAINERS )), t.Key(validation_const.CODEC): t.Or(*( t.Atom(codec) for codec in validation_const.ALLOWED_CODECS )), t.Key(validation_const.DURATION_MS): t.Int(gte=config.MIN_DURATION_MS), t.Key(validation_const.BIT_RATE): t.Int, t.Key(validation_const.CHANNELS): t.Atom(2), t.Key(validation_const.SAMPLE_RATE): t.Int, KeysSubset( validation_const.SAMPLE_RATE, validation_const.BITS_PER_SAMPLE, ): custom_validators.sample_rate_validation, t.Key(validation_const.BITS_PER_SAMPLE): t.Or(*( t.Atom(bits_per_sample) for bits_per_sample in validation_const.ALLOWED_BITS_PER_SAMPLE )), t.Key(validation_const.LOSSLESS): t.Atom(True), }, allow_extra='*')