What is a good audio library for checking files in Python?

I already check the content type, size and extension ( Django (audio) File Check ), but I need a library to read the file and confirm that this is actually what I hope for (mp3 and mp4 mostly).

I was here: http://wiki.python.org/moin/Audio/ but no luck. Some time ago, I got a little lost in the forest. Building on SO is a great time for all this end ...

Thanks in advance.

EDIT: I already (in Django) using UploadedFile.content_type ():

“The title of the content downloaded with the file (for example, text / plain or application / pdf). Like any data provided by the user, you should not trust that the downloaded file is actually a type. You’ll still need to check that the file contains content that the title of the content header requires - "trust but verify."

So, I am already reading the headline. But how can I check the actual contents of a file?

+6
source share
3 answers

If checking the header is not enough, I would recommend using mutagen to download the file. It should throw an exception if it is not correct.

FYI, I don’t think your approach is very scalable. Is it really necessary to read every byte of the file? What is the reason for rejecting the file header?

+2
source

You can call the unix sub-shell inside python as follows:

 >>> filename = 'Giant Steps.mp3' >>> import os >>> type = os.system('file %s' % filename) Giant Steps.mp3: ISO Media, MPEG v4 system, iTunes AAC-LC 

** See the man pages for more information on the file command if you want to go this route.

See this post for other options.


+2
source

Use sndhdr

This is slightly larger than the content type. Reads a file and gets its headers. Of course, this is still not reliable. Using ffmpeg is probably the only option.

0
source

Source: https://habr.com/ru/post/891769/


All Articles