RE: Problem With File Browsing through Grilo



 "tracker-search -m" does return list of all media correctly.

Am I doing something wrong in my code?. I have attached the code once again.



-----Original Message-----
From: grilo-list-bounces gnome org [mailto:grilo-list-bounces gnome org] On Behalf Of Juan A. Suarez Romero
Sent: Wednesday, 13. June 2012 8:28 PM
To: grilo-list gnome org
Subject: Re: Problem With File Browsing through Grilo

On Wed, 2012-06-13 at 17:28 +0800, Rakesh Dhanya (RBEI/ECP2) wrote:
> 1. if I use grl-filesystem plugin, the metadata for many audio files
> is being printed as NULL. (It prints for some files and is blank for
> some others)

Each source can handle its own set of properties. Thus, some plugins can
resolve GRL_METADATA_KEY_ARTIST, but others not. And even in the case
that a plugin is able to handle it, could be that for some specific file
simply it can't get the value for the key.

Glancing the code you sent, I see that you ask grl-filesystem for a set
of keys, but then you print then without checking if the media result
really has that key or no. Thus, if it doesn't have the key, it returns
a NULL value.

I suggest to use grl_data_has_key() to check if the element has the key
before printing it (or do not print if the value is NULL).

> 2. If I use grl-tracker plugin, then there are no results (Despite
> configuring tracker to search in specific folders through
> tracker-preferences it always looks for files in /usr)

Maybe tracker is not well configured, so the plugin doesn't work
neither.

What returns "tracker-search -m" ? It should return all the media files
you have indexed.


If you need more "real-time" help, don't hesitate to join #grilo at
irc.gnome.org

        J.A.


_______________________________________________
grilo-list mailing list
grilo-list gnome org
https://mail.gnome.org/mailman/listinfo/grilo-list
#include <glib.h>
#include <string.h>
#include <grilo.h>

static void browse_cb (GrlMediaSource *source,
		guint browse_id,
		GrlMedia *media,
		guint remaining,
		gpointer user_data,
		const GError *error)
{
	if (media) {
		/* Get the metadata we are interested in */
		const gchar *title = grl_media_get_title (media);

		if (GRL_IS_MEDIA_BOX (media)) {
			guint childcount = grl_media_box_get_childcount (GRL_MEDIA_BOX (media));
			//g_print ("Got '%s' (container with %d elements) \n", title, childcount);
		} else {
			guint seconds = grl_media_get_duration (media);
			const gchar *url = grl_media_get_url (media);
			const gchar *mime = grl_media_get_mime (media);
			const gchar *thumbnail = grl_media_get_thumbnail (media);
			const gchar *author = grl_media_get_author (media);
			const gchar *date = grl_media_get_date (media);
			const gchar *artist = grl_media_audio_get_artist((GrlMediaAudio *)media);

			g_print("Found New Media \n");
			g_print("Url = %s, mime= %s, author = %s, duration = %d, date = %s, thumbnail = %s artist = %s \n", url, mime, author, seconds, date, thumbnail, artist);
		}
		g_object_unref (media);
	}

	if (remaining == 0) {
		g_print ("Browse operation finished! \n");
	}
}

static GrlMedia * media_from_id (const gchar *id)
{
	GrlMedia *media;
	media = grl_media_new ();
	grl_media_set_id (media, id);
	return media;
}

static void source_added_cb (GrlPluginRegistry *registry, gpointer user_data)
{
	GrlMetadataSource *source = GRL_METADATA_SOURCE (user_data);
	GList * keys = grl_metadata_key_list_new (GRL_METADATA_KEY_TITLE,
			GRL_METADATA_KEY_DURATION,
			GRL_METADATA_KEY_URL,
			GRL_METADATA_KEY_CHILDCOUNT,
			GRL_METADATA_KEY_MIME,
			GRL_METADATA_KEY_THUMBNAIL,
			GRL_METADATA_KEY_ALBUM,
			GRL_METADATA_KEY_ARTIST,
			GRL_METADATA_KEY_DATE,
			NULL);
	g_print ("Detected new source available: '%s' \n", grl_metadata_source_get_name (source));

	if ( (g_strcmp0(grl_metadata_source_get_name (source), "Tracker") == 0) && grl_metadata_source_supported_operations (source) & GRL_OP_BROWSE) 
	{	g_print ("Browsing source: %s \n", grl_metadata_source_get_name (source));

		/*grl_media_source_browse (GRL_MEDIA_SOURCE (source),
		  media_from_id("/home/rakesh/media/audio/"),
		  keys,
		  0, 500,
		  GRL_RESOLVE_IDLE_RELAY | GRL_RESOLVE_FULL,
		  browse_cb,
		  NULL); */

		GError *error = NULL;
		GList *mediaList = grl_media_source_browse_sync (GRL_MEDIA_SOURCE (source), media_from_id("<Path to Media Files >"), keys, 0, 10, GRL_RESOLVE_IDLE_RELAY | GRL_RESOLVE_FULL, &error);
		
		if( (NULL == error) && (NULL != mediaList))
		{
			g_print("No error, got %d files from grilo \n", g_list_length(mediaList));

			GList *localList = g_list_first(mediaList);
			while( (NULL != localList) && (NULL != localList->data) )
			{
				GrlMedia* media = (GrlMedia *)localList->data;

				g_print("URI = %s, Title = %s, Mime = %s, Artist = %s, Album = %s, AlbumArt =%s \n", grl_media_get_url(media), grl_media_get_title(media), grl_media_get_mime(media), grl_media_audio_get_artist( (GrlMediaAudio *) media), grl_media_audio_get_album( (GrlMediaAudio *)media), grl_media_get_thumbnail(media));

				localList = g_list_next(localList);
			}
		}
	}

	g_list_free (keys);
}

static void load_plugins (void)
{
	GrlPluginRegistry *registry;
	GError *error = NULL;

	registry = grl_plugin_registry_get_default ();
	g_signal_connect (registry, "source-added",
			G_CALLBACK (source_added_cb), NULL);
	if (!grl_plugin_registry_load_all (registry, &error)) {
		g_error ("Failed to load plugins: %s", error->message);
	}
	else
	{
		//g_print("Plugins loaded \n");
		GList *sources = grl_plugin_registry_get_sources(registry, TRUE);
		g_print("Number of sources = %d \n", g_list_length(sources));
	}

	GrlConfig *config = grl_config_new ("grl-tracker", NULL);
	grl_config_set_boolean (config, "browse-filesystem", TRUE);
	grl_plugin_registry_add_config (registry, config, NULL);

	config = grl_config_new ("grl-tracker", NULL);
	grl_config_set_boolean (config, "per-device-source", TRUE);
	grl_plugin_registry_add_config (registry, config, NULL);
}

gint main (gint argc, gchar **argv)
{
	GMainLoop *loop;
	grl_init (&argc, &argv);
	load_plugins ();
	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);
	return 0;
}



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