[tracker: 3/12] tracker-extract: Avoid albumart duplicates for cover.png



commit 6a72d22b8899523586b69b1f67a9f739049a8a08
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Aug 17 18:05:50 2011 +0200

    tracker-extract: Avoid albumart duplicates for cover.png

 src/tracker-extract/tracker-albumart.c |   62 +++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-extract/tracker-albumart.c b/src/tracker-extract/tracker-albumart.c
index 26ad77b..1a9fd88 100644
--- a/src/tracker-extract/tracker-albumart.c
+++ b/src/tracker-extract/tracker-albumart.c
@@ -92,7 +92,67 @@ convert_from_other_format (const gchar *found,
                            const gchar *target,
                            const gchar *album_path)
 {
-	return FALSE;
+	gboolean retval;
+	gchar *buffer;
+	gsize len;
+	gchar *target_temp;
+
+	target_temp = g_strdup_printf ("%s-tmp", target);
+
+	retval = tracker_albumart_file_to_jpeg (found, target_temp);
+
+	if (retval && g_file_get_contents (target_temp, &buffer, &len, NULL)) {
+		gchar *contents = NULL;
+		gsize len2 = 0;
+
+		if (g_file_get_contents (album_path, &contents, &len2, NULL)) {
+			gchar *sum1, *sum2;
+								
+			sum1 = checksum_for_data (G_CHECKSUM_MD5, buffer, len);
+			sum2 = checksum_for_data (G_CHECKSUM_MD5, contents, len2);
+
+			if (g_strcmp0 (sum1, sum2) == 0) {
+				/* If album-space-md5.jpg is the same as found,
+			 	 * make a symlink */
+							
+				if (symlink (album_path, target) != 0) {
+					perror ("symlink() error");
+					retval = FALSE;
+				} else {
+					retval = TRUE;
+				}
+			} else {
+				/* If album-space-md5.jpg isn't the same as found,
+			 	 * make a new album-md5-md5.jpg (found -> target) */
+										
+				g_rename (target_temp, album_path);
+			}
+
+			g_free (contents);
+		} else {
+			/* If there's not yet a album-space-md5.jpg, make one,
+		 	 * and symlink album-md5-md5.jpg to it */
+									
+			g_rename (target_temp, album_path);
+						
+			if (symlink (album_path, target) != 0) {
+				perror ("symlink() error");
+				retval = FALSE;
+			} else {
+				retval = TRUE;
+			}
+
+		}
+
+		g_free (buffer);
+	} else if (retval) {
+		/* Can't read the file that it was converted to, strange ... */
+		g_unlink (target_temp);
+	}
+
+	g_free (target_temp);
+
+	return retval;
 }
 
 static gboolean



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