[PATCH] Fix repeated genre in ID3v2.3 tags

Xavier Duret xaviour.maillists at gmail.com
Tue Jan 16 20:05:06 CET 2007


Taglib converts frames like "(1)Rock" into "Rock Rock". This patch remedy that.

diff -ruN taglib/mpeg/id3v2/id3v2tag.cpp.old taglib/mpeg/id3v2/id3v2tag.cpp
--- taglib/mpeg/id3v2/id3v2tag.cpp.old  2007-01-15 18:40:18.000000000 +0100
+++ taglib/mpeg/id3v2/id3v2tag.cpp      2007-01-15 22:47:21.000000000 +0100
@@ -143,6 +143,8 @@

   String genreString;
   bool hasNumber = false;
+  bool lastFoundIsValid = false;
+  String lastFound;

   for(StringList::ConstIterator it = fields.begin(); it !=
fields.end(); ++it) {

@@ -163,13 +165,20 @@
       if(number >= 0 && number <= 255) {
         hasNumber = true;
         genreString.append(ID3v1::genre(number));
+        lastFound = String(ID3v1::genre(number));
+        lastFoundIsValid = true;
       }
     }
     else {
-      genreString.append(*it);
+      if (!lastFoundIsValid || !(lastFound == *it)) {
+        genreString.append(*it);
+        lastFound = *it;
+      }
+      lastFoundIsValid = true;
     }
   }

+  genreString = genreString.stripWhiteSpace();
   return genreString;
 }


More information about the taglib-devel mailing list