Non-UTF8 ID3 tags.
Robert Hart <[email protected]> Mon, 01 Dec 2003 18:52:20 +0000
| Newsgroups | gmane.comp.audio.zinf.devel |
|---|---|
| Message-ID | <1070304740.1951.12.camel@euclid> |
I've had a go at sorting out some of the problems with non-UTF8 friendly ID3 tags. This code simply checks to see if a tag contains valid-UTF8, and if it doesn't assume it must be in "ISO-8859-1". Obviously for the non-english speakers amongst us, they will want to assume something different. I plan to make this a preference in future, but for now you can edit the code by hand. What I don't think we will be able to do is "auto-detect" an enconding. I looked at the ruxmms, and the way it goes about it is really ugly. I am using glib to do the utf8 checking and conversion, but for the time being I just added a GTK dependency to the id3 code, which has the same effect. The problem I come across, is for this to be useful, I really need to blow away my music-catalogue and rebuild it, and that doesn't seem to be possible with the zinf in CVS. When is this mdb stuff going to work? Rob -- Robert Hart <[email protected]>
utf8.diff
(text/x-patch, 2.3 KB)
Index: plm/metadata/id3lib/Makefile.am
===================================================================
RCS file: /cvsroot/zinf/zinf/plm/metadata/id3lib/Makefile.am,v
retrieving revision 1.2
diff -a -u -r1.2 Makefile.am
--- plm/metadata/id3lib/Makefile.am 16 Sep 2003 17:35:17 -0000 1.2
+++ plm/metadata/id3lib/Makefile.am 1 Dec 2003 18:40:32 -0000
@@ -3,9 +3,9 @@
plugin_LTLIBRARIES = id3lib-mdf.la
id3lib_mdf_la_SOURCES = id3lib.cpp id3lib.h
-id3lib_mdf_la_LIBADD = $(ID3LIB_LIBS)
+id3lib_mdf_la_LIBADD = $(ID3LIB_LIBS) $(GTK_LIBS)
id3lib_mdf_la_LDFLAGS = $(plugin_ldflags)
-AM_CPPFLAGS = $(THREAD_CFLAGS) $(base_includes) $(ID3LIB_CFLAGS)
+AM_CPPFLAGS = $(THREAD_CFLAGS) $(base_includes) $(ID3LIB_CFLAGS) $(GTK_CFLAGS)
# arch-tag: 35b5aed9-5590-4112-9982-7edcb95ba33e
Index: plm/metadata/id3lib/id3lib.cpp
===================================================================
RCS file: /cvsroot/zinf/zinf/plm/metadata/id3lib/id3lib.cpp,v
retrieving revision 1.7
diff -a -u -r1.7 id3lib.cpp
--- plm/metadata/id3lib/id3lib.cpp 16 Sep 2003 17:58:14 -0000 1.7
+++ plm/metadata/id3lib/id3lib.cpp 1 Dec 2003 18:40:32 -0000
@@ -22,6 +22,7 @@
____________________________________________________________________________*/
#include <stdio.h>
+#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>
@@ -39,7 +40,7 @@
#include "id3lib.h"
#include <id3/tag.h>
-
+#include <glib.h>
#define DB printf("%s:%d\n", __FILE__, __LINE__);
@@ -304,18 +305,28 @@
bool getTag(ID3_Tag&tag, ID3_FrameID frameid, string &result)
{
static char buffer[1024];
+ gchar *utfbuffer;
ID3_Frame *frame;
ID3_Field *field;
-
frame = tag.Find(frameid);
if (frame) {
field = frame->GetField (ID3FN_TEXT);
if (field)
if (field->Get (buffer, sizeof buffer) > 0) {
- result = buffer;
- return true;
+ if (g_utf8_validate (buffer, -1 , NULL)){
+ result = buffer;
+ return true;
+ }
+ else {
+ cout << "invalid utf8 in " << tag.GetFileName() << endl;
+ utfbuffer=g_convert(buffer, sizeof buffer, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ result=utfbuffer;
+ cout << "converted to " << result << endl;
+ g_free(utfbuffer);
+ return TRUE;
+ }
}
}
return false;