static void
browse_cb (GrlSource *source,
           guint browse_id,
           GrlMedia *media,
           guint remaining,
           gpointer user_data,
           const GError *error)
{
  GHashTable *prop_table;
  GriloMs2Data *grdata = (GriloMs2Data *) user_data;
  gboolean add_media = FALSE;

  if (error) {
    grdata->error = g_error_copy (error);
    grdata->updated = TRUE;
    return;
  }

  if (media) {
    if ((grdata->list_type == LIST_ITEMS && !grl_media_is_container (media)) ||
        (grdata->list_type == LIST_CONTAINERS && grl_media_is_container (media))) {
      if (grdata->offset == 0) {
        add_media = TRUE;
      } else {
        grdata->offset--;
      }
    } else if (grdata->list_type == LIST_ALL) {
      add_media = TRUE;
    }
  }

  if (add_media) {
    if (grdata->parent_id) {
      grl_media_set_grilo_ms2_parent (media,
                                      grdata->parent_id);
    }
    prop_table = ms2_server_new_properties_hashtable ();
    fill_properties_table (grdata->server,
                           prop_table,
                           grdata->keys,
                           media);
    fill_other_properties_table (grdata->server,
                                 source,
                                 prop_table,
                                 grdata->other_keys,
                                 media);
    grdata->children = g_list_prepend (grdata->children, prop_table);
    grl_operation_options_set_count (grdata->options,
                                     grl_operation_options_get_count (grdata->options) -1);
  }

  if (!remaining) {
    grdata->children = g_list_reverse (grdata->children);
    grdata->updated = TRUE;
  } else if (grl_operation_options_get_count (grdata->options) == 0) {
    grl_operation_cancel (grdata->operation_id);
  }
}
예제 #2
0
static void
grl_bookmarks_source_query (GrlSource *source,
                            GrlSourceQuerySpec *qs)
{
  GRL_DEBUG ("grl_bookmarks_source_query");

  GrlBookmarksSource *bookmarks_source;
  OperationSpec *os;
  GError *error = NULL;

  bookmarks_source = GRL_BOOKMARKS_SOURCE (source);
  if (!bookmarks_source->priv->adapter) {
    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"));
    qs->callback (qs->source, qs->operation_id, NULL, 0, qs->user_data, error);
    g_error_free (error);
  }

  os = g_slice_new0 (OperationSpec);
  os->source = qs->source;
  os->operation_id = qs->operation_id;
  os->count = grl_operation_options_get_count (qs->options);
  os->skip = grl_operation_options_get_skip (qs->options);
  os->type_filter = grl_operation_options_get_type_filter (qs->options);
  os->callback = qs->callback;
  os->user_data = qs->user_data;
  os->error_code = GRL_CORE_ERROR_SEARCH_FAILED;
  produce_bookmarks_from_query (os, qs->query);
}
예제 #3
0
static void
grl_bookmarks_source_browse (GrlSource *source,
                             GrlSourceBrowseSpec *bs)
{
  GRL_DEBUG ("grl_bookmarks_source_browse");

  OperationSpec *os;
  GrlBookmarksSource *bookmarks_source;
  GError *error = NULL;

  bookmarks_source = GRL_BOOKMARKS_SOURCE (source);
  if (!bookmarks_source->priv->adapter) {
    GRL_WARNING ("Can't execute operation: no database connection.");
    error = g_error_new_literal (GRL_CORE_ERROR,
                                 GRL_CORE_ERROR_BROWSE_FAILED,
                                 _("No database connection"));
    bs->callback (bs->source, bs->operation_id, NULL, 0, bs->user_data, error);
    g_error_free (error);
  }

  /* Configure browse operation */
  os = g_slice_new0 (OperationSpec);
  os->source = bs->source;
  os->operation_id = bs->operation_id;
  os->media_id = grl_media_get_id (bs->container);
  os->count = grl_operation_options_get_count (bs->options);
  os->skip = grl_operation_options_get_skip (bs->options);
  os->type_filter = grl_operation_options_get_type_filter (bs->options);
  os->callback = bs->callback;
  os->user_data = bs->user_data;
  os->error_code = GRL_CORE_ERROR_BROWSE_FAILED;

  produce_bookmarks_from_category (os, os->media_id ? os->media_id : "0");
}
예제 #4
0
static void
grl_magnatune_source_browse(GrlSource *source, GrlSourceBrowseSpec *bs)
{
  OperationSpec *os = NULL;

  os = g_slice_new0(OperationSpec);
  os->source = bs->source;
  os->operation_id = bs->operation_id;
  os->container = bs->container;
  os->count = grl_operation_options_get_count(bs->options);
  os->skip = grl_operation_options_get_skip(bs->options);
  os->callback = bs->callback;
  os->user_data = bs->user_data;
  os->error_code = GRL_CORE_ERROR_BROWSE_FAILED;
  os->magnatune_cb = NULL;

  if (GRL_MAGNATUNE_SOURCE(source)->priv->db == NULL) {
    /* Get database first, then execute the browse */
    os->magnatune_cb = magnatune_execute_browse;
    magnatune_get_crc_async();
    magnatune_get_db_async(os);
  } else {
    magnatune_execute_browse(os);
    magnatune_check_update();
  }
}
예제 #5
0
static void
grl_magnatune_source_search(GrlSource *source, GrlSourceSearchSpec *ss)
{
  OperationSpec *os = NULL;

  os = g_slice_new0(OperationSpec);
  os->source = ss->source;
  os->operation_id = ss->operation_id;
  os->text = (ss->text == NULL) ? "": ss->text;
  os->count = grl_operation_options_get_count(ss->options);
  os->skip = grl_operation_options_get_skip(ss->options);
  os->callback = ss->callback;
  os->user_data = ss->user_data;
  os->error_code = GRL_CORE_ERROR_SEARCH_FAILED;
  os->magnatune_cb = NULL;

  if (GRL_MAGNATUNE_SOURCE(source)->priv->db == NULL) {
    /* Get database first, then execute the search */
    os->magnatune_cb = magnatune_execute_search;
    magnatune_get_crc_async();
    magnatune_get_db_async(os);
  } else {
    magnatune_execute_search(os);
    magnatune_check_update();
  }
}
예제 #6
0
static void
grl_raitv_source_browse (GrlSource *source,
                         GrlSourceBrowseSpec *bs)
{
  RaitvOperation *op = g_slice_new0 (RaitvOperation);

  const gchar *container_id;
  GRL_DEBUG ("%s: %s", __FUNCTION__, grl_media_get_id (bs->container));
  container_id = grl_media_get_id (bs->container);

  op->source       = g_object_ref (source);
  op->cancellable  = g_cancellable_new ();
  op->length        = grl_operation_options_get_count (bs->options);
  op->operation_id = bs->operation_id;
  op->container_id = container_id;
  op->callback     = bs->callback;
  op->user_data    = bs->user_data;
  op->skip	   = grl_operation_options_get_skip (bs->options);
  op->count	   = op->length;
  op->offset       = 0;

  grl_operation_set_data_full (bs->operation_id, op, (GDestroyNotify) raitv_operation_free);

  RaitvMediaType type = classify_media_id (container_id);
  switch (type)
    {
    case RAITV_MEDIA_TYPE_ROOT:
      produce_from_directory (root_dir, root_dir_size, op, type);
      break;
    case RAITV_MEDIA_TYPE_POPULARS:
      produce_from_directory (themes_dir,
                              root_dir[ROOT_DIR_POPULARS_INDEX].count, op, RAITV_MEDIA_TYPE_POPULAR_THEME);
      break;
    case RAITV_MEDIA_TYPE_RECENTS:
      produce_from_directory (themes_dir,
                              root_dir[ROOT_DIR_RECENTS_INDEX].count, op, RAITV_MEDIA_TYPE_RECENT_THEME);
      break;
    case RAITV_MEDIA_TYPE_POPULAR_THEME:
      produce_from_popular_theme (op);
      break;
    case RAITV_MEDIA_TYPE_RECENT_THEME:
      produce_from_recent_theme (op);
      break;
    case RAITV_MEDIA_TYPE_VIDEO:
    default:
      g_assert_not_reached ();
      break;
    }

}
예제 #7
0
static void
grl_bliptv_source_search (GrlSource *source,
                          GrlSourceSearchSpec *ss)
{
  BliptvOperation *op = g_slice_new0 (BliptvOperation);
  gchar *url;
  gint count = grl_operation_options_get_count (ss->options);
  guint page_number;
  guint page_offset;

  grl_paging_translate (grl_operation_options_get_skip (ss->options),
                        count,
                        MAX_ELEMENTS,
                        NULL,
                        &page_number,
                        &page_offset);

  op->source       = g_object_ref (source);
  op->cancellable  = g_cancellable_new ();
  op->count        = count;
  op->skip         = page_offset;
  op->page         = page_number;
  op->url          = g_strdup_printf (BLIPTV_SEARCH, ss->text);
  op->operation_id = ss->operation_id;
  op->callback     = ss->callback;
  op->user_data    = ss->user_data;


  grl_operation_set_data_full (ss->operation_id, op, (GDestroyNotify) bliptv_operation_free);

  url = g_strdup_printf (op->url, page_number);

  GRL_DEBUG ("Starting search request for id=%u : '%s'",
             ss->operation_id, ss->text);

  grl_net_wc_request_async (GRL_BLIPTV_SOURCE (source)->priv->wc,
                            url,
                            op->cancellable,
                            call_raw_async_cb,
                            op);
  g_free (url);
}
예제 #8
0
static void
grl_raitv_source_search (GrlSource *source,
                         GrlSourceSearchSpec *ss)
{
  RaitvOperation *op = g_slice_new0 (RaitvOperation);

  op->source       = g_object_ref (source);
  op->cancellable  = g_cancellable_new ();
  op->length        = grl_operation_options_get_count (ss->options);
  op->operation_id = ss->operation_id;
  op->callback     = ss->callback;
  op->user_data    = ss->user_data;
  op->skip	   = grl_operation_options_get_skip (ss->options);
  op->count	   = op->length;
  op->offset       = 0;
  op->text	   = ss->text;

  grl_operation_set_data_full (ss->operation_id, op, (GDestroyNotify) raitv_operation_free);

  g_raitv_videos_search(op);
}
예제 #9
0
static void
grl_vimeo_source_search (GrlSource *source,
                         GrlSourceSearchSpec *ss)
{
  SearchData *sd;
  GError *error;
  gint per_page;
  GVimeo *vimeo = GRL_VIMEO_SOURCE (source)->priv->vimeo;
  guint skip = grl_operation_options_get_skip (ss->options);
  gint count = grl_operation_options_get_count (ss->options);

  if (!ss->text) {
    /* Vimeo does not support searching all */
    error = g_error_new (GRL_CORE_ERROR,
                         GRL_CORE_ERROR_SEARCH_NULL_UNSUPPORTED,
                         _("Failed to search: %s"),
                         _("non-NULL search text is required"));
    ss->callback (ss->source, ss->operation_id, NULL, 0, ss->user_data, error);
    g_error_free (error);
    return;
  }

  sd = g_slice_new0 (SearchData);
  sd->vimeo = vimeo;
  sd->get_url = (g_list_find (ss->keys,
                              GRLKEYID_TO_POINTER (GRL_METADATA_KEY_URL)) != NULL);

  /* Compute items per page and page offset */
  grl_paging_translate (skip,
                        count,
                        MAX_ELEMENTS,
                        (guint *) &per_page,
                        (guint *) &(sd->page),
                        (guint *) &(sd->offset));

  g_vimeo_set_per_page (vimeo, per_page);
  sd->ss = ss;

  g_vimeo_videos_search (vimeo, ss->text, sd->page, search_cb, sd);
}
예제 #10
0
static void
grl_dpap_source_browse (GrlSource *source,
                        GrlSourceBrowseSpec *bs)
{
  GrlDpapSource *dmap_source = GRL_DPAP_SOURCE (source);
  gchar *url = grl_dmap_build_url (dmap_source->priv->service);

  GRL_DEBUG (__func__);

  ResultCbAndArgsAndDb *cb_and_db;

  cb_and_db = g_new (ResultCbAndArgsAndDb, 1);

  cb_and_db->cb.callback       = bs->callback;
  cb_and_db->cb.source         = bs->source;
  cb_and_db->cb.container      = bs->container;
  cb_and_db->cb.op_id          = bs->operation_id;
  cb_and_db->cb.skip           = grl_operation_options_get_skip (bs->options);
  cb_and_db->cb.count          = grl_operation_options_get_count (bs->options);
  cb_and_db->cb.user_data      = bs->user_data;

  if ((cb_and_db->db = g_hash_table_lookup (connections, url))) {
    /* Just call directly; already connected, already populated database. */
    browse_connected_cb (NULL, TRUE, NULL, cb_and_db);
  } else {
    /* Connect */
    cb_and_db->db = DMAP_DB (grl_dpap_db_new ());

    grl_dpap_connect (dmap_source->priv->service->name,
                      dmap_source->priv->service->host,
                      dmap_source->priv->service->port,
                      cb_and_db,
                      (DMAPConnectionCallback) browse_connected_cb);

    g_hash_table_insert (connections, g_strdup (url), cb_and_db->db);
  }

  g_free (url);
}
예제 #11
0
static void
search_cb (GVimeo *vimeo, GList *video_list, gpointer user_data)
{
  GrlMedia *media = NULL;
  AddMediaUrlData *amud;
  SearchData *sd = (SearchData *) user_data;
  gint count = grl_operation_options_get_count (sd->ss->options);
  gint id;
  gchar *media_type;
  gint video_list_size;

  /* Go to offset element */
  video_list = g_list_nth (video_list, sd->offset);

  /* No more elements can be sent */
  if (!video_list) {
    sd->ss->callback (sd->ss->source,
                      sd->ss->operation_id,
                      NULL,
                      0,
                      sd->ss->user_data,
                      NULL);
    g_slice_free (SearchData, sd);
    return;
  }

  video_list_size = g_list_length (video_list);
  if (count > video_list_size) {
    count = video_list_size;
  }

  if (sd->get_url) {
    sd->queue = g_queue_new ();
  }

  while (video_list && count)
  {
    media_type = g_hash_table_lookup (video_list->data, "title");
    if (media_type) {
      media = grl_media_video_new ();
    } else {
      media = NULL;
    }

    if (media)
    {
      update_media (media, video_list->data);
      if (sd->get_url) {
        amud = g_slice_new (AddMediaUrlData);
        amud->computed = FALSE;
        amud->media = media;
        amud->index = --count;
        amud->sd = sd;
        g_queue_push_head (sd->queue, amud);
        id = (gint) g_ascii_strtod (grl_media_get_id (media), NULL);
        g_vimeo_video_get_play_url (sd->vimeo,
                                    id,
                                    add_url_media_cb,
                                    amud);
      } else {
        sd->ss->callback (sd->ss->source,
                          sd->ss->operation_id,
                          media,
                          --count,
                          sd->ss->user_data,
                          NULL);
      }
    }
    video_list = g_list_next (video_list);
  }

  if (!sd->get_url) {
    g_slice_free (SearchData, sd);
  }
}
예제 #12
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);
  }
}