diff options
author | Tydus <Tydus@Tydus.org> | 2011-10-26 00:40:02 +0800 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-11-03 18:37:47 +0100 |
commit | 7abd7ecec457f388d0f876650b1d1a0ffb3cff7f (patch) | |
tree | 7e2af7dd5d479391260ea414822157db2ec540b4 /plugins/artwork | |
parent | ae1925da0c0efe560853ac48d0437c276d437e25 (diff) |
Implemented extracting album art from FLAC metadata
Diffstat (limited to 'plugins/artwork')
-rw-r--r-- | plugins/artwork/Makefile.am | 9 | ||||
-rw-r--r-- | plugins/artwork/artwork.c | 77 |
2 files changed, 84 insertions, 2 deletions
diff --git a/plugins/artwork/Makefile.am b/plugins/artwork/Makefile.am index 53cda944..74155a1c 100644 --- a/plugins/artwork/Makefile.am +++ b/plugins/artwork/Makefile.am @@ -12,6 +12,11 @@ else ARTWORK_DEPS=$(JPEG_DEPS_LIBS) $(PNG_DEPS_LIBS) endif -AM_CFLAGS = $(CFLAGS) $(ARTWORK_CFLAGS) -std=c99 -artwork_la_LIBADD = $(LDADD) $(ARTWORK_DEPS) +if HAVE_FLAC +FLAC_DEPS=$(FLAC_LIBS) +FLAC_CFLAGS=-DUSE_METAFLAC +endif + +AM_CFLAGS = $(CFLAGS) $(ARTWORK_CFLAGS) $(FLAC_CFLAGS) -std=c99 +artwork_la_LIBADD = $(LDADD) $(ARTWORK_DEPS) $(FLAC_DEPS) endif diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c index 1ed09611..62503d86 100644 --- a/plugins/artwork/artwork.c +++ b/plugins/artwork/artwork.c @@ -25,6 +25,10 @@ static uintptr_t imlib_mutex; #include <png.h> #endif +#ifdef USE_METAFLAC +#include <FLAC/metadata.h> +#endif + #define min(x,y) ((x)<(y)?(x):(y)) //#define trace(...) { fprintf(stderr, __VA_ARGS__); } @@ -958,6 +962,79 @@ fetcher_thread (void *none) deadbeef->fclose (fp); } } + +#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; + } + + } + FLAC__StreamMetadata_Picture *pic=&(meta->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); + unlink (tmp_path); + 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; + }while(0); + + if(meta!=NULL){ + trace ("release flac metadata block\n"); + FLAC__metadata_object_delete(meta); + } + } +#endif } if (!got_pic && artwork_enable_local) { |