77b5ded2eab73de5d61598e4a86a4247cb695d7d Port over album art extraction from the Vorbis extractor.
diff --git a/src/tracker-extract/tracker-extract-flac.c b/src/tracker-extract/tracker-extract-flac.c
index fcdd45a..4812381 100644
--- a/src/tracker-extract/tracker-extract-flac.c
+++ b/src/tracker-extract/tracker-extract-flac.c
@@ -28,6 +28,10 @@
 
 #include <FLAC/metadata.h>
 
+#ifdef HAVE_LIBMEDIAART
+#include <libmediaart/mediaart.h>
+#endif
+
 #include <libtracker-common/tracker-common.h>
 
 #include <libtracker-extract/tracker-extract.h>
@@ -62,6 +66,9 @@
 	guint channels;
 	guint bps;
 	guint64 total;
+	unsigned char *media_art_data;
+	size_t media_art_size;
+	gchar *media_art_mime;
 } FlacData;
 
 static void
@@ -155,7 +162,7 @@
 tracker_extract_get_metadata (TrackerExtractInfo *info)
 {
 	FLAC__Metadata_SimpleIterator *iter;
-	FLAC__StreamMetadata *stream = NULL, *vorbis, *picture;
+	FLAC__StreamMetadata *stream = NULL, *vorbis;
 	FLAC__bool success;
 	FlacData fd = { 0 };
 	TrackerResource *metadata, *artist, *album_disc, *album, *album_artist;
@@ -198,9 +205,15 @@
 			break;
 
 		case FLAC__METADATA_TYPE_PICTURE:
-			picture = FLAC__metadata_simple_iterator_get_block (iter);
-			/* Deal with picture */
-			FLAC__metadata_object_delete (picture);
+			vorbis = FLAC__metadata_simple_iterator_get_block (iter);
+			FLAC__StreamMetadata_Picture picture = vorbis->data.picture;
+			if (picture.data_length > 0) {
+				fd.media_art_data = g_malloc0 (picture.data_length);
+				fd.media_art_mime = g_strdup (picture.mime_type);
+				memcpy (fd.media_art_data, picture.data, picture.data_length);
+				fd.media_art_size = picture.data_length;
+			}
+			FLAC__metadata_object_delete (vorbis);
 			break;
 
 		default:
@@ -283,6 +296,47 @@
 		tracker_resource_set_int64 (metadata, "nfo:averageBitrate", stream->data.stream_info.bits_per_sample);
 		tracker_resource_set_int64 (metadata, "nfo:duration", stream->data.stream_info.total_samples / stream->data.stream_info.sample_rate);
 	}
+#ifdef HAVE_LIBMEDIAART
+	if ((fd.albumartist || fd.artist) || fd.album) {
+		MediaArtProcess *media_art_process;
+		GError *error = NULL;
+		gboolean success = TRUE;
+
+		media_art_process = tracker_extract_info_get_media_art_process (info);
+
+		if (fd.media_art_data) {
+			g_warning("Saving album art size %d for %s %s", fd.media_art_size,
+					fd.album, fd.albumartist ? fd.albumartist : fd.artist);
+			success = media_art_process_buffer (media_art_process,
+			                                    MEDIA_ART_ALBUM,
+			                                    MEDIA_ART_PROCESS_FLAGS_NONE,
+			                                    file,
+			                                    fd.media_art_data,
+			                                    fd.media_art_size,
+			                                    fd.media_art_mime,
+												fd.albumartist ? fd.albumartist : fd.artist,
+			                                    fd.album,
+			                                    NULL,
+			                                    &error);
+		} else {
+			success = media_art_process_file (media_art_process,
+			                                  MEDIA_ART_ALBUM,
+			                                  MEDIA_ART_PROCESS_FLAGS_NONE,
+			                                  file,
+											  fd.albumartist ? fd.albumartist : fd.artist,
+			                                  fd.album,
+			                                  NULL,
+			                                  &error);
+		}
+
+		if (!success || error) {
+			g_warning ("Could not process media art for '%s', %s",
+			           uri,
+			           error ? error->message : "No error given");
+			g_clear_error (&error);
+		}
+	}
+#endif
 
 	g_free (fd.artist);
 	g_free (fd.album);
@@ -309,6 +363,8 @@
 	g_free (fd.organisation);
 	g_free (fd.location);
 	g_free (fd.publisher);
+	g_free (fd.media_art_data);
+	g_free (fd.media_art_mime);
 	g_free (uri);
 
 	return TRUE;
