示例#1
0
static void
source_browser (gpointer data,
                gpointer user_data)
{
  GrlSource *source = GRL_SOURCE (data);
  GrlMedia *media = GRL_MEDIA (user_data);
  GList *media_elements;
  GError *error = NULL;
  GList *keys;
  GrlOperationOptions *options = NULL;
  GrlCaps *caps;

  keys = grl_metadata_key_list_new (GRL_METADATA_KEY_TITLE,
                                    GRL_METADATA_KEY_URL,
                                    GRL_METADATA_KEY_MODIFICATION_DATE,
                                    GRL_METADATA_KEY_MIME,
                                    GRL_METADATA_KEY_CHILDCOUNT,
                                    NULL);

  g_debug ("Detected new source available: '%s'",
	   grl_source_get_name (source));

  if (!(grl_source_supported_operations (source) & GRL_OP_BROWSE))
    goto out;

  g_debug ("Browsing source: %s", grl_source_get_name (source));
  /* Here is how you can browse a source, you have to provide:
     1) The source you want to browse contents from.
     2) The container object you want to browse (NULL for the root container)
     3) A list of metadata keys we are interested in.
     4) Options to control certain aspects of the browse operation.
     5) A callback that the framework will invoke for each available result
     6) User data for the callback
     It returns an operation identifier that you can use to match results
     with the corresponding request (we ignore it here) */

  caps = grl_source_get_caps (source, GRL_OP_BROWSE);
  options = grl_operation_options_new (caps);
  grl_operation_options_set_count (options, BROWSE_CHUNK_SIZE);
  grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_IDLE_RELAY);
  media_elements = grl_pls_browse_sync (GRL_SOURCE (source),
                                        media, keys,
                                        options,
                                        NULL,
                                        &error);
  if (!media_elements) {
    g_debug ("No elements found for source: %s!",
             grl_source_get_name (source));
    goto out;
  }

  if (error)
    g_error ("Failed to browse source: %s", error->message);

  g_list_foreach (media_elements, element_browser, source);

out:
  g_list_free (keys);
  g_clear_object (&options);
}
示例#2
0
static gchar *
get_lyrics (GrlSource *source,
            const gchar *artist,
            const gchar *title)
{
  GList *keys;
  GrlMedia *audio;
  GrlOperationOptions *options;
  GError *error = NULL;
  gchar *lyrics;

  audio = grl_media_audio_new ();
  grl_media_set_artist (audio, artist);
  grl_media_set_title (audio, title);

  keys = grl_metadata_key_list_new (GRL_METADATA_KEY_LYRICS, NULL);
  options = grl_operation_options_new (NULL);
  grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_NORMAL);

  grl_source_resolve_sync (source,
                           GRL_MEDIA (audio),
                           keys,
                           options,
                           &error);
  g_assert_no_error (error);

  lyrics = g_strdup (grl_media_get_lyrics (audio));

  g_list_free (keys);
  g_object_unref (options);
  g_object_unref (audio);
  return lyrics;
}
static GrlMedia *
create_media_box (GrlDvbDaemonExporter *self)
{
	GrlMedia * box = GRL_MEDIA (grl_media_box_new ());
	grl_media_set_id (box, self->priv->channel_list_path);
	grl_media_set_title (box, self->priv->name);
	return box;
}
static void
add_model (MexBliptvPlugin *self,
           GrlSource *source)
{
  MexFeed *feed;
  GrlMedia *box;

  box = grl_media_video_new ();

  grl_media_set_id (GRL_MEDIA (box), NULL);
  feed = mex_grilo_feed_new (source,
                             self->priv->query_keys,
                             self->priv->video_keys, box);
  g_object_set (feed, "icon-name", "icon-panelheader-computer",
                "placeholder-text", "No videos found",
                "category", "videos",
                NULL);
  mex_grilo_feed_browse (MEX_GRILO_FEED (feed), 0, 100);

  g_hash_table_insert (self->priv->video_models, source, feed);

  mex_model_manager_add_model (self->priv->manager, MEX_MODEL (feed));
}
示例#5
0
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 RhythmDBEntry *
create_entry_for_media (RhythmDB *db, RhythmDBEntryType *entry_type, GrlData *data, GrlData *container)
{
	RhythmDBEntry *entry;
	RBGriloEntryData *entry_data;

	entry = rhythmdb_entry_lookup_by_location (db, grl_media_get_url (GRL_MEDIA (data)));
	if (entry != NULL) {
		return entry;
	}

	rb_debug ("creating entry for %s / %s", grl_media_get_url (GRL_MEDIA (data)), grl_media_get_id (GRL_MEDIA (data)));

	entry = rhythmdb_entry_new (db, entry_type, grl_media_get_url (GRL_MEDIA (data)));	/* just use the url? */
	if (entry == NULL) {
		/* crap. */
		return NULL;
	}

	set_string_prop_from_key (db, entry, RHYTHMDB_PROP_TITLE, data, GRL_METADATA_KEY_TITLE);
	set_string_prop_from_key (db, entry, RHYTHMDB_PROP_ALBUM, data, GRL_METADATA_KEY_ALBUM);
	set_string_prop_from_key (db, entry, RHYTHMDB_PROP_ARTIST, data, GRL_METADATA_KEY_ARTIST);
	set_string_prop_from_key (db, entry, RHYTHMDB_PROP_GENRE, data, GRL_METADATA_KEY_GENRE);
	set_string_prop_from_key (db, entry, RHYTHMDB_PROP_TITLE, data, GRL_METADATA_KEY_TITLE);

	if (grl_data_has_key (data, GRL_METADATA_KEY_PUBLICATION_DATE)) {
		/* something - grilo has this as a string? */
	}

	if (grl_data_has_key (data, GRL_METADATA_KEY_BITRATE)) {
		GValue v = {0,};
		g_value_init (&v, G_TYPE_ULONG);
		g_value_set_ulong (&v, grl_data_get_int (data, GRL_METADATA_KEY_BITRATE));
		rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_BITRATE, &v);
		g_value_unset (&v);
	}

	if (grl_data_has_key (data, GRL_METADATA_KEY_DURATION)) {
		/* this is probably in seconds */
		GValue v = {0,};
		g_value_init (&v, G_TYPE_ULONG);
		g_value_set_ulong (&v, grl_data_get_int (data, GRL_METADATA_KEY_DURATION));
		rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_DURATION, &v);
		g_value_unset (&v);
	}

	if (grl_data_has_key (data, GRL_METADATA_KEY_MIME)) {
		const char *media_type;
		media_type = rb_gst_mime_type_to_media_type (grl_data_get_string (data, GRL_METADATA_KEY_MIME));
		if (media_type) {
			GValue v = {0,};
			g_value_init (&v, G_TYPE_STRING);
			g_value_set_string (&v, media_type);
			rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_MEDIA_TYPE, &v);
			g_value_unset (&v);
		}
	}

	if (grl_data_has_key (data, GRL_METADATA_KEY_TRACK_NUMBER)) {
		GValue v = {0,};
		g_value_init (&v, G_TYPE_ULONG);
		g_value_set_ulong (&v, grl_data_get_int (data, GRL_METADATA_KEY_TRACK_NUMBER));
		rhythmdb_entry_set (db, entry, RHYTHMDB_PROP_TRACK_NUMBER, &v);
		g_value_unset (&v);
	}

	/* rating and play count? */

	entry_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBGriloEntryData);
	entry_data->grilo_data = g_object_ref (data);
	if (container != NULL) {
		entry_data->grilo_container = g_object_ref (container);
	}

	/* might want to consider batching this */
	rhythmdb_commit (db);

	return entry;
}
示例#7
0
static void
on_request_ready (GObject *source,
                  GAsyncResult *result,
                  gpointer user_data) {
  ResolveClosure *closure = (ResolveClosure *) user_data;
  GrlTmdbRequest *request = GRL_TMDB_REQUEST (source);
  const GrlTmdbRequestDetail detail = grl_tmdb_request_get_detail (request);
  GError *error = NULL;
  GList *values, *iter;
  GValue *value;

  if (detail != GRL_TMDB_REQUEST_DETAIL_COUNT) {
    GRL_DEBUG ("Detail request (%s) ready for movie #%" G_GUINT64_FORMAT "...",
               grl_tmdb_request_detail_to_string (detail), closure->id);
  } else {
    GRL_DEBUG ("Detail request (aggregated) ready for movie #%" G_GUINT64_FORMAT "...",
               closure->id);
  }

  if (!grl_tmdb_request_run_finish (GRL_TMDB_REQUEST (source),
                                    result,
                                    &error)) {
    /* Just remove the request and hope the others have some data */
    GRL_WARNING ("Failed to get %s: %s",
                 grl_tmdb_request_get_uri (request),
                 error->message);
    goto out;
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_GENRE)) {
    iter = values = grl_tmdb_request_get_string_list (request, "$.genres..name");
    while (iter != NULL) {
      grl_data_add_string (GRL_DATA (closure->rs->media),
                           GRL_METADATA_KEY_GENRE, iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_STUDIO)) {
    iter = values = grl_tmdb_request_get_string_list (request, "$.production_companies..name");
    while (iter != NULL) {
      grl_data_add_string (GRL_DATA (closure->rs->media),
                           GRL_METADATA_KEY_STUDIO, iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_SITE)) {
    value = grl_tmdb_request_get (request, "$.homepage");
    if (value != NULL) {
      grl_media_set_site (closure->rs->media, g_value_get_string (value));
      g_value_unset (value);
      g_free (value);
    }
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_DESCRIPTION)) {
    value = grl_tmdb_request_get (request, "$.overview");
    if (value != NULL) {
      grl_media_set_description (closure->rs->media,
                                 g_value_get_string (value));
      g_value_unset (value);
      g_free (value);
    }
  }

  if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_IMDB_ID)) {
    value = grl_tmdb_request_get (request, "$.imdb_id");
    if (value != NULL) {
      grl_data_set_string (GRL_DATA (closure->rs->media),
                           GRL_TMDB_METADATA_KEY_IMDB_ID,
                           g_value_get_string (value));
      g_value_unset (value);
      g_free (value);
    }
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_RATING)) {
    value = grl_tmdb_request_get (request, "$.vote_average");
    if (value != NULL) {
      grl_media_set_rating (closure->rs->media,
                            (float) g_value_get_double (value),
                            10.0f);
      g_value_unset (value);
      g_free (value);
    }
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_ORIGINAL_TITLE)) {
    value = grl_tmdb_request_get (request, "$.original_title");
    if (value != NULL) {
      grl_media_set_original_title (closure->rs->media, g_value_get_string (value));
      g_value_unset (value);
      g_free (value);
    }
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_TITLE)) {
    value = grl_tmdb_request_get (request, "$.title");
    if (value != NULL) {
      grl_media_set_title (closure->rs->media, g_value_get_string (value));
      grl_data_set_boolean (GRL_DATA (closure->rs->media), GRL_METADATA_KEY_TITLE_FROM_FILENAME, FALSE);
      g_value_unset (value);
      g_free (value);
    }
  }

  if (!closure->slow) {
    /* Add thumbnails first and poster and backdrops later.
     * Posters more likely make a good thumbnail than backdrops.
     */
    if (SHOULD_RESOLVE (GRL_METADATA_KEY_THUMBNAIL)) {
      value = grl_tmdb_request_get (request, "$.poster_path");
      if (value != NULL) {
          add_image (closure->self, closure->rs->media,
                     GRL_METADATA_KEY_THUMBNAIL,
                     g_value_get_string (value));

          g_value_unset (value);
          g_free (value);
      }
    }

    if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_POSTER)) {
      value = grl_tmdb_request_get (request, "$.poster_path");
      if (value != NULL) {
          add_image (closure->self, closure->rs->media,
                     GRL_TMDB_METADATA_KEY_POSTER,
                     g_value_get_string (value));

          g_value_unset (value);
          g_free (value);
      }
    }

    if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_BACKDROP)) {
      value = grl_tmdb_request_get (request, "$.backdrop_path");
      if (value != NULL) {
        add_image (closure->self, closure->rs->media,
                   GRL_TMDB_METADATA_KEY_BACKDROP,
                   g_value_get_string (value));

        g_value_unset (value);
        g_free (value);
      }
    }
  }

  /* Add thumbnails first, and posters and backdrops later.
   * Posters more likely make a good thumbnail than backdrops.
   */
  if (SHOULD_RESOLVE (GRL_METADATA_KEY_THUMBNAIL)) {
    values = grl_tmdb_request_get_string_list_with_filter (request,
                                                           "$.posters",
                                                           neutral_backdrop_filter);
    if (!values)
      values = grl_tmdb_request_get_string_list_with_filter (request,
                                                             "$.images.posters",
                                                             neutral_backdrop_filter);
    iter = values;
    while (iter != NULL) {
      add_image (closure->self, closure->rs->media,
                 GRL_METADATA_KEY_THUMBNAIL,
                 iter->data);

      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_POSTER)) {
    values = grl_tmdb_request_get_string_list_with_filter (request,
                                                           "$.posters",
                                                           neutral_backdrop_filter);
    if (!values)
      values = grl_tmdb_request_get_string_list_with_filter (request,
                                                             "$.images.posters",
                                                             neutral_backdrop_filter);
    iter = values;
    while (iter != NULL) {
      add_image (closure->self, closure->rs->media,
                 GRL_TMDB_METADATA_KEY_POSTER,
                 iter->data);

      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_BACKDROP)) {
    values = grl_tmdb_request_get_string_list_with_filter (request,
                                                           "$.backdrops",
                                                           neutral_backdrop_filter);
    if (!values)
      values = grl_tmdb_request_get_string_list_with_filter (request,
                                                             "$.images.backdrops",
                                                             neutral_backdrop_filter);
    iter = values;
    while (iter != NULL) {
      add_image (closure->self, closure->rs->media,
                 GRL_TMDB_METADATA_KEY_BACKDROP,
                 iter->data);

      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_KEYWORD)) {
    values = grl_tmdb_request_get_string_list (request,
                                               "$.keywords..name");
    if (!values)
      values = grl_tmdb_request_get_string_list (request,
                                                 "$.keywords.keywords..name");
    iter = values;
    while (iter != NULL) {
      grl_media_add_keyword (closure->rs->media, iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_PERFORMER)) {
    values = grl_tmdb_request_get_string_list (request, "$.cast..name");
    if (!values)
      values = grl_tmdb_request_get_string_list (request, "$.casts.cast..name");
    iter = values;
    while (iter != NULL) {
      grl_media_add_performer (closure->rs->media, iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_PRODUCER)) {
    values = grl_tmdb_request_get_string_list_with_filter (request,
                                                           "$.crew[*]",
                                                           producer_filter);
    if (!values)
      values = grl_tmdb_request_get_string_list_with_filter (request,
                                                             "$.casts.crew[*]",
                                                             producer_filter);
    iter = values;
    while (iter != NULL) {
        grl_media_add_producer (closure->rs->media, iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_DIRECTOR)) {
    values = grl_tmdb_request_get_string_list_with_filter (request,
                                                           "$.crew[*]",
                                                           director_filter);
    if (!values)
      values = grl_tmdb_request_get_string_list_with_filter (request,
                                                             "$.casts.crew[*]",
                                                             director_filter);
    iter = values;
    while (iter != NULL) {
      grl_media_add_director (closure->rs->media, iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_AUTHOR)) {
    values = grl_tmdb_request_get_string_list_with_filter (request,
                                                           "$.crew[*]",
                                                           writer_filter);
    if (!values)
      values = grl_tmdb_request_get_string_list_with_filter (request,
                                                             "$.casts.crew[*]",
                                                             writer_filter);
    iter = values;
    while (iter != NULL) {
      grl_media_add_author (GRL_MEDIA (closure->rs->media),
                            iter->data);
      iter = iter->next;
    }
    g_list_free_full (values, g_free);
  }

  if (SHOULD_RESOLVE (GRL_METADATA_KEY_REGION) ||
          SHOULD_RESOLVE (GRL_METADATA_KEY_CERTIFICATE) ||
          SHOULD_RESOLVE (GRL_METADATA_KEY_PUBLICATION_DATE)) {
    values = grl_tmdb_request_get_list_with_filter (request,
                                                    "$.countries[*]",
                                                    NULL);
    if (!values)
      values = grl_tmdb_request_get_list_with_filter (request,
                                                      "$.releases.countries[*]",
                                                      NULL);

    for (iter = values; iter != NULL; iter = iter->next) {
      const char *region, *cert, *date;
      GDateTime *pubdate;
      JsonObject *object;

      object = json_node_get_object (iter->data);
      region = json_object_get_string_member (object, "iso_3166_1");
      cert = json_object_get_string_member (object, "certification");
      date = json_object_get_string_member (object, "release_date");
      pubdate = parse_date (date);

      grl_media_add_region_data (closure->rs->media, region, pubdate, cert);

      g_date_time_unref (pubdate);
    }

    g_list_free_full (values, (GDestroyNotify) json_node_free);
  }

out:
  if (error != NULL) {
    g_error_free (error);
  }

  remove_request (closure, request);

  if (g_queue_is_empty (closure->pending_requests)) {
    resolve_closure_callback (closure, NULL);
    resolve_closure_free (closure);
  }
}
示例#8
0
static void
grl_metadata_store_source_search (GrlSource *source,
                                  GrlSourceSearchSpec *ss)
{
  sqlite3_stmt *sql_stmt = NULL;
  sqlite3 *db;
  gchar *sql;
  gint r;
  gint i;
  GError *error = NULL;
  GrlMedia *media;
  GList *iter, *medias = NULL;
  GValue *filter_favourite_val;
  GValue *filter_source_val;
  GrlTypeFilter filter_type_val;
  GString *filters;
  guint count;
  gint type_filter[3];

  GRL_DEBUG (__FUNCTION__);

  db = GRL_METADATA_STORE_SOURCE (source)->priv->db;
  if (!db) {
    GRL_WARNING ("Can't execute operation: no database connection.");
    error = g_error_new_literal (GRL_CORE_ERROR,
                                 GRL_CORE_ERROR_QUERY_FAILED,
                                 _("No database connection"));
    ss->callback (ss->source, ss->operation_id, NULL, 0, ss->user_data, error);
    g_error_free (error);
    return;
  }

  filters = g_string_new ("");

  filter_favourite_val = grl_operation_options_get_key_filter (ss->options,
                                                               GRL_METADATA_KEY_FAVOURITE);
  filter_source_val = grl_operation_options_get_key_filter (ss->options,
                                                            GRL_METADATA_KEY_SOURCE);
  filter_type_val = grl_operation_options_get_type_filter (ss->options);

  if (filter_favourite_val) {
    filters = g_string_append (filters, GRL_SQL_FAVOURITE_FILTER);
  }

  if (filter_source_val) {
    if (filters->len > 0) {
      filters = g_string_append (filters, " AND ");
    }
    filters = g_string_append (filters, GRL_SQL_SOURCE_FILTER);
  }

  if (filter_type_val != GRL_TYPE_FILTER_ALL) {
    /* Fill the type_filter array */
    if (filter_type_val & GRL_TYPE_FILTER_AUDIO) {
      type_filter[0] = MEDIA_AUDIO;
    } else {
      type_filter[0] = -1;
    }
    if (filter_type_val & GRL_TYPE_FILTER_VIDEO) {
      type_filter[1] = MEDIA_VIDEO;
    } else {
      type_filter[1] = -1;
    }
    if (filter_type_val & GRL_TYPE_FILTER_IMAGE) {
      type_filter[2] = MEDIA_IMAGE;
    } else {
      type_filter[2] = -1;
    }
    if (filters->len > 0) {
      filters = g_string_append (filters, " AND ");
    }
    filters = g_string_append (filters, GRL_SQL_TYPE_FILTER);
  }

  if (filters->len > 0) {
    sql = g_strdup_printf (GRL_SQL_SEARCH_FILTER,
                           filters->str,
                           grl_operation_options_get_count (ss->options),
                           grl_operation_options_get_skip (ss->options));
  } else {
    sql = g_strdup_printf (GRL_SQL_SEARCH,
                           grl_operation_options_get_count (ss->options),
                           grl_operation_options_get_skip (ss->options));
  }

  r = sqlite3_prepare_v2 (db, sql, -1, &sql_stmt, NULL);

  g_free (sql);
  g_string_free (filters, TRUE);

  if (r != SQLITE_OK) {
    GRL_WARNING ("Failed to search in the metadata store: %s", sqlite3_errmsg (db));
    error = g_error_new (GRL_CORE_ERROR,
                         GRL_CORE_ERROR_SEARCH_FAILED,
                         _("Failed to search: %s"),
                         sqlite3_errmsg (db));
    ss->callback (ss->source, ss->operation_id, NULL, 0, ss->user_data, error);
    g_error_free (error);
    return;
  }

  count = 1;

  if (filter_favourite_val) {
    sqlite3_bind_int (sql_stmt, count++, (gint) g_value_get_boolean (filter_favourite_val));
  }

  if (filter_source_val) {
    sqlite3_bind_text (sql_stmt, count++, g_value_get_string (filter_source_val), -1, SQLITE_STATIC);
  }

  if (filter_type_val != GRL_TYPE_FILTER_ALL) {
    for (i = 0; i < G_N_ELEMENTS (type_filter); i++) {
      sqlite3_bind_int (sql_stmt, count++, type_filter[i]);
    }
  }

  while ((r = sqlite3_step (sql_stmt)) == SQLITE_BUSY);

  count = 0;
  while (r == SQLITE_ROW) {
    media = create_media (sql_stmt, ss->keys);
    medias = g_list_prepend (medias, media);
    count++;
    r = sqlite3_step (sql_stmt);
  }

  if (r != SQLITE_DONE) {
    GRL_WARNING ("Failed to search in the metadata store: %s", sqlite3_errmsg (db));
    error = g_error_new (GRL_CORE_ERROR,
                         GRL_CORE_ERROR_SEARCH_FAILED,
                         _("Failed to search: %s"),
                         sqlite3_errmsg (db));
    ss->callback (ss->source, ss->operation_id, NULL, 0, ss->user_data, error);
    g_error_free (error);
    sqlite3_finalize (sql_stmt);
    return;
  }

  sqlite3_finalize (sql_stmt);

  if (count > 0) {
    iter = medias;
    while (iter) {
      media = GRL_MEDIA (iter->data);
      ss->callback (ss->source,
                    ss->operation_id,
                    media,
                    --count,
                    ss->user_data,
                    NULL);
      iter = g_list_next (iter);
    }
    g_list_free (medias);
  } else {
    ss->callback (ss->source, ss->operation_id, NULL, 0, ss->user_data, NULL);
  }
}
示例#9
0
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);
  }
}
示例#10
0
static GrlMedia *
build_media_from_resource (GrlMedia      *content,
                           GomResource   *resource,
                           GrlTypeFilter  type_filter)
{
  GrlMedia *media = NULL;
  gint64 id;
  gchar *str_id;
  gchar *title;
  gchar *url;
  gchar *desc;
  gchar *date;
  gchar *mime;
  gchar *thumb;
  guint type;

  if (content) {
    media = content;
  }

  g_object_get (resource,
                  "id", &id,
                  "title", &title,
                  "url", &url,
                  "desc", &desc,
                  "date", &date,
                  "mime", &mime,
                  "type", &type,
                  "thumbnail-url", &thumb,
                  NULL);

  if (!media) {
    if (type == BOOKMARK_TYPE_CATEGORY) {
      media = GRL_MEDIA (grl_media_box_new ());
    } else if (mime_is_audio (mime)) {
      if (type_filter & GRL_TYPE_FILTER_AUDIO)
        media = GRL_MEDIA (grl_media_new ());
    } else if (mime_is_video (mime)) {
      if (type_filter & GRL_TYPE_FILTER_VIDEO)
        media = GRL_MEDIA (grl_media_new ());
    } else if (mime_is_image (mime)) {
      if (type_filter & GRL_TYPE_FILTER_IMAGE)
        media = GRL_MEDIA (grl_media_image_new ());
    } else {
      if (type_filter != GRL_TYPE_FILTER_NONE)
        media = GRL_MEDIA (grl_media_new ());
    }
  }

  if (!media)
    return NULL;

  str_id = g_strdup_printf ("%" G_GINT64_FORMAT, id);
  grl_media_set_id (media, str_id);
  g_free (str_id);
  grl_media_set_title (media, title);
  if (url) {
    grl_media_set_url (media, url);
  }
  if (desc) {
    grl_media_set_description (media, desc);
  }

  if (date) {
    GDateTime *date_time = grl_date_time_from_iso8601 (date);
    if (date_time) {
      grl_data_set_boxed (GRL_DATA (media),
                          GRL_BOOKMARKS_KEY_BOOKMARK_TIME,
                          date_time);
      g_date_time_unref (date_time);
    }
  }

  if (thumb) {
    grl_media_set_thumbnail (media, thumb);
  }

  g_free (title);
  g_free (url);
  g_free (desc);
  g_free (date);
  g_free (mime);
  g_free (thumb);

  return media;
}
示例#11
0
static void
add_model (MexTrackerPlugin *self,
           GrlMediaPlugin *plugin,
           MexTrackerCategory category)
{
  GList *metadata_keys, *query_keys;
  MexFeed *feed, *dir_feed;
  GrlMedia *box;
  gchar *query, *cat_name;
  GHashTable *models;
  const gchar *source_name = grl_metadata_source_get_name (GRL_METADATA_SOURCE (plugin));
  gint priority;

  switch (category)
    {
    case MEX_TRACKER_CATEGORY_IMAGE:
      cat_name = "pictures";
      query = "?urn a nfo:FileDataObject . "
              "?urn tracker:available true . "
              "FILTER (fn:starts-with(nie:mimeType(?urn),'image/'))";
      models = self->priv->image_models;
      metadata_keys = self->priv->image_keys;
      query_keys = self->priv->query_image_keys;
      box = grl_media_image_new ();
      break;

    case MEX_TRACKER_CATEGORY_VIDEO:
      cat_name = "videos";
      query = "?urn a nfo:FileDataObject . "
              "?urn tracker:available true . "
              "FILTER (fn:starts-with(nie:mimeType(?urn),'video/'))";
      models = self->priv->video_models;
      metadata_keys = self->priv->video_keys;
      query_keys = self->priv->query_video_keys;
      box = grl_media_video_new ();
      break;

    case MEX_TRACKER_CATEGORY_MUSIC:
      cat_name = "music";
      query = "?urn a nfo:FileDataObject . "
              "?urn tracker:available true . "
              "FILTER (fn:starts-with(nie:mimeType(?urn),'audio/'))";
      models = self->priv->music_models;
      metadata_keys = self->priv->music_keys;
      query_keys = self->priv->query_music_keys;
      box = grl_media_audio_new ();
      break;
    }

  grl_media_set_id (GRL_MEDIA (box), NULL);
  feed = mex_grilo_tracker_feed_new (GRL_MEDIA_SOURCE (plugin),
                                     query_keys,
                                     metadata_keys,
                                     NULL, box);
  mex_model_set_sort_func (MEX_MODEL (feed),
                           mex_model_sort_time_cb,
                           GINT_TO_POINTER (TRUE));
  mex_grilo_feed_query (MEX_GRILO_FEED (feed), query, 0, MAX_TRACKER_RESULTS);

  g_hash_table_insert (models, plugin, feed);

  /* set the local files source to appear first */
  if (!g_strcmp0 (source_name, "Local files"))
    priority = -100;
  else
    priority = 0;

  dir_feed = mex_grilo_tracker_feed_new (GRL_MEDIA_SOURCE (plugin),
                                         query_keys,
                                         metadata_keys,
                                         query, NULL);
  mex_model_set_sort_func (MEX_MODEL (dir_feed),
                           mex_model_sort_alpha_cb,
                           GINT_TO_POINTER (FALSE));
  mex_grilo_feed_browse (MEX_GRILO_FEED (dir_feed), 0, G_MAXINT);

  g_object_set (G_OBJECT (feed),
                "category", cat_name,
                "priority", priority,
                "alt-model", dir_feed,
                "alt-model-string", _("Show Folders"),
                NULL);

  mex_model_manager_add_model (self->priv->manager, MEX_MODEL (feed));
}