[libmediaart/process-file-fixes: 3/3] extract: Rewrite media_art_process() to use media_art_process_file()



commit 7f31cc45e7ad46abcde3c93cb4c5ca4d7de51998
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Wed Oct 16 19:27:54 2013 +0100

    extract: Rewrite media_art_process() to use media_art_process_file()

 libmediaart/extract.c |  127 ++++++-------------------------------------------
 1 files changed, 15 insertions(+), 112 deletions(-)
---
diff --git a/libmediaart/extract.c b/libmediaart/extract.c
index abd0970..7e46875 100644
--- a/libmediaart/extract.c
+++ b/libmediaart/extract.c
@@ -1159,8 +1159,8 @@ media_art_process_file (const guchar *buffer,
                            title,
                            media_art_type_name[type],
                            file,
-                           &cache_art_file,
-                           &local_art_file);
+                           &cache_art_file,
+                           &local_art_file);
 
        if (!cache_art_file) {
                g_debug ("Album art path could not be obtained, not processing any further");
@@ -1292,119 +1292,22 @@ media_art_process (const unsigned char *buffer,
                    const gchar         *title,
                    const gchar         *uri)
 {
-       gchar *art_path;
-       gchar *local_art_uri = NULL;
-       gboolean processed = TRUE, a_exists, created = FALSE;
-       guint64 mtime, a_mtime = 0;
-
-       g_return_val_if_fail (type > MEDIA_ART_NONE && type < MEDIA_ART_TYPE_COUNT, FALSE);
-
-       g_debug ("Processing media art: artist:'%s', title:'%s', type:'%s', uri:'%s'. Buffer is %ld bytes, 
mime:'%s'",
-                artist ? artist : "",
-                title ? title : "",
-                media_art_type_name[type],
-                uri,
-                (long int) len,
-                mime);
-
-       /* TODO: We can definitely work with GFiles better here */
-
-       mtime = get_mtime_by_uri (uri);
-
-       media_art_get_path (artist,
-                           title,
-                           media_art_type_name[type],
-                           uri,
-                           &art_path,
-                           &local_art_uri);
-
-       if (!art_path) {
-               g_debug ("Album art path could not be obtained, not processing any further");
-
-               g_free (local_art_uri);
-
-               return FALSE;
-       }
-
-       a_exists = g_file_test (art_path, G_FILE_TEST_EXISTS);
-
-       if (a_exists) {
-               a_mtime = get_mtime_by_path (art_path);
-       }
-
-       if ((buffer && len > 0) && ((!a_exists) || (a_exists && mtime > a_mtime))) {
-               processed = media_art_set (buffer, len, mime, type, artist, title);
-               set_mtime (art_path, mtime);
-               created = TRUE;
-       }
-
-       if ((!created) && ((!a_exists) || (a_exists && mtime > a_mtime))) {
-               /* If not, we perform a heuristic on the dir */
-               gchar *key;
-               gchar *dirname = NULL;
-               GFile *file, *dirf;
-
-               file = g_file_new_for_uri (uri);
-               dirf = g_file_get_parent (file);
-               if (dirf) {
-                       dirname = g_file_get_path (dirf);
-                       g_object_unref (dirf);
-               }
-               g_object_unref (file);
-
-               key = g_strdup_printf ("%i-%s-%s-%s",
-                                      type,
-                                      artist ? artist : "",
-                                      title ? title : "",
-                                      dirname ? dirname : "");
-
-               g_free (dirname);
-
-               if (!g_hash_table_lookup (media_art_cache, key)) {
-                       if (!media_art_heuristic (artist,
-                                                 title,
-                                                 type,
-                                                 uri,
-                                                 local_art_uri)) {
-                               /* If the heuristic failed, we
-                                * request the download the
-                                * media-art to the media-art
-                                * downloaders
-                                */
-                               media_art_request_download (type,
-                                                           artist,
-                                                           title,
-                                                           local_art_uri,
-                                                           art_path);
-                       }
+       GFile *file;
+       gboolean result;
 
-                       set_mtime (art_path, mtime);
+       g_return_val_if_fail (uri != NULL, FALSE);
 
-                       g_hash_table_insert (media_art_cache,
-                                            key,
-                                            GINT_TO_POINTER(TRUE));
-               } else {
-                       g_free (key);
-               }
-       } else {
-               if (!created) {
-                       g_debug ("Album art already exists for uri:'%s' as '%s'",
-                                uri,
-                                art_path);
-               }
-       }
+       file = g_file_new_for_uri(uri);
 
-       if (local_art_uri && !g_file_test (local_art_uri, G_FILE_TEST_EXISTS)) {
-               /* We can't reuse art_exists here because the
-                * situation might have changed
-                */
-               if (g_file_test (art_path, G_FILE_TEST_EXISTS)) {
-                       media_art_copy_to_local (art_path, local_art_uri);
-               }
-       }
+       result = media_art_process_file(buffer,
+                                       len,
+                                       mime,
+                                       type,
+                                       artist,
+                                       title,
+                                       file);
 
-       g_free (art_path);
-       g_free (local_art_uri);
+       g_object_unref(file);
 
-       return processed;
+       return file;
 }


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