什么是Python中验证文件的良好的音频库? [英] What is a good audio library for validating files in Python?

查看:202
本文介绍了什么是Python中验证文件的良好的音频库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查的内容类型,大小和扩展名( Django的(音频)文件验证),但我需要一个库读取该文件,并确认它实际上是什么,我希望它是(MP3和MP4居多)。

I'm already checking for content-type, size, and extension (Django (audio) File Validation), but I need a library to read the file and confirm that it is in fact what I hope it is (mp3 and mp4 mostly).

我一直在这里: http://wiki.python.org/moin/Audio/ ,但没有运气。在这个一期一会了,我有点在树林里迷路。依托这么大的时候的事情这整个月底...

I've been here: http://wiki.python.org/moin/Audio/ but no luck. Been at this one for a while, am a bit lost in the woods. Relying on SO big time for this whole end of things...

先谢谢了。

编辑:
我已经使用UploadedFile.content_type(在Django)()

I'm already (in Django) using UploadedFile.content_type() :

内容类型的文件头和文件(如文本/纯或应用程序/ PDF),就像由用户提供的任何数据,你不应该相信,上传的文件实际上是这种类型的上传。您还是会需要验证的文件包含内容类型头要求内容 - 信任但要验证

"The content-type header uploaded with the file (e.g. text/plain or application/pdf). Like any data supplied by the user, you shouldn't trust that the uploaded file is actually this type. You'll still need to validate that the file contains the content that the content-type header claims -- "trust but verify."

所以,我已经读头。但我怎么能验证文件的实际内容?

So, I'm already reading the header. But how can I validate the actual content of the file?

推荐答案

如果只是检查头不够好,我推荐使用诱变剂加载文件。它应该抛出一个异常,如果它是不正确的。

If just checking the header isn't good enough, I'd recommend using mutagen to load the file. It should throw an exception if it's not correct.

仅供参考,我不认为你的做法是很可扩展性。是的真正的必要读取文件的每个字节?你的理由不信任的文件头是什么?

FYI, I do not think your approach is very scalable. Is it really necessary to read every byte of the file? What is your reason for not trusting the file header?

这篇关于什么是Python中验证文件的良好的音频库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆