[tracker/cleanup-media-art] libtracker-miner: The get_path API doesn't require stripped input, fixed the query



commit 73a8f87c95f70480408302553f2c136bfc74d8c1
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed May 18 14:06:47 2011 +0200

    libtracker-miner: The get_path API doesn't require stripped input, fixed the query

 src/libtracker-miner/tracker-albumart.c |   36 ++++++++++++++++--------------
 1 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-albumart.c b/src/libtracker-miner/tracker-albumart.c
index 08c4e7b..5711160 100644
--- a/src/libtracker-miner/tracker-albumart.c
+++ b/src/libtracker-miner/tracker-albumart.c
@@ -71,26 +71,22 @@ on_query_finished (GObject      *source_object,
 	table = g_hash_table_new_full (g_str_hash,
 	                               g_str_equal,
 	                               (GDestroyNotify) g_free,
-	                               (GDestroyNotify) g_free);
+	                               (GDestroyNotify) NULL);
 
 	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
-		gchar *artist_stripped = NULL;
-		gchar *album_stripped;
 		gchar *target = NULL;
+		const gchar *album, *artist;
 
-		if (tracker_sparql_cursor_get_value_type (cursor, 1) != TRACKER_SPARQL_VALUE_TYPE_UNBOUND) {
-			artist_stripped = tracker_albumart_strip_invalid_entities (tracker_sparql_cursor_get_string (cursor, 1, NULL));
-		}
-
-		album_stripped = tracker_albumart_strip_invalid_entities (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+		album = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+		artist = tracker_sparql_cursor_get_value_type (cursor, 1) != TRACKER_SPARQL_VALUE_TYPE_UNBOUND ? tracker_sparql_cursor_get_string (cursor, 1, NULL) : NULL;
 
-		tracker_albumart_get_path (artist_stripped,
-		                           album_stripped,
+		/* The get_path API does stripping itself */
+		tracker_albumart_get_path (artist,
+		                           album,
 		                           "album", NULL,
 		                           &target, NULL);
 
-		g_hash_table_replace (table, target, album_stripped);
-		g_free (artist_stripped);
+		g_hash_table_replace (table, target, target);
 	}
 
 	/* Perhaps we should have an internal list of albumart files that we made,
@@ -99,14 +95,19 @@ on_query_finished (GObject      *source_object,
 
 	for (name = g_dir_read_name (dir); name != NULL; name = g_dir_read_name (dir)) {
 		gpointer value;
+		gchar *full;
 
-		value = g_hash_table_lookup (table, name);
+		full = g_build_filename (dirname, name, NULL);
+
+		value = g_hash_table_lookup (table, full);
 
 		if (!value) {
 			g_message ("Removing media-art file %s: no album exists that has "
 			           "more than one song for this media-art cache", name);
-			to_remove = g_list_prepend (to_remove, (gpointer) name);
+			to_remove = g_list_prepend (to_remove, (gpointer) full);
 		}
+
+		g_free (full);
 	}
 
 	g_list_foreach (to_remove, (GFunc) g_unlink, NULL);
@@ -168,9 +169,10 @@ on_timer_callback (gpointer data)
 	TrackerSparqlConnection *connection = data;
 
 	tracker_sparql_connection_query_async (connection,
-	                                       "SELECT ?title nmm:artistName (nmm:albumArtist (?album)) WHERE { "
-	                                       "   ?mpiece nmm:musicAlbum ?album . "
-	                                       "   ?album nmm:albumTitle ?title "
+	                                       "SELECT ?title nmm:artistName (?artist) WHERE { "
+	                                       "  ?mpiece nmm:musicAlbum ?album . "
+	                                       "  ?album nmm:albumTitle ?title . "
+	                                       "  OPTIONAL { ?album nmm:albumArtist ?artist } "
 	                                       "}",
 	                                       NULL,
 	                                       on_query_finished,



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