Example #1
0
static GrlMedia *
build_media(gint track_id,
            const gchar *artist_name,
            const gchar *album_name,
            const gchar *track_name,
            gint track_number,
            gint duration,
            const gchar *url_to_mp3)
{
  GrlMedia *media = NULL;
  GrlMediaAudio *audio = NULL;
  gchar *str_track_id = NULL;

  media = grl_media_audio_new();
  audio = GRL_MEDIA_AUDIO(media);
  grl_media_audio_set_track_number(audio, track_number);
  grl_media_audio_set_artist(audio, artist_name);
  grl_media_audio_set_album(audio, album_name);

  grl_media_set_url(media, url_to_mp3);
  grl_media_set_duration(media, duration);
  grl_media_set_title(media, track_name);

  str_track_id = g_strdup_printf("%d", track_id);
  grl_media_set_id(media, str_track_id);
  g_free(str_track_id);

  return media;
}
Example #2
0
static void
add_url_media_cb (const gchar *url, gpointer user_data)
{
  AddMediaUrlData *amud = (AddMediaUrlData *) user_data;
  SearchData *sd = amud->sd;

  if (url) {
    grl_media_set_url (amud->media, url);
  }

  amud->computed = TRUE;

  /* Try to send in order all the processed elements */
  while ((amud = g_queue_peek_tail (sd->queue)) &&
         amud != NULL &&
         amud->computed) {
    sd->ss->callback (sd->ss->source,
                      sd->ss->operation_id,
                      amud->media,
                      amud->index,
                      sd->ss->user_data,
                      NULL);
    g_queue_pop_tail (sd->queue);
    g_slice_free (AddMediaUrlData, amud);
  }

  /* If there are still elements not processed let's wait for them */
  if (amud == NULL) {
    g_queue_free (sd->queue);
    g_slice_free (SearchData, sd);
  }
}
static void
parsed_finished (TotemPlParser *pl, GAsyncResult *result, BrowseData *data)
{
  TotemPlParserResult retval;
  GError *error = NULL;

  retval = totem_pl_parser_parse_finish (TOTEM_PL_PARSER (pl), result, &error);

  /* Do the fallback ourselves */
  if (retval == TOTEM_PL_PARSER_RESULT_IGNORED) {
    grl_media_set_url (data->media, grl_media_get_id (data->media));
    retval = TOTEM_PL_PARSER_RESULT_SUCCESS;
  }

  if (retval == TOTEM_PL_PARSER_RESULT_SUCCESS &&
      grl_media_get_url (data->media) != NULL) {
    data->bs->callback (data->bs->source,
                        data->bs->operation_id,
                        data->media,
                        -1,
                        data->bs->user_data,
                        NULL);
  } else {
    if (retval == TOTEM_PL_PARSER_RESULT_ERROR) {
      GRL_WARNING ("Failed to parse '%s': %s",
                   grl_media_get_id (data->media),
                   error->message);
      g_error_free (error);
    }
    g_object_unref (data->media);
  }
  data->media = NULL;

  resolve_disc_urls (data);
}
Example #4
0
static GrlMedia *
build_media(gint track_id,
            const gchar *artist_name,
            const gchar *album_name,
            const gchar *track_name,
            gint track_number,
            gint duration,
            const gchar *url_to_mp3,
            GPtrArray *url_to_covers)
{
  GrlMedia *media = NULL;
  gchar *str_track_id = NULL;

  media = grl_media_audio_new();
  grl_media_set_track_number(media, track_number);
  grl_media_set_artist(media, artist_name);
  grl_media_set_album(media, album_name);
  grl_media_set_url(media, url_to_mp3);
  grl_media_set_duration(media, duration);
  grl_media_set_title(media, track_name);

  g_ptr_array_foreach(url_to_covers, add_cover, media);

  str_track_id = g_strdup_printf("%d", track_id);
  grl_media_set_id(media, str_track_id);
  g_free(str_track_id);

  return media;
}
Example #5
0
static void
video_get_play_url_cb (const gchar *url, gpointer user_data)
{
  GrlSourceResolveSpec *rs = (GrlSourceResolveSpec *) user_data;

  if (url) {
    grl_media_set_url (rs->media, url);
  }

  rs->callback (rs->source, rs->operation_id, rs->media, rs->user_data, NULL);
}
static void
entry_parsed_cb (TotemPlParser *parser,
                 const char    *uri,
                 GHashTable    *metadata,
                 BrowseData    *data)
{
  g_return_if_fail (data->media != NULL);
  if (grl_media_get_url (data->media) != NULL) {
    GRL_WARNING ("Was going to set media '%s' to URL '%s' but already has URL '%s'",
                 grl_media_get_id (data->media),
                 uri,
                 grl_media_get_url (data->media));
    return;
  }

  grl_media_set_url (data->media, uri);
}
static void
parsed_finished (TotemPlParser *pl, GAsyncResult *result, BrowseData *data)
{
  TotemPlParserResult retval;
  GError *error = NULL;

  retval = totem_pl_parser_parse_finish (TOTEM_PL_PARSER (pl), result, &error);

  /* Do the fallback ourselves */
  if (retval == TOTEM_PL_PARSER_RESULT_IGNORED) {
    GRL_DEBUG ("%s: Falling back for %s as has it's been ignored", __FUNCTION__,
               grl_media_get_id (data->media));
    grl_media_set_url (data->media, grl_media_get_id (data->media));
    retval = TOTEM_PL_PARSER_RESULT_SUCCESS;
  }

  if (retval == TOTEM_PL_PARSER_RESULT_SUCCESS &&
      grl_media_get_url (data->media) != NULL) {
    GrlOpticalMediaSource *source;

    source = GRL_OPTICAL_MEDIA_SOURCE (data->bs->source);

    GRL_DEBUG ("%s: Adding %s which resolved to %s", __FUNCTION__,
               grl_media_get_id (data->media),
               grl_media_get_url (data->media));
    data->bs->callback (GRL_SOURCE (source),
                        data->bs->operation_id,
                        data->media,
                        -1,
                        data->bs->user_data,
                        NULL);
    source->priv->list = g_list_append (source->priv->list, g_object_ref (data->media));
  } else {
    if (retval == TOTEM_PL_PARSER_RESULT_ERROR ||
        retval == TOTEM_PL_PARSER_RESULT_CANCELLED) {
      GRL_WARNING ("Failed to parse '%s': %s",
                   grl_media_get_id (data->media),
                   error ? error->message : "No reason");
      g_error_free (error);
    }
    g_object_unref (data->media);
  }
  data->media = NULL;

  resolve_disc_urls (data);
}
static void
entry_parsed_cb (TotemPlParser  *parser,
                 const char     *uri,
                 GHashTable     *metadata,
                 GrlMedia      **media)
{
  char *scheme;

  g_return_if_fail (*media != NULL);
  if (grl_media_get_url (*media) != NULL) {
    GRL_WARNING ("Was going to set media '%s' to URL '%s' but already has URL '%s'",
                 grl_media_get_id (*media),
                 uri,
                 grl_media_get_url (*media));
    return;
  }

  scheme = g_uri_parse_scheme (uri);
  if (scheme != NULL && !g_str_equal (scheme, "file"))
    grl_media_set_url (*media, uri);
  g_free (scheme);
}
static void
proxy_call_resolve_grlnet_async_cb (GObject *source_object,
                                    GAsyncResult *res,
                                    gpointer user_data)
{
  RaitvOperation     *op = (RaitvOperation *) user_data;
  xmlDocPtr           doc = NULL;
  xmlXPathContextPtr  xpath = NULL;
  GError             *wc_error = NULL;
  GError             *error = NULL;
  gchar              *content = NULL;
  gsize               length;
  gchar              *value;
  gchar              *thumbnail;
  gchar             **tokens;
  GDateTime          *date;

  GRL_DEBUG ("Response id=%u", op->operation_id);

  if (g_cancellable_is_cancelled (op->cancellable)) {
    goto finalize;
  }


  if (!grl_net_wc_request_finish (GRL_NET_WC (source_object),
                                  res,
                                  &content,
                                  &length,
                                  &wc_error)) {
    error = g_error_new (GRL_CORE_ERROR,
                         GRL_CORE_ERROR_SEARCH_FAILED,
                         _("Failed to resolve: %s"),
                         wc_error->message);

    op->resolveCb (op->source,
                   op->operation_id,
                   op->media,
                   op->user_data,
                   error);

    g_error_free (wc_error);
    g_error_free (error);

    return;
  }

  doc = xmlRecoverMemory (content, (gint) length);

  if (!doc) {
    GRL_DEBUG ("Doc failed");
    goto finalize;
  }

  xpath = xmlXPathNewContext (doc);
  if (!xpath) {
    GRL_DEBUG ("Xpath failed");
    goto finalize;
  }

  if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_URL)) {
    value = eval_xquery ("/html/head/meta[@name='videourl']", xpath);
    if (value) {
      grl_media_set_url (op->media, value);
      g_free (value);
    }
  }

  if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_TITLE)) {
    value = eval_xquery ("/html/head/meta[@name='title']", xpath);
    if (value) {
      grl_media_set_title (op->media, value);
      g_free (value);
    }
  }

  if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_PUBLICATION_DATE)) {
    value = eval_xquery ("/html/head/meta[@name='itemDate']", xpath);
    if (value) {
      tokens = g_strsplit (value, "/", -1);
      if (g_strv_length (tokens) >= 3) {
        date = g_date_time_new_local (atoi (tokens[2]), atoi (tokens[1]), atoi (tokens[0]), 0, 0, 0);
        grl_media_set_publication_date (op->media, date);
        g_date_time_unref (date);
      }
      g_strfreev (tokens);
      g_free (value);
    }
  }

  if (!grl_data_has_key (GRL_DATA (op->media), GRL_METADATA_KEY_THUMBNAIL)) {
    value = eval_xquery ("/html/head/meta[@name='vod-image']", xpath);
    if (value) {
      /* Sometimes thumbnail doesn't report a complete url */
      if (value[0] == '/') {
        thumbnail = g_strconcat ("http://www.rai.tv", value, NULL);
        g_free (value);
      } else {
        thumbnail = value;
      }

      grl_media_set_thumbnail (op->media, thumbnail);
      g_free (thumbnail);
    }
  }

 finalize:
  op->resolveCb (op->source,
                 op->operation_id,
                 op->media,
                 op->user_data,
                 NULL);

  g_clear_pointer (&xpath, xmlXPathFreeContext);
  g_clear_pointer (&doc, xmlFreeDoc);
}
Example #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;
}