static void set_date (TrackerSparqlCursor *cursor, gint column, GrlMedia *media, GrlKeyID key) { const gchar *str = tracker_sparql_cursor_get_string (cursor, column, NULL); if (key == GRL_METADATA_KEY_CREATION_DATE || key == GRL_METADATA_KEY_MODIFICATION_DATE) { GDateTime *date = grl_date_time_from_iso8601 (str); if (date) { grl_data_set_boxed (GRL_DATA (media), key, date); g_date_time_unref (date); } } }
static void proxy_call_browse_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; xmlXPathObjectPtr obj = NULL; gint i, nb_items = 0; gsize length; GRL_DEBUG ("Response id=%u", op->operation_id); GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; 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 browse: %s"), wc_error->message); op->callback (op->source, op->operation_id, NULL, 0, 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; } gchar* xquery=NULL; switch (classify_media_id (op->container_id)) { case RAITV_MEDIA_TYPE_POPULAR_THEME: xquery = "/CLASSIFICAVISTI/content"; break; case RAITV_MEDIA_TYPE_RECENT_THEME: xquery = "/INFORMAZIONICONTENTS/content"; break; default: goto finalize; } obj = xmlXPathEvalExpression ((xmlChar *) xquery, xpath); if (obj) { nb_items = xmlXPathNodeSetGetLength (obj->nodesetval); xmlXPathFreeObject (obj); } if (nb_items < op->count) op->count = nb_items; op->category_info->count = nb_items; for (i = 0; i < nb_items; i++) { //Skip if(op->skip>0) { op->skip--; continue; } GrlRaitvSource *source = GRL_RAITV_SOURCE (op->source); GList *mapping = source->priv->raitv_browse_mappings; GrlMedia *media = grl_media_video_new (); while (mapping) { gchar *str; gchar *strvalue; RaitvAssoc *assoc = (RaitvAssoc *) mapping->data; str = g_strdup_printf ("string(%s[%i]/%s)", xquery,i + 1, assoc->exp); obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj) { if (obj->stringval && obj->stringval[0] != '\0') { strvalue = g_strdup((gchar *) obj->stringval); //Sometimes GRL_METADATA_KEY_THUMBNAIL doesn't report complete url if(assoc->grl_key == GRL_METADATA_KEY_THUMBNAIL && !g_str_has_prefix(strvalue,"http://www.rai.tv/")) { strvalue = g_strdup_printf("http://www.rai.tv%s",obj->stringval); } GType _type; _type = grl_metadata_key_get_type (assoc->grl_key); switch (_type) { case G_TYPE_STRING: grl_data_set_string (GRL_DATA (media), assoc->grl_key, strvalue); break; case G_TYPE_INT: grl_data_set_int (GRL_DATA (media), assoc->grl_key, (gint) atoi (strvalue)); break; case G_TYPE_FLOAT: grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) atof (strvalue)); break; default: /* G_TYPE_DATE_TIME is not a constant, so this has to be * in "default:" */ if (_type == G_TYPE_DATE_TIME) { int year,month,day,hour,minute,seconds; sscanf((const char*)obj->stringval, "%02d/%02d/%04d %02d:%02d:%02d", &day, &month, &year, &hour,&minute, &seconds); GDateTime *date = g_date_time_new_local (year, month, day, hour,minute, seconds); grl_data_set_boxed (GRL_DATA (media), assoc->grl_key, date); if(date) g_date_time_unref (date); } else { GRL_DEBUG ("\tUnexpected data type: %s", g_type_name (_type)); } break; } g_free (strvalue); } xmlXPathFreeObject (obj); } g_free (str); mapping = mapping->next; } op->callback (op->source, op->operation_id, media, --op->count, op->user_data, NULL); if (op->count == 0) { break; } } finalize: g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); /* Signal the last element if it was not already signaled */ if (nb_items == 0) { op->callback (op->source, op->operation_id, NULL, 0, op->user_data, NULL); } else { //Continue the search if(op->count>0) { //Skip the ones already read op->skip += nb_items; op->offset += nb_items; switch (classify_media_id (op->container_id)) { case RAITV_MEDIA_TYPE_POPULAR_THEME: produce_from_popular_theme(op); break; case RAITV_MEDIA_TYPE_RECENT_THEME: produce_from_recent_theme(op); break; default: g_assert_not_reached (); break; } } } }
static void proxy_call_search_grlnet_async_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { RaitvOperation *op = (RaitvOperation *) user_data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; xmlXPathObjectPtr obj = NULL; gint i, nb_items = 0; gsize length; GRL_DEBUG ("Response id=%u", op->operation_id); GError *wc_error = NULL; GError *error = NULL; gchar *content = NULL; gboolean g_bVideoNotFound = TRUE; 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 search: %s"), wc_error->message); op->callback (op->source, op->operation_id, NULL, 0, op->user_data, error); g_error_free (wc_error); g_error_free (error); return; } doc = xmlParseMemory (content, (gint) length); if (!doc) { GRL_DEBUG ("Doc failed"); goto finalize; } xpath = xmlXPathNewContext (doc); if (!xpath) { GRL_DEBUG ("Xpath failed"); goto finalize; } obj = xmlXPathEvalExpression ((xmlChar *) "/GSP/RES/R", xpath); if (obj) { nb_items = xmlXPathNodeSetGetLength (obj->nodesetval); xmlXPathFreeObject (obj); } for (i = 0; i < nb_items; i++) { //Search only videos gchar *str; str = g_strdup_printf ("string(/GSP/RES/R[%i]/MT[@N='videourl']/@V)", i + 1); obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj->stringval && obj->stringval[0] == '\0') continue; if(op->skip>0) { op->skip--; continue; } GrlRaitvSource *source = GRL_RAITV_SOURCE (op->source); GList *mapping = source->priv->raitv_search_mappings; GrlMedia *media = grl_media_video_new (); g_bVideoNotFound = FALSE; GRL_DEBUG ("Mappings count: %d",g_list_length(mapping)); while (mapping) { RaitvAssoc *assoc = (RaitvAssoc *) mapping->data; str = g_strdup_printf ("string(/GSP/RES/R[%i]/%s)", i + 1, assoc->exp); GRL_DEBUG ("Xquery %s", str); gchar *strvalue; obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj) { if (obj->stringval && obj->stringval[0] != '\0') { strvalue = g_strdup((gchar *) obj->stringval); //Sometimes GRL_METADATA_KEY_THUMBNAIL doesn't report complete url if(assoc->grl_key == GRL_METADATA_KEY_THUMBNAIL && !g_str_has_prefix(strvalue,"http://www.rai.tv")) { strvalue = g_strdup_printf("http://www.rai.tv%s",obj->stringval); } GType _type; GRL_DEBUG ("\t%s -> %s", str, obj->stringval); _type = grl_metadata_key_get_type (assoc->grl_key); switch (_type) { case G_TYPE_STRING: grl_data_set_string (GRL_DATA (media), assoc->grl_key, strvalue); break; case G_TYPE_INT: grl_data_set_int (GRL_DATA (media), assoc->grl_key, (gint) atoi (strvalue)); break; case G_TYPE_FLOAT: grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) atof (strvalue)); break; default: /* G_TYPE_DATE_TIME is not a constant, so this has to be * in "default:" */ if (_type == G_TYPE_DATE_TIME) { int year,month,day; sscanf((const char*)obj->stringval, "%02d/%02d/%04d", &day, &month, &year); GDateTime *date = g_date_time_new_local (year, month, day, 0, 0, 0); GRL_DEBUG ("Setting %s to %s", grl_metadata_key_get_name (assoc->grl_key), g_date_time_format (date, "%F %H:%M:%S")); grl_data_set_boxed (GRL_DATA (media), assoc->grl_key, date); if(date) g_date_time_unref (date); } else { GRL_DEBUG ("\tUnexpected data type: %s", g_type_name (_type)); } break; } g_free (strvalue); } xmlXPathFreeObject (obj); } g_free (str); mapping = mapping->next; } op->callback (op->source, op->operation_id, media, --op->count, op->user_data, NULL); if (op->count == 0) break; } finalize: g_clear_pointer (&xpath, xmlXPathFreeContext); g_clear_pointer (&doc, xmlFreeDoc); /* Signal the last element if it was not already signaled */ if (nb_items == 0 || g_bVideoNotFound) { op->callback (op->source, op->operation_id, NULL, 0, op->user_data, NULL); } else { //Continue the search if(op->count>0) { op->offset += nb_items; g_raitv_videos_search(op); } } }
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; }
static void call_raw_async_cb (GObject * source_object, GAsyncResult *res, gpointer data) { BliptvOperation *op = (BliptvOperation *) data; xmlDocPtr doc = NULL; xmlXPathContextPtr xpath = NULL; xmlXPathObjectPtr obj = NULL; gint i, nb_items = 0; gchar *content = NULL; gchar *url; gsize length; GRL_DEBUG ("Response id=%u", op->operation_id); if (g_cancellable_is_cancelled (op->cancellable)) { goto finalize_send_last; } if (!grl_net_wc_request_finish (GRL_NET_WC (source_object), res, &content, &length, NULL)) { goto finalize_send_last; } doc = xmlParseMemory (content, (gint) length); if (!doc) goto finalize_send_last; xpath = xmlXPathNewContext (doc); if (!xpath) goto finalize_send_last; xmlXPathRegisterNs (xpath, (xmlChar *) "blip", (xmlChar *) BLIPTV_BACKEND "/dtd/blip/1.0"); xmlXPathRegisterNs (xpath, (xmlChar *) "media", (xmlChar *) "http://search.yahoo.com/mrss/"); obj = xmlXPathEvalExpression ((xmlChar *) "/rss/channel/item", xpath); if (obj) { nb_items = xmlXPathNodeSetGetLength (obj->nodesetval); xmlXPathFreeObject (obj); } if (nb_items == 0) { goto finalize_send_last; } /* Special case: when there are no results in a search, Blip.tv returns an element telling precisely that, no results found; so we need to report no results too */ if (nb_items == 1) { obj = xmlXPathEvalExpression ((xmlChar *) "string(/rss/channel/item[0]/blip:item_id)", xpath); if (!obj || !obj->stringval || obj->stringval[0] == '\0') { g_clear_pointer (&obj, (GDestroyNotify) xmlXPathFreeObject); nb_items = 0; goto finalize_send_last; } else { xmlXPathFreeObject (obj); } } for (i = op->skip; i < nb_items; i++) { GList *mapping = bliptv_mappings; GrlMedia *media = grl_media_video_new (); while (mapping) { BliptvAssoc *assoc = (BliptvAssoc *) mapping->data; gchar *str; str = g_strdup_printf ("string(/rss/channel/item[%i]/%s)", i + 1, assoc->exp); obj = xmlXPathEvalExpression ((xmlChar *) str, xpath); if (obj) { if (obj->stringval && obj->stringval[0] != '\0') { GType _type; GRL_DEBUG ("\t%s -> %s", str, obj->stringval); _type = grl_metadata_key_get_type (assoc->grl_key); switch (_type) { case G_TYPE_STRING: grl_data_set_string (GRL_DATA (media), assoc->grl_key, (gchar *) obj->stringval); break; case G_TYPE_INT: grl_data_set_int (GRL_DATA (media), assoc->grl_key, (gint) atoi ((gchar *) obj->stringval)); break; case G_TYPE_FLOAT: grl_data_set_float (GRL_DATA (media), assoc->grl_key, (gfloat) atof ((gchar *) obj->stringval)); break; default: /* G_TYPE_DATE_TIME is not a constant, so this has to be * in "default:" */ if (_type == G_TYPE_DATE_TIME) { GDateTime *date = grl_date_time_from_iso8601 ((gchar *) obj->stringval); GRL_DEBUG ("Setting %s to %s", grl_metadata_key_get_name (assoc->grl_key), g_date_time_format (date, "%F %H:%M:%S")); grl_data_set_boxed (GRL_DATA (media), assoc->grl_key, date); g_date_time_unref (date); } else { GRL_DEBUG ("\tUnexpected data type: %s", g_type_name (_type)); } break; } } xmlXPathFreeObject (obj); } g_free (str); mapping = mapping->next; } op->callback (op->source, op->operation_id, media, --op->count, op->user_data, NULL); if (op->count == 0) break; } if (op->count > 0) { /* Request next page */ op->skip = 0; url = g_strdup_printf (op->url, ++op->page); GRL_DEBUG ("Operation %d: requesting page %d", op->operation_id, op->page); grl_net_wc_request_async (GRL_BLIPTV_SOURCE (op->source)->priv->wc, url, op->cancellable, call_raw_async_cb, op); g_free (url); goto finalize_free; } finalize_send_last: /* Signal the last element if it was not already signaled */ if (nb_items == 0) { op->callback (op->source, op->operation_id, NULL, 0, op->user_data, NULL); } finalize_free: g_clear_pointer (&xpath, (GDestroyNotify) xmlXPathFreeContext); g_clear_pointer (&doc, (GDestroyNotify) xmlFreeDoc); }
static void resolve_video (ResolveData *resolve_data, GrlKeyID key, resolution_flags_t flags) { gchar *title, *showname, *display_name; GDateTime *date; gint season, episode; GrlData *data = GRL_DATA (resolve_data->rs->media); resolution_flags_t miss_flags = 0, fill_flags; GRL_DEBUG ("%s",__FUNCTION__); resolve_data_start_operation (resolve_data, "video"); if (!(flags & (FLAG_VIDEO_TITLE | FLAG_VIDEO_SHOWNAME | FLAG_VIDEO_DATE | FLAG_VIDEO_SEASON | FLAG_VIDEO_EPISODE | FLAG_VIDEO_EPISODE_TITLE))) { resolve_data_finish_operation (resolve_data, "video", NULL); return; } if (grl_data_has_key (data, GRL_METADATA_KEY_TITLE)) { if (grl_data_get_boolean (data, GRL_METADATA_KEY_TITLE_FROM_FILENAME)) { miss_flags = FLAG_VIDEO_TITLE; } else miss_flags = 0; } else { miss_flags = FLAG_VIDEO_TITLE; } miss_flags |= grl_data_has_key (data, GRL_METADATA_KEY_SHOW) ? 0 : FLAG_VIDEO_SHOWNAME; miss_flags |= grl_data_has_key (data, GRL_METADATA_KEY_PUBLICATION_DATE) ? 0 : FLAG_VIDEO_DATE; miss_flags |= grl_data_has_key (data, GRL_METADATA_KEY_SEASON) ? 0 : FLAG_VIDEO_SEASON; miss_flags |= grl_data_has_key (data, GRL_METADATA_KEY_EPISODE) ? 0 : FLAG_VIDEO_EPISODE; miss_flags |= grl_data_has_key (data, GRL_METADATA_KEY_EPISODE_TITLE) ? 0 : FLAG_VIDEO_EPISODE_TITLE; fill_flags = flags & miss_flags; if (!fill_flags) { resolve_data_finish_operation (resolve_data, "video", NULL); return; } if (key == GRL_METADATA_KEY_URL) { GFile *file; file = g_file_new_for_uri (grl_media_get_url (resolve_data->rs->media)); display_name = g_file_get_basename (file); g_object_unref (file); } else { display_name = g_strdup (grl_media_get_title (resolve_data->rs->media)); } video_guess_values_from_display_name (display_name, &title, &showname, &date, &season, &episode); g_free (display_name); GRL_DEBUG ("\tfound title=%s/showname=%s/year=%i/season=%i/episode=%i", title, showname, date != NULL ? g_date_time_get_year (date) : 0, season, episode); if (showname) { if (fill_flags & FLAG_VIDEO_SHOWNAME) { grl_data_set_string (data, GRL_METADATA_KEY_SHOW, showname); } g_free (showname); if (fill_flags & FLAG_VIDEO_EPISODE_TITLE && title != NULL) { grl_data_set_string (data, GRL_METADATA_KEY_EPISODE_TITLE, title); } } else { /* As this is just a guess, don't erase already provided values, * unless GRL_METADATA_KEY_TITLE_FROM_FILENAME is set */ if (grl_data_get_boolean (data, GRL_METADATA_KEY_TITLE_FROM_FILENAME)) { if (fill_flags & FLAG_VIDEO_TITLE) { grl_data_set_string (data, GRL_METADATA_KEY_TITLE, title); } } } g_free (title); if (date) { if (fill_flags & FLAG_VIDEO_DATE) { grl_data_set_boxed (data, GRL_METADATA_KEY_PUBLICATION_DATE, date); } g_date_time_unref (date); } if (season && (fill_flags & FLAG_VIDEO_SEASON)) { grl_data_set_int (data, GRL_METADATA_KEY_SEASON, season); } if (episode && (fill_flags & FLAG_VIDEO_EPISODE)) { grl_data_set_int (data, GRL_METADATA_KEY_EPISODE, episode); } resolve_data_finish_operation (resolve_data, "video", NULL); }