static void load_plugins (gchar* playlist) { GrlRegistry *registry; GrlSource *source; GError *error = NULL; GList *keys; GrlOperationOptions *options; GrlCaps *caps; GrlMedia* media; gboolean pls_media; const gchar *mime; registry = grl_registry_get_default (); grl_registry_load_all_plugins (registry, FALSE, NULL); /* Activate plugin */ if (!grl_registry_activate_plugin_by_id (registry, "grl-filesystem", &error)) g_error ("Failed to load plugin: %s", error->message); source = grl_registry_lookup_source (registry, "grl-filesystem"); if (!source) g_error ("Unable to load grl-filesystem plugin"); if (!(grl_source_supported_operations (source) & GRL_OP_MEDIA_FROM_URI)) g_error ("Unable to get media from URI"); keys = grl_metadata_key_list_new (GRL_METADATA_KEY_TITLE, GRL_METADATA_KEY_URL, GRL_METADATA_KEY_MIME, NULL); if (!keys) g_error ("Unable to create key list"); caps = grl_source_get_caps (source, GRL_OP_MEDIA_FROM_URI); if (!caps) g_error ("Unable to get source caps"); options = grl_operation_options_new (caps); if (!options) g_error ("Unable to create operation options"); media = grl_source_get_media_from_uri_sync (source, playlist, keys, options, &error); if (!media) g_error ("Unable to get GrlMedia for playlist %s", playlist); g_object_unref (options); mime = grl_media_get_mime (media); pls_media = grl_pls_media_is_playlist (media); g_printf("Got Media for %s - mime=%s\n", playlist, mime); g_printf("\tgrl_pls_media_is_playlist = %d\n", pls_media); if (pls_media) { source_browser (source, media); } g_object_unref (media); g_object_unref (source); }
/* * If we need to, generate a thumbnail. * * If the URL is not file:/// then we assume it's okay to use. * */ static void mex_grilo_program_thumbnail (MexContent *content, GrlMedia *media) { const char *url; char *thumb_path; /* If the media isn't local, then we'll ignore it for now */ url = grl_media_get_url (media); if (url == NULL || !g_str_has_prefix (url, "file:///")) return; if (GRL_IS_MEDIA_BOX (media)) { gchar *tmp; tmp = g_build_filename (mex_get_data_dir (), "common", "folder-tile.png", NULL); mex_grilo_program_set_metadata (content, MEX_CONTENT_METADATA_STILL, tmp); g_free (tmp); return; } /* * If we're already got a thumbnail, see if we're happy with it or want to * ignore it. */ thumb_path = (char*)mex_content_get_metadata (content, MEX_CONTENT_METADATA_STILL); if (thumb_path) { /* If the thumbnail is already a good one, we're done */ if (thumb_path && strstr (thumb_path, "/.thumbnails/x-huge/")) return; /* * If the thumbnail currently set is a "normal" thumbnail we ignore it on the * basis that it's likely to have been generated by Totem, and thus is bad. * If your platform doesn't have Totem then this can be removed! */ if (thumb_path && strstr (thumb_path, "/.thumbnails/normal/")) mex_grilo_program_set_metadata (content, MEX_CONTENT_METADATA_STILL, NULL); } /* * Now see if we've a thumbnail generated already. TODO: use the Tumbler API * to do this. */ thumb_path = get_thumbnail_path_for_uri (url); if (g_file_test (thumb_path, G_FILE_TEST_EXISTS)) { gchar *thumb_uri = g_filename_to_uri (thumb_path, NULL, NULL); mex_grilo_program_set_metadata (content, MEX_CONTENT_METADATA_STILL, thumb_uri); g_free (thumb_uri); } else { mex_thumbnailer_generate (url, grl_media_get_mime (media), thumbnail_cb, content); } g_free (thumb_path); }
static gboolean add_single_file_from_media (BgPicturesSource *bg_source, GFile *file, GrlMedia *media) { GDateTime *mtime; const gchar *content_type; gint64 mtime_unix; content_type = grl_media_get_mime (media); /* only GRL_METADATA_KEY_CREATION_DATE is implemented in the Flickr * plugin, GRL_METADATA_KEY_MODIFICATION_DATE is not */ mtime = grl_media_get_creation_date (media); if (!mtime) mtime = grl_media_get_modification_date (media); if (mtime) mtime_unix = g_date_time_to_unix (mtime); else mtime_unix = g_get_real_time () / G_USEC_PER_SEC; return add_single_file (bg_source, file, content_type, (guint64) mtime_unix, NULL); }
static void element_browser (gpointer data, gpointer user_data) { GrlMedia *media = GRL_MEDIA (data); GrlSource *source = GRL_SOURCE (user_data); /* Check if we got a valid media object as some plugins may call the callback with a NULL media under certain circumstances (for example when they cannot estimate the number of remaining results and they find suddenly they don't have any more results to send) */ if (!media) { g_debug ("Media element is NULL!"); goto out; } const gchar *title = grl_media_get_title (media); /* If the media is a container, that means we will browse it again */ if (grl_media_is_container (media)) { guint childcount = grl_media_get_childcount (media); g_debug ("\t Got '%s' (container with %d elements)", title, childcount); source_browser (source, media); } else { const gchar *url = grl_media_get_url (media); const gchar *mime = grl_media_get_mime (media); GDateTime *date = grl_media_get_modification_date (media); time_t rawdate = g_date_time_to_unix(date); g_printf ("\t Got '%s', of type '%s', ctime is '%s'\n", title, mime, ctime(&rawdate)); g_printf ("\t\t URL: %s\n", url); } out: g_object_unref (media); }
static void store_bookmark (GrlBookmarksSource *bookmarks_source, GList **keylist, GrlMediaBox *parent, GrlMedia *bookmark, GError **error) { GomResource *resource; const gchar *title; const gchar *url; const gchar *desc; const gchar *thumb; GTimeVal now; gint64 parent_id; const gchar *mime; gchar *date; guint type; gint64 id; gchar *str_id; GError *local_error = NULL; gboolean ret; GRL_DEBUG ("store_bookmark"); title = grl_media_get_title (bookmark); url = grl_media_get_url (bookmark); thumb = grl_media_get_thumbnail (bookmark); desc = grl_media_get_description (bookmark); mime = grl_media_get_mime (bookmark); g_get_current_time (&now); date = g_time_val_to_iso8601 (&now); if (!parent) { parent_id = 0; } else { parent_id = g_ascii_strtoll (grl_media_get_id (GRL_MEDIA (parent)), NULL, 0); } if (parent_id < 0) { parent_id = 0; } GRL_DEBUG ("URL: '%s'", url); if (GRL_IS_MEDIA_BOX (bookmark)) { type = BOOKMARK_TYPE_CATEGORY; } else { type = BOOKMARK_TYPE_STREAM; } resource = g_object_new (BOOKMARKS_TYPE_RESOURCE, "repository", bookmarks_source->priv->repository, "parent", parent_id, "type", type, NULL); if (type == BOOKMARK_TYPE_STREAM) { g_object_set (G_OBJECT (resource), "url", url, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_URL)); } if (title) { g_object_set (G_OBJECT (resource), "title", title, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_TITLE)); } else if (url) { g_object_set (G_OBJECT (resource), "title", url, NULL); } else { g_object_set (G_OBJECT (resource), "title", "(unknown)", NULL); } if (date) { g_object_set (G_OBJECT (resource), "date", date, NULL); } if (mime) { g_object_set (G_OBJECT (resource), "mime", mime, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_MIME)); } if (desc) { g_object_set (G_OBJECT (resource), "desc", desc, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_DESCRIPTION)); } if (thumb) { g_object_set (G_OBJECT (resource), "thumbnail-url", desc, NULL); *keylist = g_list_remove (*keylist, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_THUMBNAIL)); } ret = gom_resource_save_sync (resource, &local_error); if (!ret) { GRL_WARNING ("Failed to store bookmark '%s': %s", title, local_error->message); *error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_STORE_FAILED, _("Failed to store: %s"), local_error->message); g_error_free (local_error); g_object_unref (resource); return; } g_object_get (resource, "id", &id, NULL); str_id = g_strdup_printf ("%" G_GINT64_FORMAT, id); grl_media_set_id (bookmark, str_id); g_free (str_id); g_object_unref (resource); if (bookmarks_source->priv->notify_changes) { grl_source_notify_change (GRL_SOURCE (bookmarks_source), bookmark, GRL_CONTENT_ADDED, FALSE); } }
static void fill_properties_table (MS2Server *server, GHashTable *properties_table, GList *keys, GrlMedia *media) { GList *prop; GrlKeyID key; const gchar *title; gchar *id; gchar *urls[2] = { 0 }; for (prop = keys; prop; prop = g_list_next (prop)) { key = GRLPOINTER_TO_KEYID (prop->data); if (key == GRL_METADATA_KEY_ID || grl_data_has_key (GRL_DATA (media), key)) { if (key == GRL_METADATA_KEY_ID) { id = serialize_media (media); if (id) { ms2_server_set_path (server, properties_table, id, grl_media_is_container (media)); g_free (id); } } else if (key == GRL_METADATA_KEY_TITLE) { /* Ensure we always insert a valid title */ title = grl_media_get_title (media); if (!title) { title = "Unknown"; } ms2_server_set_display_name (server, properties_table, title); } else if (key == GRL_METADATA_KEY_ALBUM) { ms2_server_set_album (server, properties_table, grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM)); } else if (key == GRL_METADATA_KEY_ARTIST) { ms2_server_set_artist (server, properties_table, grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST)); } else if (key == GRL_METADATA_KEY_GENRE) { ms2_server_set_genre (server, properties_table, grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE)); } else if (key == GRL_METADATA_KEY_MIME) { ms2_server_set_mime_type (server, properties_table, grl_media_get_mime (media)); } else if (key == GRL_METADATA_KEY_URL) { urls[0] = (gchar *) grl_media_get_url (media); ms2_server_set_urls (server, properties_table, urls); } else if (key == GRL_METADATA_KEY_BITRATE) { ms2_server_set_bitrate (server, properties_table, grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_BITRATE)); } else if (key == GRL_METADATA_KEY_DURATION) { ms2_server_set_duration (server, properties_table, grl_media_get_duration (media)); } else if (key == GRL_METADATA_KEY_HEIGHT) { ms2_server_set_height (server, properties_table, grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_HEIGHT)); } else if (key == GRL_METADATA_KEY_WIDTH) { ms2_server_set_width (server, properties_table, grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_WIDTH)); } else if (key == GRL_METADATA_KEY_GRILO_MS2_PARENT) { if (grl_media_get_id (media) == NULL) { ms2_server_set_parent (server, properties_table, MS2_ROOT); } else { ms2_server_set_parent (server, properties_table, grl_media_get_grilo_ms2_parent (media)); } } } } }