diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-11-09 22:07:01 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-11-09 22:07:01 +0000 |
commit | 598db0d296a8c16e181b488040a324f9ae20cc33 (patch) | |
tree | f42184b12895cd9fad298f0db6808fa262c1e5c9 /src/inputPlugins/flac_plugin.c | |
parent | 4abf1b7d56425be009c8d6826a753b8682bc7c22 (diff) | |
download | mpd-598db0d296a8c16e181b488040a324f9ae20cc33.tar.gz mpd-598db0d296a8c16e181b488040a324f9ae20cc33.tar.xz mpd-598db0d296a8c16e181b488040a324f9ae20cc33.zip |
work in progress
git-svn-id: https://svn.musicpd.org/mpd/branches/r2562-metadata-handling-rewrite@2566 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/inputPlugins/flac_plugin.c')
-rw-r--r-- | src/inputPlugins/flac_plugin.c | 122 |
1 files changed, 66 insertions, 56 deletions
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index d038f1418..bc706ff64 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -450,12 +450,73 @@ FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__SeekableStreamDecoder *dec, return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } +static int commentMatchesAddToTag( + char * str, + FLAC__StreamMetadata_VorbisComment_Entry * entry, + int itemType, + MpdTag ** tag) +{ + int slen = strlen(str); + int vlen = entry->length - slen; + + if( vlen <= 0 ) return 0; + + if( 0 == strncasecmp(str, entry->entry, slen) ) { + if(*tag == NULL) *tag = newMpdTag(); + addItemToMpdTagWithLen(*tag, itemType, + entry->entry+slen, vlen); + return 1; + } + + return 0; +} + + +static MpdTag * copyVorbisCommentBlockToMpdTag(FLAC__StreamMetadata * block, + MpdTag * tag) +{ + int i; + + for(i = 0; i < block->data.vorbis_comment.num_comments; i++) { + if(commentMatchesAddToTag( + "artist=", + block->data.vorbis_comment.comments+i, + TAG_ITEM_ARTIST, + &tag)); + else if(commentMatchesAddToTag( + "title=", + block->data.vorbis_comment.comments+i, + TAG_ITEM_TITLE, + &tag)); + else if(commentMatchesAddToTag( + "album=", + block->data.vorbis_comment.comments+i, + TAG_ITEM_ALBUM, + &tag)); + else if(commentMatchesAddToTag( + "tracknumber=", + block->data.vorbis_comment.comments+i, + TAG_ITEM_TRACK, + &tag)); + else if(commentMatchesAddToTag( + "genre=", + block->data.vorbis_comment.comments+i, + TAG_ITEM_GENRE, + &tag)); + else if(commentMatchesAddToTag( + "date=", + block->data.vorbis_comment.comments+i, + TAG_ITEM_DATE, + &tag)); + } + + return tag; +} + MpdTag * flacMetadataDup(char * file, int * vorbisCommentFound) { MpdTag * ret = NULL; FLAC__Metadata_SimpleIterator * it; FLAC__StreamMetadata * block = NULL; - int offset; - int len, pos; *vorbisCommentFound = 0; @@ -469,60 +530,9 @@ MpdTag * flacMetadataDup(char * file, int * vorbisCommentFound) { block = FLAC__metadata_simple_iterator_get_block(it); if(!block) break; if(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { - char * dup; - - offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"artist"); - if(offset>=0) { - *vorbisCommentFound = 1; - if(!ret) ret = newMpdTag(); - pos = strlen("artist="); - len = block->data.vorbis_comment.comments[offset].length-pos; - if(len>0) { - dup = malloc(len+1); - memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len); - dup[len] = '\0'; - ret->artist = dup; - } - } - offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"album"); - if(offset>=0) { - *vorbisCommentFound = 1; - if(!ret) ret = newMpdTag(); - pos = strlen("album="); - len = block->data.vorbis_comment.comments[offset].length-pos; - if(len>0) { - dup = malloc(len+1); - memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len); - dup[len] = '\0'; - ret->album = dup; - } - } - offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"title"); - if(offset>=0) { - *vorbisCommentFound = 1; - if(!ret) ret = newMpdTag(); - pos = strlen("title="); - len = block->data.vorbis_comment.comments[offset].length-pos; - if(len>0) { - dup = malloc(len+1); - memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len); - dup[len] = '\0'; - ret->title = dup; - } - } - offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"tracknumber"); - if(offset>=0) { - *vorbisCommentFound = 1; - if(!ret) ret = newMpdTag(); - pos = strlen("tracknumber="); - len = block->data.vorbis_comment.comments[offset].length-pos; - if(len>0) { - dup = malloc(len+1); - memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len); - dup[len] = '\0'; - ret->track = dup; - } - } + ret = copyVorbisCommentBlockToMpdTag(block, ret); + + if(ret) *vorbisCommentFound = 1; } else if(block->type == FLAC__METADATA_TYPE_STREAMINFO) { if(!ret) ret = newMpdTag(); |