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); } }
static void update_media (GrlMedia *media, GHashTable *video) { gchar *str; str = g_hash_table_lookup (video, VIMEO_VIDEO_ID); if (str) { char *external_url; grl_media_set_id (media, str); external_url = g_strdup_printf ("https://vimeo.com/%s", str); grl_media_set_external_url (media, external_url); g_free (external_url); } str = g_hash_table_lookup (video, VIMEO_VIDEO_TITLE); if (str) { grl_media_set_title (media, str); } str = g_hash_table_lookup (video, VIMEO_VIDEO_DESCRIPTION); if (str) { grl_media_set_description (media, str); } str = g_hash_table_lookup (video, VIMEO_VIDEO_DURATION); if (str) { grl_media_set_duration (media, str_to_gint (str)); } str = g_hash_table_lookup (video, VIMEO_VIDEO_OWNER_NAME); if (str) { grl_media_set_author (media, str); } str = g_hash_table_lookup (video, VIMEO_VIDEO_UPLOAD_DATE); if (str) { GDateTime *date = parse_date (str); if (date) { grl_media_set_publication_date (media, date); g_date_time_unref (date); } } str = g_hash_table_lookup (video, VIMEO_VIDEO_THUMBNAIL); if (str) { grl_media_set_thumbnail (media, str); } str = g_hash_table_lookup (video, VIMEO_VIDEO_WIDTH); if (str) { grl_media_set_width (media, str_to_gint (str)); } str = g_hash_table_lookup (video, VIMEO_VIDEO_HEIGHT); if (str) { grl_media_set_height (media, str_to_gint (str)); } }
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; }