summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmediaart/extract.c53
-rw-r--r--libmediaart/extractgeneric.h16
-rw-r--r--libmediaart/extractpixbuf.c75
-rw-r--r--libmediaart/extractqt.cpp23
4 files changed, 94 insertions, 73 deletions
diff --git a/libmediaart/extract.c b/libmediaart/extract.c
index bd60c98..690bca7 100644
--- a/libmediaart/extract.c
+++ b/libmediaart/extract.c
@@ -375,10 +375,11 @@ end:
}
static gboolean
-convert_from_other_format (const gchar *found,
- const gchar *target,
- const gchar *album_path,
- const gchar *artist)
+convert_from_other_format (const gchar *found,
+ const gchar *target,
+ const gchar *album_path,
+ const gchar *artist,
+ GError **error)
{
gboolean retval;
gchar *sum1 = NULL;
@@ -386,7 +387,7 @@ convert_from_other_format (const gchar *found,
target_temp = g_strdup_printf ("%s-tmp", target);
- if (!media_art_file_to_jpeg (found, target_temp)) {
+ if (!media_art_file_to_jpeg (found, target_temp, error)) {
g_free (target_temp);
return FALSE;
}
@@ -650,11 +651,12 @@ media_art_find_by_artist_and_title (const gchar *uri,
}
static gboolean
-get_heuristic (MediaArtType type,
- const gchar *filename_uri,
- const gchar *local_uri,
- const gchar *artist,
- const gchar *title)
+get_heuristic (MediaArtType type,
+ const gchar *filename_uri,
+ const gchar *local_uri,
+ const gchar *artist,
+ const gchar *title,
+ GError **error)
{
gchar *art_file_path = NULL;
gchar *album_art_file_path = NULL;
@@ -856,7 +858,8 @@ get_heuristic (MediaArtType type,
retval = convert_from_other_format (art_file_path,
target,
album_art_file_path,
- artist);
+ artist,
+ error);
}
g_free (sum1);
@@ -878,7 +881,8 @@ get_heuristic (MediaArtType type,
retval = convert_from_other_format (art_file_path,
target,
album_art_file_path,
- artist);
+ artist,
+ error);
}
g_free (art_file_path);
@@ -918,12 +922,13 @@ is_buffer_jpeg (const gchar *mime,
}
static gboolean
-media_art_set (const unsigned char *buffer,
- size_t len,
- const gchar *mime,
- MediaArtType type,
- const gchar *artist,
- const gchar *title)
+media_art_set (const unsigned char *buffer,
+ size_t len,
+ const gchar *mime,
+ MediaArtType type,
+ const gchar *artist,
+ const gchar *title,
+ GError **error)
{
gchar *local_path;
gchar *album_path;
@@ -974,7 +979,7 @@ media_art_set (const unsigned char *buffer,
* i) save buffer to jpeg only.
*/
if (type != MEDIA_ART_ALBUM || (artist == NULL || g_strcmp0 (artist, " ") == 0)) {
- retval = media_art_buffer_to_jpeg (buffer, len, mime, local_path);
+ retval = media_art_buffer_to_jpeg (buffer, len, mime, local_path, error);
g_debug ("Saving buffer to jpeg (%ld bytes) --> '%s'", len, local_path);
g_free (local_path);
@@ -995,7 +1000,7 @@ media_art_set (const unsigned char *buffer,
if (!g_file_test (album_path, G_FILE_TEST_EXISTS)) {
retval = TRUE;
- if (media_art_buffer_to_jpeg (buffer, len, mime, album_path)) {
+ if (media_art_buffer_to_jpeg (buffer, len, mime, album_path, error)) {
g_debug ("Saving buffer to jpeg (%ld bytes) --> '%s'", len, album_path);
/* If album-space-md5.jpg doesn't
@@ -1054,7 +1059,7 @@ media_art_set (const unsigned char *buffer,
/* If album-space-md5.jpg isn't the same as
* buffer, make a new album-md5-md5.jpg
*/
- retval = media_art_buffer_to_jpeg (buffer, len, mime, local_path);
+ retval = media_art_buffer_to_jpeg (buffer, len, mime, local_path, error);
g_debug ("Saving buffer to jpeg (%ld bytes) --> '%s'", len, local_path);
}
@@ -1075,7 +1080,7 @@ media_art_set (const unsigned char *buffer,
temp = g_strdup_printf ("%s-tmp", album_path);
/* If buffer isn't a JPEG */
- if (!media_art_buffer_to_jpeg (buffer, len, mime, temp)) {
+ if (!media_art_buffer_to_jpeg (buffer, len, mime, temp, error)) {
/* Can't read temp file ... */
g_unlink (temp);
@@ -1511,7 +1516,7 @@ media_art_process_file (MediaArtProcess *process,
no_cache_or_old = cache_mtime == 0 || mtime > cache_mtime;
if ((buffer && len > 0) && no_cache_or_old) {
- processed = media_art_set (buffer, len, mime, type, artist, title);
+ processed = media_art_set (buffer, len, mime, type, artist, title, error);
set_mtime (cache_art_path, mtime);
created = TRUE;
}
@@ -1527,7 +1532,7 @@ media_art_process_file (MediaArtProcess *process,
local_art_uri = g_file_get_uri (local_art_file);
- if (!get_heuristic (type, uri, local_art_uri, artist, title)) {
+ if (!get_heuristic (type, uri, local_art_uri, artist, title, error)) {
/* If the heuristic failed, we
* request the download the
* media-art to the media-art
diff --git a/libmediaart/extractgeneric.h b/libmediaart/extractgeneric.h
index b48d2be..7f0584e 100644
--- a/libmediaart/extractgeneric.h
+++ b/libmediaart/extractgeneric.h
@@ -32,15 +32,17 @@
G_BEGIN_DECLS
-void media_art_plugin_init (gint max_width);
+void media_art_plugin_init (gint max_width);
void media_art_plugin_shutdown (void);
-gboolean media_art_file_to_jpeg (const gchar *filename,
- const gchar *target);
-gboolean media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target);
+gboolean media_art_file_to_jpeg (const gchar *filename,
+ const gchar *target,
+ GError **error);
+gboolean media_art_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target,
+ GError **error);
G_END_DECLS
diff --git a/libmediaart/extractpixbuf.c b/libmediaart/extractpixbuf.c
index 2f823fc..3b2854b 100644
--- a/libmediaart/extractpixbuf.c
+++ b/libmediaart/extractpixbuf.c
@@ -40,28 +40,28 @@ media_art_plugin_shutdown (void)
}
gboolean
-media_art_file_to_jpeg (const gchar *filename,
- const gchar *target)
+media_art_file_to_jpeg (const gchar *filename,
+ const gchar *target,
+ GError **error)
{
GdkPixbuf *pixbuf;
- GError *error = NULL;
+ GError *local_error = NULL;
/* TODO: Add resizing support */
- pixbuf = gdk_pixbuf_new_from_file (filename, &error);
-
- if (error) {
- g_clear_error (&error);
+ pixbuf = gdk_pixbuf_new_from_file (filename, &local_error);
+ if (local_error) {
+ g_propagate_error (error, local_error);
return FALSE;
- } else {
- gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL);
- g_object_unref (pixbuf);
+ }
- if (error) {
- g_clear_error (&error);
- return FALSE;
- }
+ gdk_pixbuf_save (pixbuf, target, "jpeg", &local_error, NULL);
+ g_object_unref (pixbuf);
+
+ if (local_error) {
+ g_propagate_error (error, local_error);
+ return FALSE;
}
return TRUE;
@@ -87,11 +87,14 @@ size_prepared_cb (GdkPixbufLoader *loader,
}
gboolean
-media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target)
+media_art_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target,
+ GError **error)
{
+ GError *local_error = NULL;
+
if (max_width_in_bytes < 0) {
g_debug ("Not saving album art from buffer, disabled in config");
return TRUE;
@@ -103,11 +106,12 @@ media_art_buffer_to_jpeg (const unsigned char *buffer,
g_strcmp0 (buffer_mime, "JPG") == 0) &&
(buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
g_debug ("Saving album art using raw data as uri:'%s'", target);
- g_file_set_contents (target, (const gchar *) buffer, (gssize) len, NULL);
+ if (!g_file_set_contents (target, (const gchar *) buffer, (gssize) len, error)) {
+ return FALSE;
+ }
} else {
GdkPixbuf *pixbuf;
GdkPixbufLoader *loader;
- GError *error = NULL;
g_debug ("Saving album art using GdkPixbufLoader for uri:'%s' (max width:%d)",
target,
@@ -121,11 +125,11 @@ media_art_buffer_to_jpeg (const unsigned char *buffer,
NULL);
}
- if (!gdk_pixbuf_loader_write (loader, buffer, len, &error)) {
- g_warning ("Could not write with GdkPixbufLoader when setting album art, %s",
- error ? error->message : "no error given");
+ if (!gdk_pixbuf_loader_write (loader, buffer, len, &local_error)) {
+ g_warning ("Could not write with GdkPixbufLoader when setting media art, %s",
+ local_error ? local_error->message : "no error given");
- g_clear_error (&error);
+ g_propagate_error (error, local_error);
gdk_pixbuf_loader_close (loader, NULL);
g_object_unref (loader);
@@ -135,7 +139,9 @@ media_art_buffer_to_jpeg (const unsigned char *buffer,
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (pixbuf == NULL) {
- g_warning ("Could not get pixbuf from GdkPixbufLoader when setting album art");
+ g_warning ("Could not get pixbuf from GdkPixbufLoader when setting media art");
+
+ /* FIXME: Set error here */
gdk_pixbuf_loader_close (loader, NULL);
g_object_unref (loader);
@@ -143,21 +149,24 @@ media_art_buffer_to_jpeg (const unsigned char *buffer,
return FALSE;
}
- if (!gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL)) {
- g_warning ("Could not save GdkPixbuf when setting album art, %s",
- error ? error->message : "no error given");
+ if (!gdk_pixbuf_save (pixbuf, target, "jpeg", &local_error, NULL)) {
+ g_warning ("Could not save GdkPixbuf when setting media art, %s",
+ local_error ? local_error->message : "no error given");
- g_clear_error (&error);
+ g_propagate_error (error, local_error);
gdk_pixbuf_loader_close (loader, NULL);
g_object_unref (loader);
return FALSE;
}
- if (!gdk_pixbuf_loader_close (loader, &error)) {
- g_warning ("Could not close GdkPixbufLoader when setting album art, %s",
- error ? error->message : "no error given");
- g_clear_error (&error);
+ if (!gdk_pixbuf_loader_close (loader, &local_error)) {
+ g_warning ("Could not close GdkPixbufLoader when setting media art, %s",
+ local_error ? local_error->message : "no error given");
+
+ g_propagate_error (error, local_error);
+
+ return FALSE;
}
g_object_unref (loader);
diff --git a/libmediaart/extractqt.cpp b/libmediaart/extractqt.cpp
index d39ddd7..dda324f 100644
--- a/libmediaart/extractqt.cpp
+++ b/libmediaart/extractqt.cpp
@@ -82,8 +82,9 @@ media_art_plugin_shutdown (void)
}
gboolean
-media_art_file_to_jpeg (const gchar *filename,
- const gchar *target)
+media_art_file_to_jpeg (const gchar *filename,
+ const gchar *target,
+ GError **error)
{
if (max_width_in_bytes < 0) {
g_debug ("Not saving album art from file, disabled in config");
@@ -91,6 +92,7 @@ media_art_file_to_jpeg (const gchar *filename,
}
/* TODO: Add resizing support */
+ /* TODO: Add error reporting */
QFile file (filename);
@@ -129,10 +131,11 @@ media_art_file_to_jpeg (const gchar *filename,
}
gboolean
-media_art_buffer_to_jpeg (const unsigned char *buffer,
- size_t len,
- const gchar *buffer_mime,
- const gchar *target)
+media_art_buffer_to_jpeg (const unsigned char *buffer,
+ size_t len,
+ const gchar *buffer_mime,
+ const gchar *target,
+ GError **error)
{
if (max_width_in_bytes < 0) {
g_debug ("Not saving album art from buffer, disabled in config");
@@ -144,14 +147,16 @@ media_art_buffer_to_jpeg (const unsigned char *buffer,
(g_strcmp0 (buffer_mime, "image/jpeg") == 0 ||
g_strcmp0 (buffer_mime, "JPG") == 0) &&
(buffer && len > 2 && buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff)) {
- g_debug ("Saving album art using raw data as uri:'%s'",
- target);
- g_file_set_contents (target, (const gchar*) buffer, (gssize) len, NULL);
+ g_debug ("Saving album art using raw data as uri:'%s'", target);
+ if (!g_file_set_contents (target, (const gchar*) buffer, (gssize) len, error)) {
+ return FALSE;
+ }
} else {
QImageReader *reader = NULL;
QByteArray array;
/* TODO: Add resizing support */
+ /* TODO: Add error reporting */
array = QByteArray ((const char *) buffer, (int) len);