[tracker/media-art-enhancements: 10/16] libtracker-common: Refactor tracker_media_art_get_path()



commit f30299be8266622673537b11a546bb807771957a
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Thu Oct 20 17:41:24 2011 +0100

    libtracker-common: Refactor tracker_media_art_get_path()

 src/libtracker-common/tracker-media-art.c |   77 +++++++++++++---------------
 1 files changed, 36 insertions(+), 41 deletions(-)
---
diff --git a/src/libtracker-common/tracker-media-art.c b/src/libtracker-common/tracker-media-art.c
index 8d5a0a4..184d1cc 100644
--- a/src/libtracker-common/tracker-media-art.c
+++ b/src/libtracker-common/tracker-media-art.c
@@ -203,32 +203,33 @@ media_art_checksum_for_data (GChecksumType  checksum_type,
 /**
  * tracker_media_art_get_path:
  * @artist: the artist
- * @album: the album
+ * @title: the title
  * @prefix: For example "album"
  * @uri: NULL or the uri of the file
  * @path: the location to store the local path
  * @local_uri: the location to store the local uri or NULL
  *
- * Get the path to media art for a given album or song. Newly allocated data in
+ * Get the path to media art for a given resource. Newly allocated data in
  * @path and @local_uri must be freed with g_free.
  *
  * Since: 0.10.14
  */
 void
 tracker_media_art_get_path (const gchar  *artist,
-                            const gchar  *album,
+                            const gchar  *title,
                             const gchar  *prefix,
                             const gchar  *uri,
                             gchar       **path,
                             gchar       **local_uri)
 {
 	const gchar *space_checksum = "7215ee9c7d9dc229d2921a40e899ec5f";
+	const gchar *a, *b;
 
 	gchar *art_filename;
 	gchar *dir;
-	gchar *artist_down, *album_down;
-	gchar *artist_stripped, *album_stripped;
-	gchar *artist_checksum, *album_checksum;
+	gchar *artist_down, *title_down;
+	gchar *artist_stripped , *title_stripped;
+	gchar *artist_checksum = NULL, *title_checksum = NULL;
 
 	/* http://live.gnome.org/MediaArtStorageSpec */
 
@@ -240,30 +241,26 @@ tracker_media_art_get_path (const gchar  *artist,
 		*local_uri = NULL;
 	}
 
-	if (!artist && !album) {
+	if (!artist && !title) {
 		return;
 	}
 
-	if (!artist) {
-		artist_stripped = g_strdup (" ");
-	} else {
+	if (artist) {
 		artist_stripped = tracker_media_art_strip_invalid_entities (artist);
+		artist_down = g_utf8_strdown (artist_stripped, -1);
+		artist_checksum = media_art_checksum_for_data (G_CHECKSUM_MD5,
+		                                               (const guchar *) artist_down,
+		                                               strlen (artist_down));
 	}
 
-	if (!album) {
-		album_stripped = g_strdup (" ");
-	} else {
-		album_stripped = tracker_media_art_strip_invalid_entities (album);
+	if (title) {
+		title_stripped = tracker_media_art_strip_invalid_entities (title);
+		title_down = g_utf8_strdown (title_stripped, -1);
+		title_checksum = media_art_checksum_for_data (G_CHECKSUM_MD5,
+		                                              (const guchar *) title_down,
+		                                              strlen (title_down));
 	}
 
-	artist_down = g_utf8_strdown (artist_stripped, -1);
-	album_down = g_utf8_strdown (album_stripped, -1);
-
-	/* g_print ("[%s] [%s]\n", artist_down, album_down); */
-
-	g_free (artist_stripped);
-	g_free (album_stripped);
-
 	dir = g_build_filename (g_get_user_cache_dir (),
 	                        "media-art",
 	                        NULL);
@@ -272,26 +269,26 @@ tracker_media_art_get_path (const gchar  *artist,
 		g_mkdir_with_parents (dir, 0770);
 	}
 
-	artist_checksum = media_art_checksum_for_data (G_CHECKSUM_MD5,
-	                                               (const guchar *) artist_down,
-	                                               strlen (artist_down));
-	album_checksum = media_art_checksum_for_data (G_CHECKSUM_MD5,
-	                                              (const guchar *) album_down,
-	                                              strlen (album_down));
+	if (artist) {
+		a = artist_checksum;
+		b = title ? title_checksum : space_checksum;
+	} else {
+		a = title_checksum;
+		b = space_checksum;
+	}
 
-	g_free (artist_down);
-	g_free (album_down);
+	art_filename = g_strdup_printf ("%s-%s-%s.jpeg", prefix ? prefix : "album", a, b);
 
 	if (artist) {
-		art_filename = g_strdup_printf ("%s-%s-%s.jpeg",
-		                                prefix ? prefix : "album",
-		                                artist_checksum,
-		                                album_checksum);
-	} else {
-		art_filename = g_strdup_printf ("%s-%s-%s.jpeg",
-		                                prefix ? prefix : "album",
-		                                album_checksum,
-		                                space_checksum);
+		g_free (artist_checksum);
+		g_free (artist_stripped);
+		g_free (artist_down);
+	}
+
+	if (title) {
+		g_free (title_checksum);
+		g_free (title_stripped);
+		g_free (title_down);
 	}
 
 	if (path) {
@@ -323,6 +320,4 @@ tracker_media_art_get_path (const gchar  *artist,
 
 	g_free (dir);
 	g_free (art_filename);
-	g_free (artist_checksum);
-	g_free (album_checksum);
 }



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