From f4f70d6a0e9158b28add0260a337344d8126213d Mon Sep 17 00:00:00 2001 From: waker Date: Sun, 13 May 2012 09:20:16 +0200 Subject: fixed flac embedded covers loading --- plugins/artwork/artwork.c | 114 ++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'plugins/artwork/artwork.c') diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 2bac1826..aa941b81 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -979,72 +979,66 @@ fetcher_thread (void *none) #ifdef USE_METAFLAC // try to load embedded from flac metadata { - FLAC__StreamMetadata *meta = NULL; - do { - trace ("trying to load artwork flac metadata for %s\n", param->fname); - - if (!FLAC__metadata_get_picture ( - param->fname, // filename - &meta, // picture - FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER, // type - NULL, // mime_type - NULL, // description - (unsigned)(-1), // max_width - (unsigned)(-1), // max_height - (unsigned)(-1), // max_depth - (unsigned)(-1) // max_colors - )){ - trace ("%s don't have an embedded cover\n",param->fname); - - if (!FLAC__metadata_get_picture ( - param->fname, // filename - &meta, // picture - -1, // type - NULL, // mime_type - NULL, // description - (unsigned)(-1), // max_width - (unsigned)(-1), // max_height - (unsigned)(-1), // max_depth - (unsigned)(-1) // max_colors - )){ - trace ("%s don't have an embedded album art\n",param->fname); - break; - } + const char *filename = param->fname; + FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new(); + int is_ogg = 0; + if(strlen(filename) >= 4 && (0 == strcmp(filename+strlen(filename)-4, ".oga") || 0 == strcasecmp(filename+strlen(filename)-4, ".ogg"))) { + is_ogg = 1; + } - } - FLAC__StreamMetadata_Picture *pic = &meta->data.picture; + if(! (is_ogg? FLAC__metadata_chain_read_ogg(chain, filename) : FLAC__metadata_chain_read(chain, filename)) ) { + trace ("%s: ERROR: reading metadata", filename); + FLAC__metadata_chain_delete(chain); + break; + } + FLAC__StreamMetadata *picture = 0; + FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); + FLAC__metadata_iterator_init(iterator, chain); - trace ("found flac cover art of %d bytes (%s)\n", pic->data_length, pic->description); - char tmp_path[1024]; - char cache_path[1024]; - make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist, -1); - trace ("will write flac cover art into %s\n", cache_path); - snprintf (tmp_path, sizeof (tmp_path), "%s.part", cache_path); - FILE *out = fopen (tmp_path, "w+b"); - if (!out) { - trace ("artwork: failed to open %s for writing\n", tmp_path); - break; - } - if (fwrite (pic->data, 1, pic->data_length, out) != pic->data_length) { - trace ("artwork: failed to write flac picture into %s\n", tmp_path); - fclose (out); - unlink (tmp_path); - break; + do { + FLAC__StreamMetadata *block = FLAC__metadata_iterator_get_block(iterator); + if(block->type == FLAC__METADATA_TYPE_PICTURE) { + picture = block; } + } while(FLAC__metadata_iterator_next(iterator) && 0 == picture); + + if (!picture) { + trace ("%s doesn't have an embedded cover\n", param->fname); + break; + } + FLAC__StreamMetadata_Picture *pic = &picture->data.picture; + trace ("found flac cover art of %d bytes (%s)\n", pic->data_length, pic->description); + char tmp_path[1024]; + char cache_path[1024]; + make_cache_path (cache_path, sizeof (cache_path), param->album, param->artist, -1); + trace ("will write flac cover art into %s\n", cache_path); + snprintf (tmp_path, sizeof (tmp_path), "%s.part", cache_path); + FILE *out = fopen (tmp_path, "w+b"); + if (!out) { + trace ("artwork: failed to open %s for writing\n", tmp_path); + break; + } + if (fwrite (pic->data, 1, pic->data_length, out) != pic->data_length) { + trace ("artwork: failed to write flac picture into %s\n", tmp_path); fclose (out); - int err = rename (tmp_path, cache_path); - if (err != 0) { - trace ("Failed not move %s to %s: %s\n", tmp_path, cache_path, strerror (err)); - unlink (tmp_path); - break; - } unlink (tmp_path); - got_pic = 1; - } while (0); + break; + } + fclose (out); + int err = rename (tmp_path, cache_path); + if (err != 0) { + trace ("Failed not move %s to %s: %s\n", tmp_path, cache_path, strerror (err)); + unlink (tmp_path); + break; + } + unlink (tmp_path); + got_pic = 1; - if (meta != NULL) { - trace ("release flac metadata block\n"); - FLAC__metadata_object_delete (meta); + if (chain) { + FLAC__metadata_chain_delete(chain); + } + if (iterator) { + FLAC__metadata_iterator_delete(iterator); } } #endif -- cgit v1.2.3