我们正在用 Python 动态生成 MP3 文件,需要使用类似文件的对象在内存中编辑 ID3 header 。
PyPI 上的所有 ID3 库似乎 要求您将文件系统路径作为字符串传递。我觉得这很令人沮丧!
将我们生成的 MP3 写入磁盘(或 ramdisk)只是为了添加 ID3 标签是 Not Acceptable ,原因有很多,尤其是性能。
鉴于 ID3 库的丰富性,是否有一个 ID3 库可以简单地处理类文件对象?
最佳答案
对于那些在遥远的 future 找到这个答案的人,mutagen , 对我来说工作得很好,它的一个 MP3 对象的构造函数采用一个文件路径或一个类似文件的对象(文档称它为“filething”) .
来自 https://mutagen.readthedocs.io/en/latest/user/filelike.html :
The first argument passed to a FileType or Metadata can either be a file name or a file-like object, such as StringIO (BytesIO in Python 3) and mutagen will figure out what to do.
MP3("myfile.mp3") MP3(myfileobj)
关于python - 在 Python 中编辑类文件对象上的 MP3 元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1534374/