[tracker/avoid-album-art-duplicates] tracker-extract: Avoid albumart duplicates for embedded
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/avoid-album-art-duplicates] tracker-extract: Avoid albumart duplicates for embedded
- Date: Wed, 17 Aug 2011 11:45:55 +0000 (UTC)
commit bd693287f0aa23e8dd3ce7239dd31c7f9f8a8cda
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Aug 17 13:45:25 2011 +0200
tracker-extract: Avoid albumart duplicates for embedded
src/tracker-extract/tracker-albumart.c | 65 +++++++++++++++++++++++++++++++-
1 files changed, 64 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-extract/tracker-albumart.c b/src/tracker-extract/tracker-albumart.c
index 61a148f..af20126 100644
--- a/src/tracker-extract/tracker-albumart.c
+++ b/src/tracker-extract/tracker-albumart.c
@@ -67,6 +67,26 @@ albumart_queue_cb (GObject *source_object,
gpointer user_data);
+static gchar *
+checksum_for_data (GChecksumType checksum_type,
+ const guchar *data,
+ gsize length)
+{
+ GChecksum *checksum;
+ gchar *retval;
+
+ checksum = g_checksum_new (checksum_type);
+ if (!checksum) {
+ return NULL;
+ }
+
+ g_checksum_update (checksum, data, length);
+ retval = g_strdup (g_checksum_get_string (checksum));
+ g_checksum_free (checksum);
+
+ return retval;
+}
+
static gboolean
albumart_heuristic (const gchar *artist,
const gchar *album,
@@ -319,7 +339,50 @@ albumart_set (const unsigned char *buffer,
tracker_albumart_get_path (artist, album, "album", NULL, &local_path, NULL);
- retval = tracker_albumart_buffer_to_jpeg (buffer, len, mime, local_path);
+ if (artist == NULL || g_strcmp0 (artist, " ") == 0) {
+ retval = tracker_albumart_buffer_to_jpeg (buffer, len, mime, local_path);
+ } else {
+ gchar *album_path;
+
+ tracker_albumart_get_path (" ", album, "album", NULL, &album_path, NULL);
+
+ if (!g_file_test (album_path, G_FILE_TEST_EXISTS)) {
+ retval = tracker_albumart_buffer_to_jpeg (buffer, len, mime, album_path);
+
+ if (retval && symlink(album_path, local_path) != 0) {
+ perror ("symlink() error");
+ retval = FALSE;
+ } else {
+ retval = TRUE;
+ }
+ } else {
+ 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 (symlink (album_path, local_path) != 0) {
+ perror ("symlink() error");
+ retval = FALSE;
+ } else {
+ retval = TRUE;
+ }
+ } else {
+ retval = tracker_albumart_buffer_to_jpeg (buffer, len, mime, local_path);
+ }
+
+ g_free (sum1);
+ g_free (sum2);
+ }
+
+ g_free (album_path);
+ }
+ }
g_free (local_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]