summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2003-10-21 10:44:34 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2003-10-21 10:44:34 +0000
commitd9ae29a6910b2bd89cfd748a585fb8133a159c56 (patch)
tree8522b818efa946f1228de6f2447dfb02340be71c
parent0bce9580a1ae8b14712c350825a201028c923236 (diff)
downloadrockbox-d9ae29a6910b2bd89cfd748a585fb8133a159c56.zip
rockbox-d9ae29a6910b2bd89cfd748a585fb8133a159c56.tar.gz
rockbox-d9ae29a6910b2bd89cfd748a585fb8133a159c56.tar.bz2
rockbox-d9ae29a6910b2bd89cfd748a585fb8133a159c56.tar.xz
An attempt to fix the ID3V2 genre tag parsing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3981 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/id3.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/firmware/id3.c b/firmware/id3.c
index dd3fb1a..d059841 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
+#include <ctype.h>
#include "file.h"
#include "debug.h"
#include "atoi.h"
@@ -121,11 +122,11 @@ static int parseyearnum( struct mp3entry* entry, char* tag, int bufferpos )
return bufferpos;
}
-/* parse numeric genre from string */
-static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos )
+/* parse numeric genre from string, version 2.2 and 2.3 */
+static int parseoldgenre( struct mp3entry* entry, char* tag, int bufferpos )
{
- if( tag[ 1 ] == '(' && tag[ 2 ] != '(' ) {
- entry->genre = atoi( tag + 2 );
+ if( tag[0] == '(' && tag[1] != '(' ) {
+ entry->genre = atoi( tag + 1 );
entry->genre_string = 0;
return tag - entry->id3v2buf;
}
@@ -135,6 +136,23 @@ static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos )
}
}
+/* parse numeric genre from string, version 2.4 and up */
+static int parsenewgenre( struct mp3entry* entry, char* tag, int bufferpos )
+{
+ /* In version 2.4 and up, there are no parentheses, and the genre frame
+ is a list of strings, either numbers or text. */
+
+ /* Is it a number? */
+ if(isdigit(tag[0])) {
+ entry->genre = atoi( tag );
+ entry->genre_string = 0;
+ return tag - entry->id3v2buf;
+ } else {
+ entry->genre = 0xFF;
+ return bufferpos;
+ }
+}
+
static struct tag_resolver taglist[] = {
{ "TPE1", 4, offsetof(struct mp3entry, artist), NULL },
{ "TP1", 3, offsetof(struct mp3entry, artist), NULL },
@@ -146,7 +164,8 @@ static struct tag_resolver taglist[] = {
{ "TRCK", 4, offsetof(struct mp3entry, track_string), &parsetracknum },
{ "TYER", 4, offsetof(struct mp3entry, year_string), &parseyearnum },
{ "TYE", 3, offsetof(struct mp3entry, year_string), &parseyearnum },
- { "TCON", 4, offsetof(struct mp3entry, genre_string), &parsegenre },
+ { "TCON", 4, offsetof(struct mp3entry, genre_string), &parsenewgenre },
+ { "TCO", 3, offsetof(struct mp3entry, genre_string), &parseoldgenre },
{ "TCOM", 4, offsetof(struct mp3entry, composer), NULL }
};