1
0
Fork 0
forked from len0rd/rockbox

An attempt to fix the ID3V2 genre tag parsing

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3981 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2003-10-21 10:44:34 +00:00
parent 0bce9580a1
commit d9ae29a691

View file

@ -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 }
};