diff options
Diffstat (limited to 'src/tag_ape.c')
-rw-r--r-- | src/tag_ape.c | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/tag_ape.c b/src/tag_ape.c index 7cbf32208..d18cc84ee 100644 --- a/src/tag_ape.c +++ b/src/tag_ape.c @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" #include "tag_ape.h" #include "tag.h" @@ -25,6 +26,36 @@ #include <assert.h> #include <stdio.h> +static const char *const ape_tag_names[] = { + [TAG_TITLE] = "title", + [TAG_ARTIST] = "artist", + [TAG_ALBUM] = "album", + [TAG_COMMENT] = "comment", + [TAG_GENRE] = "genre", + [TAG_TRACK] = "track", + [TAG_DATE] = "year" +}; + +static struct tag * +tag_ape_import_item(struct tag *tag, unsigned long flags, + const char *key, const char *value, size_t value_length) +{ + /* we only care about utf-8 text tags */ + if ((flags & (0x3 << 1)) != 0) + return tag; + + for (unsigned i = 0; i < G_N_ELEMENTS(ape_tag_names); i++) { + if (ape_tag_names[i] != NULL && + g_ascii_strcasecmp(key, ape_tag_names[i]) == 0) { + if (tag == NULL) + tag = tag_new(); + tag_add_item_n(tag, i, value, value_length); + } + } + + return tag; +} + struct tag * tag_ape_load(const char *file) { @@ -36,7 +67,6 @@ tag_ape_load(const char *file) size_t tagLen; size_t size; unsigned long flags; - int i; char *key; struct { @@ -48,26 +78,6 @@ tag_ape_load(const char *file) unsigned char reserved[8]; } footer; - const char *apeItems[7] = { - "title", - "artist", - "album", - "comment", - "genre", - "track", - "year" - }; - - int tagItems[7] = { - TAG_ITEM_TITLE, - TAG_ITEM_ARTIST, - TAG_ITEM_ALBUM, - TAG_ITEM_COMMENT, - TAG_ITEM_GENRE, - TAG_ITEM_TRACK, - TAG_ITEM_DATE, - }; - fp = fopen(file, "r"); if (!fp) return NULL; @@ -127,17 +137,8 @@ tag_ape_load(const char *file) if (tagLen < size) goto fail; - /* we only care about utf-8 text tags */ - if (!(flags & (0x3 << 1))) { - for (i = 0; i < 7; i++) { - if (g_ascii_strcasecmp(key, apeItems[i]) == 0) { - if (!ret) - ret = tag_new(); - tag_add_item_n(ret, tagItems[i], - p, size); - } - } - } + ret = tag_ape_import_item(ret, flags, key, p, size); + p += size; tagLen -= size; } |