ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

m4a files are detected as video #266

Closed anuj-scanova closed 2 years ago

anuj-scanova commented 2 years ago

Using this library in the Django project and using Django REST Framework. In the serializer's validate method, using the following code snippet to validate for the valid file extension using python-magic

    def validate(self, attrs):
        file = attrs.get('file')
        file_mime = magic.from_buffer(file.open('rb').read(2048), mime=True)
        log.info(f'File mime type : {file_mime}')

On uploading the m4a file (attached) it is detecting as video/mp4 file.

ahupp commented 2 years ago

python-magic delegates the actual identification logic to libmagic. You might be able to upgrade libmagic to get a more accurate identification. In this case I suspect the .m4a file is really an mp4 container that just happens to contain only an audio track vs audio+video. So libmagic would need to know more about the details of the format to accurately identify it.