tracker r2376 - in trunk: . src/tracker-extract



Author: pvanhoof
Date: Wed Oct 15 13:56:53 2008
New Revision: 2376
URL: http://svn.gnome.org/viewvc/tracker?rev=2376&view=rev

Log:
2008-10-15  Philip Van Hoof  <philip codeminded be>

	* src/tracker-extract/tracker-extract-mp3.c
	* src/tracker-extract/tracker-albumart.c
	* src/tracker-extract/tracker-albumart.h
	* src/tracker-extract/Makefile.am
	* src/tracker-extract/tracker-extract-gstreamer.c: Handling of albumart



Modified:
   trunk/ChangeLog
   trunk/src/tracker-extract/Makefile.am
   trunk/src/tracker-extract/tracker-albumart.c
   trunk/src/tracker-extract/tracker-albumart.h
   trunk/src/tracker-extract/tracker-extract-gstreamer.c
   trunk/src/tracker-extract/tracker-extract-mp3.c

Modified: trunk/src/tracker-extract/Makefile.am
==============================================================================
--- trunk/src/tracker-extract/Makefile.am	(original)
+++ trunk/src/tracker-extract/Makefile.am	Wed Oct 15 13:56:53 2008
@@ -20,6 +20,7 @@
 	$(XINE_CFLAGS) 							\
 	$(GDKPIXBUF_CFLAGS)						\
 	$(GMODULE_CFLAGS) 						\
+	$(DBUS_CFLAGS)							\
 	$(GLIB2_CFLAGS)
 
 modules_LTLIBRARIES = 							\
@@ -73,15 +74,17 @@
 
 # Common AlbumArt sources
 albumart_sources =
-albumart_libs =
+albumart_libs = 
+albumart_flags = 
 
 if HAVE_GDKPIXBUF
 albumart_sources +=							\
 	tracker-albumart.c						\
 	tracker-albumart.h
 
+albumart_flags += $(DBUS_CFLAGS)
 albumart_libs += 							\
-	$(GDKPIXBUF_LIBS)
+	$(GDKPIXBUF_LIBS) $(DBUS_LIBS)
 endif
 
 # ABW
@@ -101,7 +104,7 @@
 
 # MP3
 libextract_mp3_la_SOURCES = tracker-extract-mp3.c $(albumart_sources)
-libextract_mp3_la_LDFLAGS = $(module_flags)
+libextract_mp3_la_LDFLAGS = $(module_flags) $(albumart_flags)
 libextract_mp3_la_LIBADD = $(albumart_libs) $(GLIB2_LIBS)
 
 # MPlayer
@@ -153,7 +156,7 @@
 
 # GStreamer
 libextract_gstreamer_la_SOURCES = tracker-extract-gstreamer.c $(albumart_sources)
-libextract_gstreamer_la_LDFLAGS = $(module_flags)
+libextract_gstreamer_la_LDFLAGS = $(module_flags) $(albumart_flags)
 libextract_gstreamer_la_LIBADD = $(albumart_libs) $(GSTREAMER_LIBS) $(GLIB2_LIBS)
 
 # Xine

Modified: trunk/src/tracker-extract/tracker-albumart.c
==============================================================================
--- trunk/src/tracker-extract/tracker-albumart.c	(original)
+++ trunk/src/tracker-extract/tracker-albumart.c	Wed Oct 15 13:56:53 2008
@@ -26,12 +26,66 @@
 #include <gio/gio.h>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <dbus/dbus-glib-bindings.h>
+
+#define ALBUMARTER_SERVICE      "com.nokia.albumart"
+#define ALBUMARTER_PATH         "/com/nokia/albumart/Requester"
+#define ALBUMARTER_INTERFACE    "com.nokia.albumart.Requester"
+
 
 #include "tracker-albumart.h"
 
+static gboolean 
+tracker_heuristic_albumart (const gchar *artist,  const gchar *album, const gchar *filename)
+{
+	// TODO: implement and return TRUE if something was found and copied 
+	return FALSE;
+}
+
+
+
+static DBusGProxy*
+tracker_dbus_get_albumart_requester (void)
+{
+	static DBusGProxy *albart_proxy = NULL;
+
+	if (!albart_proxy) {
+		GError          *error = NULL;
+		DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+		if (!error) {
+			albart_proxy = dbus_g_proxy_new_for_name (connection,
+								  ALBUMARTER_SERVICE,
+								  ALBUMARTER_PATH,
+								  ALBUMARTER_INTERFACE);
+		} else
+			g_error_free (error);
+	}
+
+	return albart_proxy;
+}
 
 static void
-get_albumart_path (const gchar *a, const gchar *b, const gchar *prefix, gchar **path)
+get_file_albumart_queue_cb (DBusGProxy     *proxy,
+			    DBusGProxyCall *call,
+			    gpointer	     user_data)
+{
+	GError *error = NULL;
+	guint	handle;
+
+	/* FIXME: What is the point of this? */
+	dbus_g_proxy_end_call (proxy, call, &error,
+			       G_TYPE_UINT, &handle,
+			       G_TYPE_INVALID);
+
+	if (error) {
+		g_warning (error->message);
+		g_error_free (error);
+	}
+}
+
+static void
+tracker_get_albumart_path (const gchar *a, const gchar *b, const gchar *prefix, gchar **path)
 {
 	gchar *art_filename, *str;
 	gchar *dir = NULL;
@@ -75,7 +129,7 @@
 	g_free (dir);
 }
 
-gboolean
+static gboolean
 tracker_save_albumart (const unsigned char *buffer,
 		       size_t               len,
 		       const gchar         *artist, 
@@ -94,7 +148,7 @@
 		return FALSE;
 	}
 
-	get_albumart_path (artist, album, "album", &filename);
+	tracker_get_albumart_path (artist, album, "album", &filename);
 
 	loader = gdk_pixbuf_loader_new ();
 
@@ -131,3 +185,41 @@
 
 	return TRUE;
 }
+
+
+gboolean
+tracker_process_albumart (const unsigned char *buffer,
+                          size_t               len,
+                          const gchar         *artist,
+                          const gchar         *album,
+                          const gchar         *filename)
+{
+	gchar *art_path;
+	gboolean retval = TRUE;
+
+	tracker_get_albumart_path (artist, album, "album", &art_path);
+
+	if (!g_file_test (art_path, G_FILE_TEST_EXISTS)) {
+
+		if (buffer && len) {
+			retval = tracker_save_albumart (buffer, len,
+						       artist,
+						       album,
+						       filename);
+
+		} else if (!tracker_heuristic_albumart (artist, album, filename)) {
+
+			dbus_g_proxy_begin_call (tracker_dbus_get_albumart_requester (),
+				 "Queue",
+				 get_file_albumart_queue_cb,
+				 NULL, NULL,
+				 G_TYPE_STRING, artist,
+				 G_TYPE_STRING, album,
+				 G_TYPE_STRING, "album",
+				 G_TYPE_UINT, 0,
+				 G_TYPE_INVALID);
+		}
+	}
+
+	return retval;
+}

Modified: trunk/src/tracker-extract/tracker-albumart.h
==============================================================================
--- trunk/src/tracker-extract/tracker-albumart.h	(original)
+++ trunk/src/tracker-extract/tracker-albumart.h	Wed Oct 15 13:56:53 2008
@@ -24,7 +24,7 @@
 
 G_BEGIN_DECLS
 
-gboolean tracker_save_albumart (const unsigned char *buffer,
+gboolean tracker_process_albumart (const unsigned char *buffer,
                                 size_t               len,
                                 const gchar         *artist,
                                 const gchar         *album,

Modified: trunk/src/tracker-extract/tracker-extract-gstreamer.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-gstreamer.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-gstreamer.c	Wed Oct 15 13:56:53 2008
@@ -859,7 +859,7 @@
 	/* Save embedded art */
 	if (extractor->album_art_data && extractor->album_art_size) {
 #ifdef HAVE_GDKPIXBUF
-		tracker_save_albumart (extractor->album_art_data, extractor->album_art_size,
+		tracker_process_albumart (extractor->album_art_data, extractor->album_art_size,
 				       g_hash_table_lookup (metadata, "Audio:Artist") ,
 				       g_hash_table_lookup (metadata, "Audio:Album"),
 				       uri);

Modified: trunk/src/tracker-extract/tracker-extract-mp3.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-mp3.c	(original)
+++ trunk/src/tracker-extract/tracker-extract-mp3.c	Wed Oct 15 13:56:53 2008
@@ -1071,6 +1071,7 @@
 	}
 }
 
+
 static void
 extract_mp3 (const gchar *filename,
 	     GHashTable  *metadata)
@@ -1176,16 +1177,15 @@
 	/* Get mp3 stream info */
 	mp3_parse (buffer, size, metadata);
 
-	/* Save embedded album art */
 #ifdef HAVE_GDKPIXBUF
-	if (albumart.data && albumart.size) {
-		tracker_save_albumart (albumart.data, albumart.size,
-				       g_hash_table_lookup (metadata, "Audio:Artist") ,
-				       g_hash_table_lookup (metadata, "Audio:Album"),
-				       filename);
-	}
+
+	tracker_process_albumart (albumart.data, albumart.size,
+				  g_hash_table_lookup (metadata, "Audio:Artist"),
+				  g_hash_table_lookup (metadata, "Audio:Album"),
+				  filename);
+
 #endif /* HAVE_GDKPIXBUF */
-	
+
 	/* Check that we have the minimum data. FIXME We should not need to do this */
 	if (!g_hash_table_lookup (metadata, "Audio:Title")) {
 		g_hash_table_insert (metadata,



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