[libmediaart/api-cleanup: 4/4] wip



commit 4117c0e1124c8a36e8721aaac7b0a9dad8c500e0
Author: Martyn Russell <martyn lanedo com>
Date:   Fri Feb 21 21:43:02 2014 +0000

    wip

 libmediaart/extract.c |   77 ++++++++++++++++++++++++++++++++----------------
 libmediaart/extract.h |    2 +-
 2 files changed, 52 insertions(+), 27 deletions(-)
---
diff --git a/libmediaart/extract.c b/libmediaart/extract.c
index 5bd3c36..f694df1 100644
--- a/libmediaart/extract.c
+++ b/libmediaart/extract.c
@@ -1335,14 +1335,15 @@ media_art_process_file (GFile         *file,
 {
        GFile *cache_art_file, *local_art_file;
        GError *local_error = NULL;
-       gchar *art_path, *uri;
-       gchar *local_art_uri = NULL;
-       gboolean processed = TRUE, a_exists, created = FALSE;
-       guint64 mtime, a_mtime = 0;
+       gchar *cache_art_path, *uri;
+       gboolean processed, created;
+       guint64 mtime, cache_mtime = 0;
 
        g_return_val_if_fail (G_IS_FILE (file), FALSE);
        g_return_val_if_fail (type > MEDIA_ART_NONE && type < MEDIA_ART_TYPE_COUNT, FALSE);
 
+       processed = created = FALSE;
+
        uri = g_file_get_uri (file);
        g_debug ("Processing media art: artist:'%s', title:'%s', type:'%s', uri:'%s'. Buffer is %ld bytes, 
mime:'%s'",
                 artist ? artist : "",
@@ -1354,7 +1355,7 @@ media_art_process_file (GFile         *file,
 
        mtime = get_mtime (file, &local_error);
        if (local_error != NULL) {
-               g_debug ("Could not get mtime for '%s': %s",
+               g_debug ("Could not get mtime for file '%s': %s",
                         uri,
                         local_error->message);
                g_propagate_error (error, local_error);
@@ -1370,34 +1371,50 @@ media_art_process_file (GFile         *file,
                            &cache_art_file,
                            &local_art_file);
 
-       if (!cache_art_file) {
-               g_debug ("Album art path could not be obtained, not processing any further");
+       cache_mtime = get_mtime (cache_art_file, &local_error);
+
+       if (local_error &&
+           local_error->domain == g_io_error_quark () &&
+           local_error->code == G_IO_ERROR_NOT_FOUND) {
+               /* cache_art_file not existing is the only error we
+                * accept here, anything else and we return.
+                */
+               gchar *path;
+
+               path = g_file_get_uri (cache_art_file);
+               g_debug ("Cache for media art didn't exist (%s)",
+                        path);
+               g_free (path);
+               g_clear_error (&local_error);
+       }
+
+       if (local_error) {
+               g_free (uri);
+
+               uri = g_file_get_uri (cache_art_file);
+               g_debug ("Could not get mtime for cache '%s': %s",
+                        uri,
+                        local_error->message);
+               g_free (uri);
 
                if (local_art_file) {
                        g_object_unref (local_art_file);
                }
 
-               g_free (uri);
+               g_propagate_error (error, local_error);
 
                return FALSE;
        }
 
-       a_exists = g_file_query_exists (cache_art_file, NULL);
-
-       if (a_exists) {
-               a_mtime = get_mtime (cache_art_file, &local_error);
-       }
+       cache_art_path = g_file_get_path (cache_art_file);
 
-       art_path = g_file_get_path (cache_art_file);
-       local_art_uri = g_file_get_uri (local_art_file);
-
-       if ((buffer && len > 0) && ((!a_exists) || (a_exists && mtime > a_mtime))) {
+       if ((buffer && len > 0) && (cache_mtime == 0 || mtime > cache_mtime)) {
                processed = media_art_set (buffer, len, mime, type, artist, title);
-               set_mtime (art_path, mtime);
+               set_mtime (cache_art_path, mtime);
                created = TRUE;
        }
 
-       if ((!created) && ((!a_exists) || (a_exists && mtime > a_mtime))) {
+       if (!created && (cache_mtime == 0 || mtime > cache_mtime)) {
                /* If not, we perform a heuristic on the dir */
                gchar *key;
                gchar *dirname = NULL;
@@ -1418,6 +1435,10 @@ media_art_process_file (GFile         *file,
                g_free (dirname);
 
                if (!g_hash_table_lookup (media_art_cache, key)) {
+                       gchar *local_art_uri;
+
+                       local_art_uri = g_file_get_uri (local_art_file);
+
                        if (!media_art_heuristic (artist,
                                                  title,
                                                  type,
@@ -1432,14 +1453,15 @@ media_art_process_file (GFile         *file,
                                                            artist,
                                                            title,
                                                            local_art_uri,
-                                                           art_path);
+                                                           cache_art_path);
                        }
 
-                       set_mtime (art_path, mtime);
+                       set_mtime (cache_art_path, mtime);
 
                        g_hash_table_insert (media_art_cache,
                                             key,
                                             GINT_TO_POINTER(TRUE));
+                       g_free (local_art_uri);
                } else {
                        g_free (key);
                }
@@ -1447,7 +1469,7 @@ media_art_process_file (GFile         *file,
                if (!created) {
                        g_debug ("Album art already exists for uri:'%s' as '%s'",
                                 uri,
-                                art_path);
+                                cache_art_path);
                }
        }
 
@@ -1456,7 +1478,11 @@ media_art_process_file (GFile         *file,
                 * situation might have changed
                 */
                if (g_file_query_exists (cache_art_file, NULL)) {
-                       media_art_copy_to_local (art_path, local_art_uri);
+                       gchar *local_art_uri;
+
+                       local_art_uri = g_file_get_uri (local_art_file);
+                       media_art_copy_to_local (cache_art_path, local_art_uri);
+                       g_free (local_art_uri);
                }
        }
 
@@ -1468,8 +1494,7 @@ media_art_process_file (GFile         *file,
                g_object_unref (local_art_file);
        }
 
-       g_free (art_path);
-       g_free (local_art_uri);
+       g_free (cache_art_path);
        g_free (uri);
 
        return processed;
@@ -1516,7 +1541,7 @@ media_art_process (const gchar          *uri,
                                         mime,
                                         type,
                                         artist,
-                                        title, 
+                                        title,
                                         error);
 
        g_object_unref (file);
diff --git a/libmediaart/extract.h b/libmediaart/extract.h
index c3063a0..da71fff 100644
--- a/libmediaart/extract.h
+++ b/libmediaart/extract.h
@@ -53,7 +53,7 @@ typedef enum {
  * @MEDIA_ART_ERROR_NOENT: The resource that the was passed (for example a
  * file or URI) does not exist.
  * @MEDIA_ART_ERROR_NOENT: The URI or GFile provided
- * points to a file that does not exist. 
+ * points to a file that does not exist.
  *
  * Enumeration values used in errors returned by the
  * #MediaArtError API.


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