[tracker/cuesheets: 12/18] tracker-extract-gstreamer: Avoid duplicate nmm:Artist inserts



commit f99d2beec39c397c96d544d6a0cb73184f409912
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Mon Aug 22 12:41:01 2011 +0100

    tracker-extract-gstreamer: Avoid duplicate nmm:Artist inserts
    
    Maintain an internal list to avoid creating more than one INSERT per
    nmm:Artist. Once CUE reading lands, a single file may contain 15 songs
    by one artist and previously this would have resulted in 15 identical
    INSERT statements in the preupdate.

 src/tracker-extract/tracker-extract-gstreamer.c |   68 ++++++++++++----------
 1 files changed, 37 insertions(+), 31 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index c254147..64677e7 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -100,6 +100,9 @@ typedef struct {
 	ExtractMime     mime;
 	GstTagList     *tagcache;
 	gboolean        is_content_encrypted;
+
+	GSList         *artist_list;
+
 	unsigned char  *album_art_data;
 	guint           album_art_size;
 	const gchar    *album_art_mime;
@@ -158,6 +161,31 @@ static void common_extract_stream_metadata (MetadataExtractor    *extractor,
 #endif /* DECODEBIN2/DISCOVERER/GUPnP-DLNA */
 
 static void
+add_artist (MetadataExtractor     *extractor,
+            TrackerSparqlBuilder  *preupdate,
+            const gchar           *artist_name,
+            gchar                **p_artist_uri)
+{
+	g_return_if_fail (artist_name != NULL);
+
+	*p_artist_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", artist_name);
+
+	/* Check if already added to the preupdate, to avoid sending 9 identical INSERTs */
+	if (g_slist_find_custom (extractor->artist_list, artist_name, (GCompareFunc)g_ascii_strcasecmp))
+		return;
+
+	tracker_sparql_builder_insert_open (preupdate, NULL);
+	tracker_sparql_builder_subject_iri (preupdate, *p_artist_uri);
+	tracker_sparql_builder_predicate (preupdate, "a");
+	tracker_sparql_builder_object (preupdate, "nmm:Artist");
+	tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
+	tracker_sparql_builder_object_unvalidated (preupdate, artist_name);
+	tracker_sparql_builder_insert_close (preupdate);
+
+	extractor->artist_list = g_slist_prepend (extractor->artist_list, g_strdup (artist_name));
+}
+
+static void
 add_string_gst_tag (TrackerSparqlBuilder *metadata,
                     const gchar          *key,
                     GstTagList           *tag_list,
@@ -460,40 +488,14 @@ extract_metadata (MetadataExtractor      *extractor,
 
 			performer = tracker_coalesce_strip (2, performer_temp, artist_temp);
 
-			if (performer != NULL) {
-				performer_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", performer);
+			if (performer != NULL)
+				add_artist (extractor, preupdate, performer, &performer_uri);
 
-				tracker_sparql_builder_insert_open (preupdate, NULL);
-				tracker_sparql_builder_subject_iri (preupdate, performer_uri);
-				tracker_sparql_builder_predicate (preupdate, "a");
-				tracker_sparql_builder_object (preupdate, "nmm:Artist");
-				tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
-				tracker_sparql_builder_object_unvalidated (preupdate, performer);
-				tracker_sparql_builder_insert_close (preupdate);
-			}
-
-			if (composer != NULL) {
-				composer_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", composer);
-
-				tracker_sparql_builder_insert_open (preupdate, NULL);
-				tracker_sparql_builder_subject_iri (preupdate, composer_uri);
-				tracker_sparql_builder_predicate (preupdate, "a");
-				tracker_sparql_builder_object (preupdate, "nmm:Artist");
-				tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
-				tracker_sparql_builder_object_unvalidated (preupdate, composer);
-				tracker_sparql_builder_insert_close (preupdate);
-			}
+			if (composer != NULL)
+				add_artist (extractor, preupdate, composer, &composer_uri);
 
 			if (album_artist_local != NULL) {
-				album_artist_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", album_artist_local);
-
-				tracker_sparql_builder_insert_open (preupdate, NULL);
-				tracker_sparql_builder_subject_iri (preupdate, album_artist_uri);
-				tracker_sparql_builder_predicate (preupdate, "a");
-				tracker_sparql_builder_object (preupdate, "nmm:Artist");
-				tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
-				tracker_sparql_builder_object_unvalidated (preupdate, album_artist_local);
-				tracker_sparql_builder_insert_close (preupdate);
+				add_artist (extractor, preupdate, album_artist_local, &album_artist_uri);
 
 				*album_artist = g_strdup (album_artist_local);
 			} else if (performer != NULL) {
@@ -1519,6 +1521,7 @@ tracker_extract_gstreamer (const gchar          *uri,
 	extractor = g_slice_new0 (MetadataExtractor);
 	extractor->mime = type;
 	extractor->tagcache = gst_tag_list_new ();
+	extractor->artist_list = NULL;
 	extractor->album_art_data = NULL;
 	extractor->album_art_size = 0;
 	extractor->album_art_mime = NULL;
@@ -1551,6 +1554,9 @@ tracker_extract_gstreamer (const gchar          *uri,
 
 	gst_tag_list_free (extractor->tagcache);
 
+	g_slist_foreach (extractor->artist_list, (GFunc)g_free, NULL);
+	g_slist_free (extractor->artist_list);
+
 #if defined(GSTREAMER_BACKEND_TAGREADBIN)
 	tagreadbin_shutdown (extractor);
 #elif defined(GSTREAMER_BACKEND_DECODEBIN2)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]