gboolean grl_tmdb_source_plugin_init (GrlRegistry *registry, GrlPlugin *plugin, GList *configs) { GrlConfig *config; char *api_key; GRL_LOG_DOMAIN_INIT (tmdb_log_domain, "tmdb"); GRL_DEBUG ("grl_tmdb_source_plugin_init"); /* Initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); if (!configs) { GRL_INFO ("No configuration provided. Will not load plugin"); return FALSE; } config = GRL_CONFIG (configs->data); api_key = grl_config_get_api_key (config); if (!api_key) { GRL_INFO ("Missing API Key, cannot load plugin"); return FALSE; } GRL_TMDB_METADATA_KEY_BACKDROP = register_metadata_key (registry, "tmdb-backdrop", "tmdb-backdrop", "A list of URLs for movie backdrops"); GRL_TMDB_METADATA_KEY_POSTER = register_metadata_key (registry, "tmdb-poster", "tmdb-poster", "A list of URLs for movie posters"); GRL_TMDB_METADATA_KEY_IMDB_ID = register_metadata_key (registry, "tmdb-imdb-id", "tmdb-imdb-id", "ID of this movie at imdb.org"); GRL_TMDB_METADATA_KEY_TMDB_ID = register_metadata_key (registry, "tmdb-id", "tmdb-id", "ID of this movie at tmdb.org"); GrlTmdbSource *source = grl_tmdb_source_new (api_key); grl_registry_register_source (registry, plugin, GRL_SOURCE (source), NULL); g_free (api_key); return TRUE; }
gboolean grl_local_metadata_source_plugin_init (GrlRegistry *registry, GrlPlugin *plugin, GList *configs) { guint config_count; gboolean guess_video = TRUE; GrlConfig *config; GRL_LOG_DOMAIN_INIT (local_metadata_log_domain, "local-metadata"); GRL_DEBUG ("grl_local_metadata_source_plugin_init"); /* Initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); if (!configs) { GRL_INFO ("\tConfiguration not provided! Using default configuration."); } else { config_count = g_list_length (configs); if (config_count > 1) { GRL_INFO ("\tProvided %i configs, but will only use one", config_count); } config = GRL_CONFIG (configs->data); guess_video = grl_config_get_boolean (config, "guess-video"); } GrlLocalMetadataSource *source = grl_local_metadata_source_new (guess_video); grl_registry_register_source (registry, plugin, GRL_SOURCE (source), NULL); return TRUE; }
gboolean grl_tmdb_source_plugin_init (GrlRegistry *registry, GrlPlugin *plugin, GList *configs) { GrlConfig *config; char *api_key; GRL_LOG_DOMAIN_INIT (tmdb_log_domain, "tmdb"); GRL_DEBUG ("grl_tmdb_source_plugin_init"); /* Initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); if (!configs) { GRL_INFO ("No configuration provided. Will not load plugin"); return FALSE; } config = GRL_CONFIG (configs->data); api_key = grl_config_get_api_key (config); if (!api_key) { GRL_INFO ("Missing API Key, cannot load plugin"); return FALSE; } GrlTmdbSource *source = grl_tmdb_source_new (api_key); grl_registry_register_source (registry, plugin, GRL_SOURCE (source), NULL); g_free (api_key); return TRUE; }
gboolean grl_vimeo_plugin_init (GrlRegistry *registry, GrlPlugin *plugin, GList *configs) { gchar *vimeo_key; gchar *vimeo_secret; gchar *format; GrlConfig *config; gint config_count; gboolean init_result = FALSE; GrlVimeoSource *source; GRL_LOG_DOMAIN_INIT (vimeo_log_domain, "vimeo"); GRL_DEBUG ("vimeo_plugin_init"); /* Initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); if (!configs) { GRL_INFO ("Configuration not provided! Plugin not loaded"); return FALSE; } config_count = g_list_length (configs); if (config_count > 1) { GRL_INFO ("Provided %d configs, but will only use one", config_count); } config = GRL_CONFIG (configs->data); vimeo_key = grl_config_get_api_key (config); vimeo_secret = grl_config_get_api_secret (config); if (!vimeo_key || !vimeo_secret) { GRL_INFO ("Required API key or secret configuration not provided." " Plugin not loaded"); goto go_out; } source = grl_vimeo_source_new (); source->priv->vimeo = g_vimeo_new (vimeo_key, vimeo_secret); format = grl_config_get_string (config, "format"); if (format) { g_object_set (source->priv->vimeo, "quvi-format", format, NULL); g_free (format); } grl_registry_register_source (registry, plugin, GRL_SOURCE (source), NULL); init_result = TRUE; go_out: g_clear_pointer (&vimeo_key, g_free); g_clear_pointer (&vimeo_secret, g_free); return init_result; }
static void got_file_info (GFile *file, GAsyncResult *result, gpointer user_data) { GCancellable *cancellable; GFileInfo *info; GError *error = NULL; const gchar *thumbnail_path; gboolean thumbnail_is_valid; GrlLocalMetadataSourcePriv *priv; ResolveData *resolve_data = user_data; GrlSourceResolveSpec *rs = resolve_data->rs; resolution_flags_t flags; GRL_DEBUG ("got_file_info"); priv = GRL_LOCAL_METADATA_SOURCE_GET_PRIVATE (resolve_data->source); cancellable = resolve_data_ensure_cancellable (resolve_data); info = g_file_query_info_finish (file, result, &error); if (error) goto error; thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); #if GLIB_CHECK_VERSION (2, 39, 0) thumbnail_is_valid = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID); #else thumbnail_is_valid = TRUE; #endif if (thumbnail_path && thumbnail_is_valid) { gchar *thumbnail_uri = g_filename_to_uri (thumbnail_path, NULL, &error); if (error) goto error; GRL_INFO ("Got thumbnail %s for media: %s", thumbnail_uri, grl_media_get_url (rs->media)); grl_media_set_thumbnail (rs->media, thumbnail_uri); g_free (thumbnail_uri); } else if (thumbnail_path && !thumbnail_is_valid) { GRL_INFO ("Found outdated thumbnail %s for media: %s", thumbnail_path, grl_media_get_url (rs->media)); } else { GRL_INFO ("Could not find thumbnail for media: %s", grl_media_get_url (rs->media)); } flags = get_resolution_flags (rs->keys, priv); if (GRL_IS_MEDIA_AUDIO (rs->media) && !(thumbnail_path && thumbnail_is_valid)) { /* We couldn't get a per-track thumbnail; try for a per-album one, * using libmediaart */ resolve_album_art (resolve_data, flags); } if (flags & FLAG_GIBEST_HASH) { extract_gibest_hash_async (resolve_data, file, cancellable); } else { resolve_data_finish_operation (resolve_data, "image", NULL); } goto exit; error: { GError *new_error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("Failed to resolve: %s"), error->message); resolve_data_finish_operation (resolve_data, "image", new_error); g_error_free (error); g_error_free (new_error); } exit: g_clear_object (&info); }