metadata_common.c optimize parse_tag

Change-Id: I84ad404fdcc9698b9d08e6e9c37929f4b7bf569f
This commit is contained in:
William Wilgus 2022-03-13 01:36:52 -05:00 committed by William Wilgus
parent 22a6ae97a6
commit a9c62f2c39

View file

@ -252,6 +252,22 @@ bool skip_id3v2(int fd, struct mp3entry *id3)
return success;
}
static int get_tag_option(const char *option, const char *const oplist[])
{
int i;
int ifound = -1;
const char *op;
for (i=0; (op=oplist[i]) != NULL; i++)
{
if (strcasecmp(op, option) == 0)
{
ifound = i;
break;
}
}
return ifound;
}
/* Parse the tag (the name-value pair) and fill id3 and buffer accordingly.
* String values to keep are written to buf. Returns number of bytes written
* to buf (including end nil).
@ -262,19 +278,38 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
long len = 0;
char** p;
if ((((strcasecmp(name, "track") == 0) && (type == TAGTYPE_APE)))
|| ((strcasecmp(name, "tracknumber") == 0) && (type == TAGTYPE_VORBIS)))
enum
{
eTRACK = 0, eTRACKNUMBER, eDISCNUMBER, eDISC,
eYEAR, eDATE, eTITLE, eARTIST, eALBUM, eGENRE,
eCOMPOSER, eCOMMENT, eALBUMARTIST, eALBUM_ARTIST,
eENSEMBLE, eGROUPING, eCONTENTGROUP, eCONTENT_GROUP,
eMUSICBRAINZ1, eMUSICBRAINZ2
};
const char *tagops[] =
{ "track", "tracknumber", "discnumber", "disc",
"year","date","title", "artist", "album", "genre"
"composer","comment","albumartist","album artist",
"ensemble","grouping","contentgroup","content group",
"musicbrainz_trackid", "http://musicbrainz.org", NULL
};
int item = get_tag_option(name, tagops);
if (((item == eTRACK && (type == TAGTYPE_APE)))
|| (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS)))
{
id3->tracknum = atoi(value);
p = &(id3->track_string);
}
else if (strcasecmp(name, "discnumber") == 0 || strcasecmp(name, "disc") == 0)
else if (item == eDISCNUMBER || item == eDISC)
{
id3->discnum = atoi(value);
p = &(id3->disc_string);
}
else if (((strcasecmp(name, "year") == 0) && (type == TAGTYPE_APE))
|| ((strcasecmp(name, "date") == 0) && (type == TAGTYPE_VORBIS)))
else if ((item == eYEAR && (type == TAGTYPE_APE))
|| (item == eDATE && (type == TAGTYPE_VORBIS)))
{
/* Date's can be in any format in Vorbis. However most of them
* are in ISO8601 format so if we try and parse the first part
@ -288,56 +323,43 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
}
p = &(id3->year_string);
}
else if (strcasecmp(name, "title") == 0)
else if (item == eTITLE)
{
p = &(id3->title);
}
else if (strcasecmp(name, "artist") == 0)
else if (item == eARTIST)
{
p = &(id3->artist);
}
else if (strcasecmp(name, "album") == 0)
else if (item == eALBUM)
{
p = &(id3->album);
}
else if (strcasecmp(name, "genre") == 0)
else if (item == eGENRE)
{
p = &(id3->genre_string);
}
else if (strcasecmp(name, "composer") == 0)
else if (item == eCOMPOSER)
{
p = &(id3->composer);
}
else if (strcasecmp(name, "comment") == 0)
else if (item == eCOMMENT)
{
p = &(id3->comment);
}
else if (strcasecmp(name, "albumartist") == 0)
else if (item == eALBUMARTIST || item == eALBUM_ARTIST)
{
p = &(id3->albumartist);
}
else if (strcasecmp(name, "album artist") == 0)
else if (item == eENSEMBLE)
{
p = &(id3->albumartist);
}
else if (strcasecmp(name, "ensemble") == 0)
{
p = &(id3->albumartist);
}
else if (strcasecmp(name, "grouping") == 0)
else if (item == eGROUPING || item == eCONTENTGROUP || item == eCONTENT_GROUP)
{
p = &(id3->grouping);
}
else if (strcasecmp(name, "content group") == 0)
{
p = &(id3->grouping);
}
else if (strcasecmp(name, "contentgroup") == 0)
{
p = &(id3->grouping);
}
else if (strcasecmp(name, "musicbrainz_trackid") == 0
|| strcasecmp(name, "http://musicbrainz.org") == 0 )
else if (item == eMUSICBRAINZ1 || item == eMUSICBRAINZ2)
{
p = &(id3->mb_track_id);
}