static htsmsg_t * tmdb_load_movie_cast(const char *lookup_id) { char url[300]; char errbuf[256]; buf_t *result; snprintf(url, sizeof(url), "http://api.themoviedb.org/3/movie/%s/casts", lookup_id); retry: tmdb_check_rate_limit(); int http_response_code = 0; struct http_header_list response_headers; LIST_INIT(&response_headers); result = fa_load(url, FA_LOAD_ERRBUF(errbuf, sizeof(errbuf)), FA_LOAD_QUERY_ARG("api_key", TMDB_APIKEY), FA_LOAD_QUERY_ARG("language", getlang()), FA_LOAD_RESPONSE_HEADERS(&response_headers), FA_LOAD_PROTOCOL_CODE(&http_response_code), FA_LOAD_FLAGS(FA_COMPRESSION), NULL); if(result == NULL) { if(http_response_code == 429) { tmdb_handle_rate_limit(&response_headers); goto retry; } http_headers_free(&response_headers); TRACE(TRACE_INFO, "TMDB", "Load error %s", errbuf); return NULL; } http_headers_free(&response_headers); htsmsg_t *doc = htsmsg_json_deserialize2(buf_cstr(result), errbuf, sizeof(errbuf)); if(doc == NULL) { TRACE(TRACE_ERROR, "TMDB", "Got bad JSON from %s -- %s", url, errbuf); } buf_release(result); return doc; }
/** * Load entire image into memory using fileaccess load method. * Faster than open+read+close. */ static image_t * fa_imageloader2(const char *url, const char **vpaths, char *errbuf, size_t errlen, int *cache_control, cancellable_t *c) { buf_t *buf; buf = fa_load(url, FA_LOAD_VPATHS(vpaths), FA_LOAD_ERRBUF(errbuf, errlen), FA_LOAD_CACHE_CONTROL(cache_control), FA_LOAD_CANCELLABLE(c), FA_LOAD_FLAGS(FA_CONTENT_ON_ERROR), NULL); if(buf == NULL || buf == NOT_MODIFIED) return (image_t *)buf; image_t *img = fa_imageloader_buf(buf, errbuf, errlen); buf_release(buf); return img; }
static int tmdb_configure(void) { hts_mutex_lock(&tmdb_mutex); if(!tmdb_configured) { buf_t *result; char errbuf[256]; result = fa_load("http://api.themoviedb.org/3/configuration", FA_LOAD_ERRBUF(errbuf, sizeof(errbuf)), FA_LOAD_QUERY_ARG("api_key", TMDB_APIKEY), FA_LOAD_QUERY_ARG("language", getlang()), FA_LOAD_FLAGS(FA_COMPRESSION | FA_IMPORTANT), NULL); if(result == NULL) { TRACE(TRACE_INFO, "TMDB", "Unable to get configuration -- %s", errbuf); goto done; } htsmsg_t *doc = htsmsg_json_deserialize2(buf_cstr(result), errbuf, sizeof(errbuf)); buf_release(result); if(doc == NULL) { TRACE(TRACE_ERROR, "TMDB", "Got bad JSON from config -- %s", errbuf); goto done; } tmdb_parse_config(doc); htsmsg_release(doc); tmdb_configured = 1; } done: hts_mutex_unlock(&tmdb_mutex); return !tmdb_configured; }
void load_site_news(void) { #if ENABLE_WEBPOPUP struct http_header_list response_headers; buf_t *b; char errbuf[512]; b = fa_load("https://movian.tv/projects/movian/news.json", FA_LOAD_FLAGS(FA_DISABLE_AUTH | FA_COMPRESSION), FA_LOAD_RESPONSE_HEADERS(&response_headers), FA_LOAD_ERRBUF(errbuf, sizeof(errbuf)), NULL); if(b == NULL) { TRACE(TRACE_DEBUG, "News", "Unable to load news -- %s", errbuf); return; } const char *dateheader = http_header_get(&response_headers, "date"); if(dateheader == NULL) { buf_release(b); http_headers_free(&response_headers); return; } dateheader = mystrdupa(dateheader); http_headers_free(&response_headers); htsmsg_t *newsinfo = htsmsg_store_load("sitenews"); time_t no_news_before; if(newsinfo == NULL) newsinfo = htsmsg_create_map(); no_news_before = htsmsg_get_u32_or_default(newsinfo, "nothingbefore", 0); if(no_news_before == 0) { if(http_ctime(&no_news_before, dateheader)) { buf_release(b); htsmsg_release(newsinfo); return; } htsmsg_add_u32(newsinfo, "nothingbefore", no_news_before); htsmsg_store_save(newsinfo, "sitenews"); htsmsg_release(newsinfo); } htsmsg_t *doc = htsmsg_json_deserialize(buf_cstr(b)); buf_release(b); if(doc == NULL) { return; } hts_mutex_lock(&news_mutex); htsmsg_t *news = htsmsg_get_list(doc, "news"); if(news != NULL) { htsmsg_field_t *f; HTSMSG_FOREACH(f, news) { htsmsg_t *entry; if((entry = htsmsg_get_map_by_field(f)) == NULL) continue; const char *title = htsmsg_get_str(entry, "title"); const char *created_on = htsmsg_get_str(entry, "created_on"); int id = htsmsg_get_u32_or_default(entry, "id", 0); if(created_on == NULL || title == NULL || id == 0) continue; time_t t; if(parse_created_on_time(&t, created_on)) continue; if(t < no_news_before) continue; char idstr[64]; snprintf(idstr, sizeof(idstr), "sitenews:%d", id); prop_t *p = add_news_locked(idstr, title, NULL, "Read more", idstr); if(p != NULL) { prop_subscribe(PROP_SUB_TRACK_DESTROY, PROP_TAG_CALLBACK, open_news, p, PROP_TAG_ROOT, prop_create(p, "eventSink"), PROP_TAG_MUTEX, &news_mutex, NULL); } }