diff options
author | waker <wakeroid@gmail.com> | 2011-11-03 18:58:50 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-11-03 18:58:50 +0100 |
commit | d565d295038bc65e06d4be871183dae9fcf3f823 (patch) | |
tree | 561adcd27a1feda2d10048074bdd732bf4696366 /plugins/artwork | |
parent | 095c21789c8210f5e51452b83b8e4b3caa6989dd (diff) | |
parent | 9e4a5021eb7bd880b90fde42b6b19bbeda7ffd01 (diff) |
Merge branch 'master' into devel
Conflicts:
configure.ac
scripts/quickinstall.sh
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 458737fb..19bc0ede 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__); } @@ -964,6 +968,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) { |