2009-02-28 16:44:41 +01:00
|
|
|
/*
|
2010-01-01 05:55:13 +01:00
|
|
|
* Copyright (C) 2003-2010 The Music Player Daemon Project
|
2009-02-28 16:44:41 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-02-28 16:44:41 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2009-02-28 16:44:41 +01:00
|
|
|
#include "tag_ape.h"
|
|
|
|
#include "tag.h"
|
2010-05-30 22:39:09 +02:00
|
|
|
#include "tag_table.h"
|
2010-11-18 21:44:24 +01:00
|
|
|
#include "ape.h"
|
2009-02-28 16:44:41 +01:00
|
|
|
|
2010-05-30 22:39:09 +02:00
|
|
|
static const char *const ape_tag_names[TAG_NUM_OF_ITEM_TYPES] = {
|
2010-05-30 22:29:48 +02:00
|
|
|
[TAG_ALBUM_ARTIST] = "album artist",
|
|
|
|
[TAG_DATE] = "year",
|
2009-07-19 17:59:35 +02:00
|
|
|
};
|
|
|
|
|
2010-05-31 08:22:53 +02:00
|
|
|
static enum tag_type
|
|
|
|
tag_ape_name_parse(const char *name)
|
|
|
|
{
|
2010-05-31 08:24:05 +02:00
|
|
|
enum tag_type type = tag_table_lookup(ape_tag_names, name);
|
|
|
|
if (type == TAG_NUM_OF_ITEM_TYPES)
|
|
|
|
type = tag_name_parse_i(name);
|
|
|
|
|
|
|
|
return type;
|
2010-05-31 08:22:53 +02:00
|
|
|
}
|
|
|
|
|
2009-07-19 17:59:36 +02:00
|
|
|
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;
|
|
|
|
|
2010-05-31 08:22:53 +02:00
|
|
|
enum tag_type type = tag_ape_name_parse(key);
|
2010-05-30 22:39:09 +02:00
|
|
|
if (type == TAG_NUM_OF_ITEM_TYPES)
|
|
|
|
return tag;
|
|
|
|
|
|
|
|
if (tag == NULL)
|
|
|
|
tag = tag_new();
|
|
|
|
tag_add_item_n(tag, type, value, value_length);
|
2009-07-19 17:59:36 +02:00
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2010-11-18 21:44:24 +01:00
|
|
|
struct tag_ape_ctx {
|
|
|
|
struct tag *tag;
|
|
|
|
};
|
2009-02-28 16:44:41 +01:00
|
|
|
|
2010-11-18 21:44:24 +01:00
|
|
|
static bool
|
|
|
|
tag_ape_callback(unsigned long flags, const char *key,
|
|
|
|
const char *value, size_t value_length, void *_ctx)
|
|
|
|
{
|
|
|
|
struct tag_ape_ctx *ctx = _ctx;
|
2009-02-28 16:44:41 +01:00
|
|
|
|
2010-11-18 21:44:24 +01:00
|
|
|
ctx->tag = tag_ape_import_item(ctx->tag, flags, key,
|
|
|
|
value, value_length);
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-19 17:59:36 +02:00
|
|
|
|
2010-11-18 21:44:24 +01:00
|
|
|
struct tag *
|
|
|
|
tag_ape_load(const char *file)
|
|
|
|
{
|
|
|
|
struct tag_ape_ctx ctx = { .tag = NULL };
|
2009-02-28 16:44:41 +01:00
|
|
|
|
2010-11-18 21:44:24 +01:00
|
|
|
tag_ape_scan(file, tag_ape_callback, &ctx);
|
|
|
|
return ctx.tag;
|
2009-02-28 16:44:41 +01:00
|
|
|
}
|