flac: splitted flac_copy_vorbis_comment()
Splitted flac_copy_vorbis_comment() into flac_copy_comment() and flac_copy_comment().
This commit is contained in:
@ -26,6 +26,8 @@
|
|||||||
#include <FLAC/format.h>
|
#include <FLAC/format.h>
|
||||||
#include <FLAC/metadata.h>
|
#include <FLAC/metadata.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
flac_data_init(struct flac_data *data, struct decoder * decoder,
|
flac_data_init(struct flac_data *data, struct decoder * decoder,
|
||||||
struct input_stream *input_stream)
|
struct input_stream *input_stream)
|
||||||
@ -114,60 +116,59 @@ flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tracknumber is used in VCs, MPD uses "track" ..., all the other
|
/**
|
||||||
* tag names match */
|
* Check if the comment's name equals the passed name, and if so, copy
|
||||||
static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber";
|
* the comment value into the tag.
|
||||||
static const char *VORBIS_COMMENT_DISC_KEY = "discnumber";
|
*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
flac_copy_vorbis_comment(struct tag *tag,
|
flac_copy_comment(struct tag *tag,
|
||||||
const FLAC__StreamMetadata_VorbisComment_Entry *entry,
|
const FLAC__StreamMetadata_VorbisComment_Entry *entry,
|
||||||
enum tag_type type)
|
const char *name, enum tag_type tag_type)
|
||||||
{
|
{
|
||||||
const char *str;
|
|
||||||
size_t slen;
|
|
||||||
int vlen;
|
|
||||||
const char *value;
|
const char *value;
|
||||||
size_t value_length;
|
size_t value_length;
|
||||||
|
|
||||||
switch (type) {
|
value = flac_comment_value(entry, name, &value_length);
|
||||||
case TAG_ITEM_TRACK:
|
|
||||||
str = VORBIS_COMMENT_TRACK_KEY;
|
|
||||||
break;
|
|
||||||
case TAG_ITEM_DISC:
|
|
||||||
str = VORBIS_COMMENT_DISC_KEY;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
str = mpdTagItemKeys[type];
|
|
||||||
}
|
|
||||||
slen = strlen(str);
|
|
||||||
vlen = entry->length - slen - 1;
|
|
||||||
|
|
||||||
value = flac_comment_value(entry, str, &value_length);
|
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
tag_add_item_n(tag, type, value, value_length);
|
tag_add_item_n(tag, tag_type, value, value_length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* tracknumber is used in VCs, MPD uses "track" ..., all the other
|
||||||
|
* tag names match */
|
||||||
|
static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber";
|
||||||
|
static const char *VORBIS_COMMENT_DISC_KEY = "discnumber";
|
||||||
|
|
||||||
|
static void
|
||||||
|
flac_parse_comment(struct tag *tag,
|
||||||
|
const FLAC__StreamMetadata_VorbisComment_Entry *entry)
|
||||||
|
{
|
||||||
|
assert(tag != NULL);
|
||||||
|
|
||||||
|
if (flac_copy_comment(tag, entry, VORBIS_COMMENT_TRACK_KEY,
|
||||||
|
TAG_ITEM_TRACK) ||
|
||||||
|
flac_copy_comment(tag, entry, VORBIS_COMMENT_DISC_KEY,
|
||||||
|
TAG_ITEM_DISC))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||||
|
if (flac_copy_comment(tag, entry,
|
||||||
|
mpdTagItemKeys[i], i))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
flac_vorbis_comments_to_tag(struct tag *tag,
|
flac_vorbis_comments_to_tag(struct tag *tag,
|
||||||
const FLAC__StreamMetadata *block)
|
const FLAC__StreamMetadata *block)
|
||||||
{
|
{
|
||||||
unsigned int i, j;
|
FLAC__StreamMetadata_VorbisComment_Entry *comments =
|
||||||
FLAC__StreamMetadata_VorbisComment_Entry *comments;
|
block->data.vorbis_comment.comments;
|
||||||
|
|
||||||
comments = block->data.vorbis_comment.comments;
|
for (unsigned i = block->data.vorbis_comment.num_comments; i > 0; --i)
|
||||||
|
flac_parse_comment(tag, comments++);
|
||||||
for (i = block->data.vorbis_comment.num_comments; i != 0; --i) {
|
|
||||||
for (j = TAG_NUM_OF_ITEM_TYPES; j--;) {
|
|
||||||
if (flac_copy_vorbis_comment(tag, comments, j))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
comments++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
||||||
|
Reference in New Issue
Block a user