[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: kdesupport/taglib/mpeg/id3v1
From:       Scott Wheeler <wheeler () kde ! org>
Date:       2004-04-04 17:55:19
Message-ID: 200404041955.26532.wheeler () kde ! org
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok, and now I'm attaching a small Qt-based program that shows how to override 
the default string encoding.  This one just uses utf8, but I think it's clear 
how one would proceed based on this...

I would also recommend by default (i.e. when ISO-8859-1 is selected) not using 
an external string handler at all since they extra lookups will likely slow 
things down...

- -Scott

On Sunday 04 April 2004 16:42, Scott Wheeler wrote:
> CVS commit by wheeler: 
> 
> Add the ability to override the default ID3v1 string handling in TagLib by
> adding a ID3v1::StringHandler class that has render and parse methods.
> 
> By default this still makes the (correct) assumption that ID3v1 tags contain
> ISO-8859-1 data, but this makes it easy for applications to override this to
> allow user specified codecs.
> 
> CCMAIL:78428@bugs.kde.org
> CCMAIL:77710@bugs.kde.org
> CCMAIL:amarok-devel@lists.sourceforge.net
> CCMAIL:Shlomi Loubaton <loubaton.shlomi@012.net.il>
> CCMAIL:Nir Misgav <misgav@ee.bgu.ac.il>
> 
> 
>   M +34 -10    id3v1tag.cpp   1.23
>   M +47 -0     id3v1tag.h   1.14
> 
> 
> 
> 

- -- 
Many people would sooner die than think; in fact, they do so. 
- --Bertrand Russell
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQFAcEwKQu0ByfY5QTkRAkJ6AKDNP3i9PIzwkm8yBYBRJV+vih9HNwCgoIvL
/497A6rVnHUkyYD51Yf3kfI=
=mLTy
-----END PGP SIGNATURE-----

["utf8.cpp" (text/x-c++src)]

// g++ `taglib-config --libs --cflags` -I${QTDIR}/include -L${QTDIR}/lib \
-Wl,-R${QTDIR}/lib -lqt-mt utf8.cpp -o utf8

#include <tstring.h>
#include <mpegfile.h>
#include <id3v1tag.h>

#include <qstring.h>
#include <qtextcodec.h>

using namespace TagLib;

class LocaleStringHandler : public ID3v1::StringHandler
{
public:
  LocaleStringHandler() : m_codec(QTextCodec::codecForName("utf8")) {}

  virtual String parse(const ByteVector &data) const
  {
    return QStringToTString(m_codec->toUnicode(data.data(), data.size()));
  }

private:
  QTextCodec *m_codec;
};

int main(int argc, char *argv[])
{
  ID3v1::Tag::setStringHandler(new LocaleStringHandler);

  for(int i = 1; i < argc; i++) {

    TagLib::MPEG::File f(argv[i], false);

    if(f.isValid() && f.ID3v1Tag(false)) {

      Tag *tag = f.ID3v1Tag(false);

      cout << "title   - \"" << tag->title()   << "\"" << endl;
      cout << "artist  - \"" << tag->artist()  << "\"" << endl;
      cout << "album   - \"" << tag->album()   << "\"" << endl;
      cout << "year    - \"" << tag->year()    << "\"" << endl;
      cout << "comment - \"" << tag->comment() << "\"" << endl;
      cout << "track   - \"" << tag->track()   << "\"" << endl;
      cout << "genre   - \"" << tag->genre()   << "\"" << endl;
    }
  }
}



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic