We're generating MP3 files on the fly in Python, and need to edit the ID3 headers in-memory using a file-like object.
All the ID3 libraries on PyPI appear to require you to pass a filesystem path as a string. I find this rather frustrating!
Writing our generated MP3 out to disk (or ramdisk) just to add ID3 tags is unacceptable for a number of reasons, especially performance.
Given the plentitude of ID3 libraries, is there an ID3 library that simply works with file-like objects?
For those finding this answer in the distant future, mutagen, has worked perfectly for me and the constructor for one of its MP3 objects takes either a file path or a file-like object (the docs call it a 'filething').
From 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With