TagPy

TagPy is a set of Python bindings for Scott Wheeler's TagLib. It builds upon Boost.Python, a wrapper generation library which is part of the Boost set of C++ libraries 3.

Just like TagLib, TagPy can:

  • read and write ID3 tags of version 1 and 2, with many supported frame types for version 2 (in MPEG Layer 2 and MPEG Layer 3, FLAC and MPC),
  • access Xiph Comments in Ogg Vorbis Files and Ogg Flac Files,
  • access APE tags in Musepack and MP3 files.

All these features have their own specific interfaces, but TagLib's generic tag reading and writing mechanism is also supported. It comes with a bunch of examples.

TagPy is maintained in its git repository

Download

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I just realized that I had posted this comment under 0.91 comments by mistake, so I'm now posting it here again so people will see it.

Hi Andreas,

I just wonder what would be the best way to copy all of the tags from one file to another (possibly across different tagging standards).

It seems Tag::duplicate() from TagLib isn’t implemented in TagPy. Besides that, even duplicate() would only copy over the generic tags. What am I supposed to do if I have tags named on my own (I think these are, except in ID3V1, part of all tagging standards!?).

Perhaps there is a quick-and-dirty way like copying all string objects f.tag() possesses over to f2.tag()? How would this look in a concrete way? Will this work a safe way? Does the encoding of those strings play a role or is encoding-independence part of the abstraction?

I would appreciate some small input. I hope it is not to obvious, im just at the beginning of doing some computer stuff. Thanks!

I've just released 0.94.6 that, among a couple other updates, wraps Tag::duplicate. There's no canned functionality for tag duplication, unfortunately. If you're trying to duplicate ID3->ID3, that should be reasonably straightforward, but going across tag standards will require a bit more work.

Hope that helps at least a bit, Andreas

Hi, does tagpy support Win32? I haven't been able to get the latest version to install properly on Windows XP.

I'm having a hard time using unicode file paths to instantiate FileRef.

I have a filename that contains a 'cent' symbol, "20 ¢".

When I attempt to open this file, I get an error.

Traceback

I realize that the TabLib library is not accepting the Unicode value. Is this something that can be fixed?

An attempt to fix this problem, on my end, is to convert all unicode values to ascii. (simply wrapping the filename in str() ). However, this attempt fails, because ASCII has no character representing 'cents'.

Traceback

I hope you have a suggestion for me!

Thank you

Well, UNIX filenames are plain ASCII bytes, by definition. Conventionally, Unicode is then encoded in UTF8 and stored in these byte strings.

Unfortunately, this is only a convention, and you can't rely on it. Therefore, Taglib (and Python) would make a huge mistake by making that assumption for you. Instead, you have to UTF-8 en/decode the filename yourself. Or better yet, only touch a file name's encoding when you're rendering it to text in a user interface.

Andreas

Update: I was able to use the latin_1 encoding without brandishing an error when encoding.

However, it does not correctly encode it.. I still get this error when opening the encoded filename:

TagLib: Could not open file /Volumes/Media/Unorganized Music/Moved from C/Goldfinger/Hang-Ups/05 20? Goodbye.mp3

It seems that I am going to be having problems regardless of what encoding I use, unless I can get Unicode working.

Well it looks like I solved my own problem thanks to some IRC support.

The solution was to explicitly encode my filename path in UTF-8 f = tagpy.FileRef(file_path.encode('utf-8'))

This confuses me... if my string is already unicode, why does explicitly encoding it in utf-8 fix the problem?

Thanks :)

A UTF-8 str object is not the same as a unicode object. Python 3 will make this distinction more clear, where str is renamed bytes (or some such) and unicode becomes simply str.

Andreas

Hi, thanks for providing this wrapper! Is it true that the only tags available are: title, artist, album, genre, year, and track, or am I missing something? For example, composer would be another very useful thing to have access to for me.

You can get all these tags, too. Only problem: You need to use the file-format-specific APIs in that case, because there's no portable way.

Download links does not seem to work now, can you please fix them?

Points to PyPI now, this should (in theory) never break ever again. Sorry for the fuss.