y-brehm / waveAlign

Python repo for audio loudness matching in order to end the loudness war between DJs.
3 stars 0 forks source link

If no metadata can be read from an audio file, an exception is thrown #36

Closed SimonZimmer closed 1 month ago

SimonZimmer commented 1 month ago

Instead, we should just process these files without transferring their metadata, since there are likely people out there who have tracks in their rekordbox library without any metadata.

maosi100 commented 1 month ago

This is the current implementation after 9d6b0a3 of metadata_extractor.py:

        try:
            metadata = File(file_path)
            if metadata is None:
                raise ValueError

Mutagens File() function returns a mutagen.FileType object if a valid file type (all of rekordbox supported filetypes) is accessed. Even if no metadata is present on the file such an object is returned. None is returned only if a non-supported filetype is accessed.

Therefore all valid filetypes with and without metadata are processed. If you're fine you can close this issue, otherwise let me know 🫡

SimonZimmer commented 1 month ago

@maosi100 Hmm according to this code in mutagen/_file.py, File returns None if the file-type is none of the ones supported by mutagen. But this is not the same as rekordbox.

        options = [MP3, TrueAudio, OggTheora, OggSpeex, OggVorbis, OggFLAC,
                   FLAC, AIFF, APEv2File, MP4, ID3FileType, WavPack,
                   Musepack, MonkeysAudio, OptimFROG, ASF, OggOpus, AAC, AC3,
                   SMF, TAK, DSF, DSDIFF, WAVE]

    if not options:
        return None

supported Rekordbox formats (https://support.pioneerdj.com/hc/en-us/articles/4408217704857-Which-file-formats-can-I-play)

We already have a non-exception throwing check for that in data_colletion/audio_file_finder.py:

    @staticmethod
    def __is_supported_audio_file(file_name: str) -> bool:
        file_extension = os.path.splitext(file_name)[1]
        supported_file_extensions = [".wav", ".aiff", ".aif", ".mp3", ".m4a", ".flac"]

        return file_extension in supported_file_extensions

So IMO we should just do this in metadata_extractor.py

class MetaDataExtractor:
    def extract(
        self,
        file_path: str,
    ) -> AudioMetadata:
    metadata = File(file_path)
    full_details = probe.full_details(file_path)
    audio_stream_metadata = full_details["streams"][0]
    bit_rate = self.__get_bitrate_specifier(audio_stream_metadata["bit_rate"])

    return AudioMetadata(
        num_channels=audio_stream_metadata["channels"],
        metadata=metadata,
        codec_name=audio_stream_metadata["codec_name"],
        bit_rate=bit_rate,
        sample_rate=audio_stream_metadata["sample_rate"],
    )

    @staticmethod
    def __get_bitrate_specifier(bit_rate: int) -> str:
        return f"{int(bit_rate / 1000)}k"
maosi100 commented 1 month ago

Wouldn't an .m4a file be treated as .mp4 and still be supported?

This module will read MPEG-4 audio information and metadata, as found in Apple’s MP4 (aka M4A, M4B, M4P) files.

But anyways since we are already checking for supported file formats it makes sense to exclude the check at metadata level 👌👌

SimonZimmer commented 1 month ago

Wouldn't an .m4a file be treated as .mp4 and still be supported?

Yes, the .m4a file would pass the check and therefore its metadata would be read by mutagen, which supports it. Do you think there's a problem here?

maosi100 commented 1 month ago

3e46f7c