gpt4 book ai didi

python - 什么是用于在 Python 中验证文件的好音频库?

转载 作者:太空狗 更新时间:2023-10-30 00:08:22 24 4
gpt4 key购买 nike

我已经在检查内容类型、大小和扩展名 ( Django (audio) File Validation ),但我需要一个库来读取文件并确认它确实是我希望的(主要是 mp3 和 mp4) .

我来过这里:http://wiki.python.org/moin/Audio/但没有运气。在这里呆了一段时间,我有点迷失在树林里。依靠如此大的时间来完成这整个事情......

提前致谢。

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

"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."

所以,我已经在阅读标题了。但是我怎样才能验证文件的实际内容呢?

最佳答案

如果仅仅检查 header 还不够好,我建议使用 mutagen 加载文件。如果不正确,它应该抛出异常。

仅供引用,我认为您的方法不是很有可扩展性。 真的有必要读取文件的每个字节吗?您不信任文件头的原因是什么?

关于python - 什么是用于在 Python 中验证文件的好音频库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6541639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com