3

I need to accept only MP4 videos and WMV videos in a Django web app I am building. For that, I am checking the mime type of the file once it hits the server.

As far as I understand, MP4 files have 'video/mp4' mime type, which is exactly what I am receiving on my web app. The problem comes with the WMV files, which according to every site I found (e.g.: this and that) should have 'video/x-ms-wmv' as the mime type. When I get this files on the server and I inspect them using python-magic I get 'video/x-ms-asf' as its mime type.

I have converted some youtube videos to WMV videos using different online converters but the result is always the same.

So actually, I do not know what am I doing wrong here.

  1. Maybe I have a problem of concets, where WMV videos can also have 'video/x-ms-asf' mime type, and not only 'video/x-ms-wmv'
  2. Maybe python-magic is not reading the mime type correctly, which I think would be hardly the case.

Any help is deeply appreciated.

As a side note, I am using python-magic instead of django's file.content_type because the second is not reliable. Just change the file's extension to the wrong one and file.content_type will give the extention mime type instead of the real one.

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64
Storo
  • 988
  • 1
  • 7
  • 31

2 Answers2

4

video/x-ms-asf is the correct MIME type as it is a catch-all for Windows Media files containing audio and video under the "Advanced System Format" family name.

Within the 'family', Audio only files (.wma) can use audio/x-ms-wma and Video/Audio files (.wmv) can use video/x-ms-wmv, but for content optimized for streaming it is common to reference the container family rather than the file extension in the MIME type.

Offbeatmammal
  • 7,970
  • 2
  • 33
  • 52
0

If python-magic wraps well-known libmagic library, the reason is in that libmagic actually can't determine the content of ASF files: https://bugs.astron.com/view.php?id=84

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64