Looking For mp3 ID Tag Module

Iain King iainking at gmail.com
Fri Aug 18 06:56:31 EDT 2006


Tim Daneliuk wrote:
> Iñigo Serna wrote:
> > On 8/18/06, Tim Daneliuk <tundra at tundraware.com> wrote:
> >> > try mutagen.
> >> http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen
> >>
> >> This module is more-or-less exactly what I needed.  However, I am running
> >> into problems when the filenames or ID tags have unicode characters in
> >> them.
> >>
> >> Typically, I do something like:
> >>
> >> from mutagen.easyid3 import EasyID3
> >>
> >> audio["title'] = Something based on the filename that has unicode
> >> chars in it
> >>
> >> I then get this:
> >>
> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position
> >> 56: ordinal not in range(128)
> >
> >> From the docs:
> > """Mutagen has full Unicode support for all formats. When you assign
> > text strings, we strongly recommend using Python unicode objects
> > rather than str objects. If you use str objects, Mutagen will assume
> > they are in UTF-8."""
> >
> > So I suppose the value you try to assign as title is not unicode,
> > check the encoding used in the file system.
> >
> > Iñigo
>
> I am trying to set the title based on the filename.  The file is in a Win32
> NTFS filesystem, so it could have non-ASCII chars in it.  What I am stumbling
> on it how to coerce it into unicode.  I have tried:
>
> name = filename.split(....) blah blah blah
> audio["title"] = unicode(name)
>
> But I still get this error.  I am not real up to speed on the whole unicode
> end of things, so any kind suggestions would be most welcome.
>
> By the way, I believe the offending string contains a German umlaut, at least in one
> of the cases.
>
>

To get the MP3's name, use os.path.basename (I'm guessing that's what
your split() is for?)
Looking at the mutagen tutorial, most of the tags are lists of unicode
strings, so you might want to try audio["title"] = [unicode(name)],
instead of audio["title"] = unicode(name).  This might be your problem
when reading the tags, too.

Iain




More information about the Python-list mailing list