leosongwei / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

EasyID3 + MP3 leads parsing ID3 information twice. #44

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have noticed that EasyID3 is missing TLAN (Languages) for instance.

And now that I'd like to use EasyID3 *and* "raw" MP3 access, I've found out 
that I have to parse the ID3 tags *twice* to be able to use EasyID3 and raw 
access, why is that? E.g:

from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3

easymp3 = EasyID3(path_to_mp3_file)
rawmp3 = MP3(path_to_mp3_file) # Unneccessary second parsing, why?

languages = unicode(rawmp3.get('TLAN', ""))
tracknumber = easymp3.get('tracknumber', [""]).pop(0)
...

# Btw, above line is another problem, accessing EasyID3 without problems in 
one line is such a pain. (I have MP3 files where TRCK is missing thus 
easymp3['tracknumber'][0] won't do, it raises the KeyError in internal)

Original issue reported on code.google.com by jari.pennanen@gmail.com on 19 Dec 2009 at 9:19

GoogleCodeExporter commented 9 years ago
Btw, I've found to my particular problem a simpler solution:

    try:
        easymp3 = MP3(filepath, ID3=EasyID3)
    except HeaderNotFoundError:
        raise IDv3Exception("Header not found")

    EasyID3.RegisterTextKey("language", "TLAN")

    languages = easymp3.get('language', [""]).pop(0)

Btw, that pop is also wrong, since it removes the item. Maybe someone should do 
simpler access to MP3 objects like:

    languages = easymp3.getfirst('language', 
default_value_if_language_is_not_found_goes_here)

Original comment by jari.pennanen@gmail.com on 19 Dec 2009 at 9:39

GoogleCodeExporter commented 9 years ago
TLAN is not mapped to language because TLAN is not a freeform string.

The correct way to handle a missing key in any kind of Python map is to catch
KeyError. Mutagen is no different.

Original comment by joe.wreschnig@gmail.com on 19 Dec 2009 at 9:52