Ejemplo n.º 1
0
GrlSource *GriloRegistry::lookupSource(const QString& id) {
  if (m_registry) {
    return grl_registry_lookup_source(m_registry, id.toUtf8().constData());
  }

  return 0;
}
void
test_setup_thetvdb (void)
{
  GrlConfig *config;
  GrlRegistry *registry;
  GError *error = NULL;

  if (tmp_dir == NULL) {
    /* Only create tmp dir and set the XDG_DATA_HOME once */
    tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL);
    tmp_dir = g_mkdtemp (tmp_dir);
    g_assert_nonnull (tmp_dir);

    g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE);
  }

  config = grl_config_new (THETVDB_ID, NULL);
  grl_config_set_api_key (config, "THETVDB_TEST_MOCK_API_KEY");

  registry = grl_registry_get_default ();
  grl_registry_add_config (registry, config, &error);
  g_assert_no_error (error);

  grl_registry_load_plugin_by_id (registry, THETVDB_ID, &error);
  g_assert_no_error (error);

  source = GRL_SOURCE (grl_registry_lookup_source (registry, THETVDB_ID));
  g_assert (source != NULL);

  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
}
Ejemplo n.º 3
0
static void
server_lost_cb (GrlDleynaServersManager *serversmgr,
                GrlDleynaServer         *server,
                gpointer                *user_data)
{
  GrlDleynaMediaDevice *device;
  GrlSource *source;
  GrlRegistry *registry;
  const gchar* udn;
  gchar *source_id;

  GRL_DEBUG (G_STRFUNC);
  device = grl_dleyna_server_get_media_device (server);
  udn = grl_dleyna_media_device_get_udn (device);
  GRL_DEBUG ("%s udn: %s ", G_STRFUNC, udn);

  registry = grl_registry_get_default ();
  source_id = grl_dleyna_source_build_id (udn);

  GRL_DEBUG ("%s id: %s ", G_STRFUNC, source_id);

  source = grl_registry_lookup_source (registry, source_id);
  if (source != NULL) {
    GError *error = NULL;
    GRL_DEBUG ("%s unregistered %s", G_STRFUNC, source_id);
    grl_registry_unregister_source (registry, source, &error);
    if (error != NULL) {
      GRL_WARNING ("Failed to unregister source %s: %s", udn, error->message);
      g_error_free (error);
    }
  }

  g_free (source_id);
}
Ejemplo n.º 4
0
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);
}
static GrlSource*
test_lua_factory_get_source (gchar *source_id,
                             GrlSupportedOps source_ops)
{
  GrlRegistry *registry = grl_registry_get_default ();
  GrlSource *source = grl_registry_lookup_source (registry, source_id);
  g_assert_nonnull (source);
  g_assert (grl_source_supported_operations (source) & source_ops);
  return source;
}
void
test_setup_tmdb (void)
{
  GrlConfig *config;
  GrlRegistry *registry;
  GError *error = NULL;

  config = grl_config_new (TMDB_PLUGIN_ID, NULL);
  /* It does not matter what we set this to. It just needs to be non-empty because we're
   * going to fake the network responses. */
  grl_config_set_api_key (config, "TMDB_TEST_API_KEY");

  registry = grl_registry_get_default ();
  grl_registry_add_config (registry, config, &error);
  g_assert_no_error (error);

  grl_registry_load_plugin_by_id (registry, TMDB_PLUGIN_ID, &error);
  g_assert_no_error (error);

  source = GRL_SOURCE (grl_registry_lookup_source (registry, TMDB_PLUGIN_ID));
  g_assert (source != NULL);

  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
}
Ejemplo n.º 7
0
int main (int argc, char *argv[])
{
#if !GLIB_CHECK_VERSION(2,35,0)
  g_type_init ();
#endif

  grl_init (&argc, &argv);

  /*
   * Set the TMDB API key:
   * You must use your own TMDB API key in your own application.
   */
  GrlRegistry *reg = grl_registry_get_default ();
  GrlConfig *config = grl_config_new (TMDB_PLUGIN_ID, NULL);
  grl_config_set_api_key (config, TMDB_KEY);
  grl_registry_add_config (reg, config, NULL);

  /*
   * Get the plugin:
   */
  GError *error = NULL;
  gboolean plugin_loaded =
    grl_registry_load_plugin_by_id (reg, TMDB_PLUGIN_ID, &error);
  g_assert (plugin_loaded);
  g_assert_no_error (error);

  /*
   * Get the Grilo source:
   */
  GrlSource *src =
    grl_registry_lookup_source (reg, TMDB_PLUGIN_ID);

  /*
   * Check that it has the expected capability:
   */
  g_assert (grl_source_supported_operations (src) & GRL_OP_RESOLVE);
  GrlCaps *caps = grl_source_get_caps (src, GRL_OP_RESOLVE);
  g_assert (caps);

  GrlOperationOptions *options = grl_operation_options_new (caps);

  /*
   * A media item that we will give to the TMDB plugin,
   * to discover its details.
   */
  GrlMedia *media = grl_media_video_new ();
  grl_media_set_title (media, "Sherlock Holmes");

  /*
   * Discover what keys are provided by the source:
   */
  const GList *keys = grl_source_supported_keys (src);
  const GList* l = NULL;
  for (l = keys; l != NULL; l = l->next) {
    GrlKeyID id = GPOINTER_TO_INT (l->data);
    g_assert (id);

    const gchar *name = grl_metadata_key_get_name (id);
    printf ("Supported key: %s\n", name);

    /*
     * Remember this for later use:
     * You may instead use grl_registry_lookup_metadata_key_name().
     */
    if (g_strcmp0 (name, "tmdb-director") == 0) {
      director_key = id;
    }
  }

  /*
   * Ask the TMDB plugin for the media item's details,
   * from the TMDB online service:
   */
  grl_source_resolve (src, media,
    keys, options,
    resolve_cb, NULL);

  /*
   * Start the main loop so our callback can be called:
   */
  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);

  /*
   * Release objects:
   */
  g_object_unref (media);
  g_object_unref (config);
  g_object_unref (options);

  /*
   * Deinitialize Grilo:
   */
  grl_deinit ();
}