From d9ae29a6910b2bd89cfd748a585fb8133a159c56 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Tue, 21 Oct 2003 10:44:34 +0000 Subject: An attempt to fix the ID3V2 genre tag parsing git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3981 a1c6a512-1295-4272-9138-f99709370657 --- firmware/id3.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/firmware/id3.c b/firmware/id3.c index dd3fb1ab8a..d059841991 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -33,6 +33,7 @@ #include #include #include +#include #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 } }; -- cgit v1.2.3