Generic API useless with Unicode for ID3v2?

Scott Wheeler wheeler at kde.org
Thu Oct 18 16:41:19 CEST 2007


Andreas Klöckner wrote:
> On Donnerstag 18 Oktober 2007, Scott Wheeler wrote:
>   
>> [...] The encoding is set right after the frame parsed (in 
>> ID3v2FrameFactory). [...]
>
> Well, then something is broken.

Your example, specifically.  :-)

As I mentioned,  this happens when the frame is parsed -- it doesn't go 
back and change all in-memory frames after they have been created.  So, 
the following example:

#include <mpegfile.h>
#include <id3v2tag.h>
#include <textidentificationframe.h>
#include <iostream>

static const char *encodings[] = { "Latin1", "UTF16", "UTF16BE", "UTF8", 
"UTF16LE" };

static void printEncodings()
{
    TagLib::MPEG::File f("test.mp3");

    TagLib::ID3v2::Tag *tag = f.ID3v2Tag(true);

    const TagLib::ID3v2::FrameList &frames = tag->frameList();

    for(TagLib::ID3v2::FrameList::ConstIterator it = frames.begin(); it 
!= frames.end(); ++it)
    {
        if((*it)->frameID().startsWith("T"))
        {
            TagLib::ID3v2::TextIdentificationFrame *textFrame =
                static_cast<TagLib::ID3v2::TextIdentificationFrame *>(*it);

            std::cout << textFrame->frameID() << " - "
                                << 
encodings[int(textFrame->textEncoding())] << std::endl;
        }
    }
}

int main()
{
    printEncodings();

    
TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding(TagLib::String::UTF16);

    printEncodings();

    return 0;
}

Produces:

TIT2 - UTF8
TPE1 - UTF8
TALB - UTF8
TDRC - UTF8
TCON - UTF8
TPOS - UTF8
TCMP - UTF8
TRCK - UTF8
TBPM - UTF8
TIT2 - UTF16
TPE1 - UTF16
TALB - UTF16
TDRC - UTF16
TCON - UTF16
TPOS - UTF16
TCMP - UTF16
TRCK - UTF16
TBPM - UTF16

-Scott


More information about the taglib-devel mailing list