public static TmdbCompany[] SearchCompanies(string query, int minPage, int maxPage) { var args = new JsonObject(); args.Add("query", query); return(JsonArray.ToArray( Tmdb.CollapsePagedJson( Tmdb.InvokePaged("/search/company", minPage, maxPage, args)), (d) => new TmdbCompany((IDictionary <string, object>)d))); }
public static TmdbKeyword[] SearchKeywords(string query, int minPage, int maxPage) { var args = new JsonObject(); args.Add("query", query); return(JsonArray.ToArray( Tmdb.CollapsePagedJson( Tmdb.InvokePagedLang("/search/keyword", minPage, maxPage, args)), (d) => new TmdbKeyword((IDictionary <string, object>)d))); }
public void Close() { if (!_isDisposed) { var payload = new JsonObject(); payload.Add("session_id", Id); Tmdb.Invoke("/authentication/session", null, payload, httpMethod: "DELETE"); } _isDisposed = true; }
public static TmdbMovie[] DiscoverMovies(TmdbDiscoverMoviesInfo query, int minPage, int maxPage) { if (null == query) { query = new TmdbDiscoverMoviesInfo(); } return(JsonArray.ToArray( Tmdb.CollapsePagedJson( Tmdb.InvokePagedLang("/discover/movie", minPage, maxPage, query.ToArguments())), (d) => new TmdbMovie((IDictionary <string, object>)d))); }
void _EnsureFetchedTimeZones() { var l = GetField <IList <object> >("timezones"); if (null == l) { l = Tmdb.InvokeLangEx(string.Concat("/", string.Join("/", PathIdentity), "/timezones")) as IList <object>; if (null != l) { Json.Add("timezones", l); } } }
void _EnsureFetchedPrimaryTranslations() { var l = GetField <IList <object> >("primary_translations"); if (null == l) { l = Tmdb.InvokeLangEx(string.Concat("/", string.Join("/", PathIdentity), "/primary_translations")) as IList <object>; if (null != l) { Json.Add("primary_translations", l); } } }
static TmdbMovie[] _GetMovies(string method, string region, int minPage, int maxPage) { var args = new JsonObject(); if (null != region) { args.Add("region", region); } var l = Tmdb.CollapsePagedJson( Tmdb.InvokePagedLang(string.Concat("/movie/", method), minPage, maxPage, args)); return(JsonArray.ToArray(l, (d) => new TmdbMovie((IDictionary <string, object>)d))); }
public TmdbMovie[] GetMovies(bool includeAdult = false) { // this routine does not accept a page parameter but returns the results // in paged format var args = new JsonObject(); if (includeAdult) { args.Add("include_adult", true); } return(JsonArray.ToArray( Tmdb.CollapsePagedJson(Tmdb.InvokePagedLang(string.Concat("/keyword/", Id.ToString(), "/movies"), 0, 0, args)), (d) => new TmdbMovie((IDictionary <string, object>)d))); }
public static TmdbShow[] SearchShows(string query, int minPage, int maxPage, int firstAirDateYear = 0) { var args = new JsonObject(); args.Add("query", query); if (0 < firstAirDateYear) { args.Add("first_air_date_year", firstAirDateYear); } return(JsonArray.ToArray( Tmdb.CollapsePagedJson( Tmdb.InvokePagedLang("/search/tv", minPage, maxPage, args)), (d) => new TmdbShow((IDictionary <string, object>)d))); }
public static TmdbPrimary[] GetTrending(TmdbTimeWindow window, int minPage = 0, int maxPage = 999) { string tw = "day"; switch (window) { case TmdbTimeWindow.Week: tw = "week"; break; } var l = Tmdb.CollapsePagedJson( Tmdb.InvokePaged(string.Concat("/trending/all/", tw), minPage, maxPage)); return(JsonArray.ToArray(l, (d) => _GetPrimaryTrending((IDictionary <string, object>)d))); }
protected void FetchJson(string path = null, Func <object, object> fixupResponse = null, Func <object, object> fixupError = null) { try { var json = Tmdb.Invoke(path ?? string.Join("/", PathIdentity), null, null, fixupResponse, fixupError); JsonObject.CopyTo(json, Json); } catch (JsonRpcException rex) { if (rex.ErrorCode == -39) { return; } throw; } }
void _EnsureFetchedRatedShows() { var l = GetField <IList <object> >("rated_shows"); if (null == l) { // this function does not actually accept a page parameter, but it returns the result // in paged form, so we use the paged routines with the default page (0) which does not // send a page parameter. l = Tmdb.CollapsePagedJson(Tmdb.InvokePagedLang(string.Concat("/guest_session/", Id, "/rated/tv"), 0, 0)); if (null != l) { Json.Add("rated_shows", l); } } }
public TmdbMediaAccountInfo GetAccountInfo(TmdbSession session = null) { var args = new JsonObject(); if (null == session) { args.Add("guest_session_id", Tmdb.GuestSessionId); } else { args.Add("session_id", session.Id); } var json = Tmdb.Invoke(string.Concat("/", string.Join("/", PathIdentity), "/account_states")); return(new TmdbMediaAccountInfo(json)); }
public static TmdbMovie[] GetMovieChanges(DateTime startDate = default(DateTime), DateTime endDate = default(DateTime), int minPage = 0, int maxPage = 999) { var args = new JsonObject(); if (default(DateTime) != startDate) { args.Add("start_date", startDate.ToString("yyyy-MM-dd")); } if (default(DateTime) != endDate) { args.Add("end_date", endDate.ToString("yyyy-MM-dd")); } return(JsonArray.ToArray( Tmdb.CollapsePagedJson( Tmdb.InvokePaged("/movie/changes", minPage, maxPage, args)) , (d) => new TmdbMovie(d as IDictionary <string, object>))); }
void _EnsureFetchedImages() { var l = GetField <IList <object> >("images"); if (null == l) { l = new JsonArray().Synchronize() as IList <object>; var json = Tmdb.InvokeLang(string.Concat("/", string.Join("/", PathIdentity), "/images")); var array = new JsonArray().Synchronize() as IList <object>; object o; if (json.TryGetValue("backdrops", out o)) { var ll = o as IList <object>; if (null != ll) { for (int ic = ll.Count, i = 0; i < ic; ++i) { var d = ll[i] as IDictionary <string, object>; if (null != d) { d["image_type"] = "backdrop"; l.Add(d); } } } } if (json.TryGetValue("posters", out o)) { var ll = o as IList <object>; if (null != ll) { for (int ic = ll.Count, i = 0; i < ic; ++i) { var d = ll[i] as IDictionary <string, object>; if (null != d) { d["image_type"] = "poster"; l.Add(d); } } } } Json.Add("images", l); } }
void _EnsureFetchedAlternativeNames() { var l = GetField <IList <object> >("alternative_names"); if (null == l) { var json = Tmdb.InvokeLang(string.Concat("/", string.Join("/", PathIdentity), "/alternative_names")); object o; if (json.TryGetValue("results", out o)) { l = o as IList <object>; } if (null != l) { Json.Add("alternative_names", l); } } }
public static TmdbPerson[] SearchPeople(string query, int minPage, int maxPage, string region = null, bool includeAdult = false) { var args = new JsonObject(); args.Add("query", query); if (!string.IsNullOrEmpty(region)) { args.Add("region", region); } if (includeAdult) { args.Add("include_adult", includeAdult); } return(JsonArray.ToArray( Tmdb.CollapsePagedJson( Tmdb.InvokePagedLang("/search/person", minPage, maxPage, args)), (d) => new TmdbPerson((IDictionary <string, object>)d))); }
void _EnsureFetchedReleases() { var l = GetField <IList <object> >("releases"); if (null == l) { var json = Tmdb.Invoke(string.Concat("/", string.Join("/", _ParentPathIdentity), "/release_dates")); object o; if (json.TryGetValue("results", out o)) { l = o as IList <object>; } if (null != l) { Json.Add("keywords", l); } } }
void _EnsureFetchedContentRatings() { var l = GetField <IList <object> >("content_ratings"); if (null == l) { var json = Tmdb.Invoke(string.Concat("/", string.Join("/", PathIdentity), "/alternative_titles")); object o; if (json.TryGetValue("results", out o)) { l = o as IList <object>; if (null != l) { Json["content_ratings"] = l; } } } }
// TODO: refactor this. It's a duplicate from TmdbMedia and TmdbPerson, and TmdbSeason public KeyValuePair <string, TmdbChangeAction[]>[] GetChangesGroupedByKey(int minPage, int maxPage, DateTime startDate = default(DateTime), DateTime endDate = default(DateTime)) { var args = new JsonObject(); if (default(DateTime) != startDate) { args.Add("start_date", Tmdb.DateTimeToDate(startDate)); } if (default(DateTime) != endDate) { args.Add("end_date", Tmdb.DateTimeToDate(endDate)); } var l = Tmdb.CollapsePagedJson(Tmdb.InvokeFlatPaged(string.Concat("/", string.Join("/", PathIdentity), "/changes"), minPage, maxPage, args)); if (null != l) { var result = new KeyValuePair <string, TmdbChangeAction[]> [l.Count]; for (var i = 0; i < result.Length; i++) { var ci = l[i] as IDictionary <string, object>; if (null != ci) { string key = null; TmdbChangeAction[] value; object o; if (ci.TryGetValue("key", out o)) { key = o as string; } if (ci.TryGetValue("items", out o)) { var ll = o as IList <object>; value = JsonArray.ToArray(ll, (dd) => new TmdbChangeAction((IDictionary <string, object>)dd)); result[i] = new KeyValuePair <string, TmdbChangeAction[]>(key, value); } } } return(result); } return(null); }
public static TmdbPrimary[] Search(string query, int minPage, int maxPage, string region = null, bool includeAdult = false) { var args = new JsonObject(); args.Add("query", query); if (!string.IsNullOrEmpty(region)) { args.Add("region", region); } if (includeAdult) { args.Add("includeAdult", includeAdult); } var l = Tmdb.CollapsePagedJson( Tmdb.InvokePagedLang("/search/multi", minPage, maxPage, args)); return(JsonArray.ToArray <TmdbPrimary>(l, (dd) => { var d = dd as IDictionary <string, object>; if (null != d) { object o; if (d.TryGetValue("media_type", out o)) { switch (o as string) { case "movie": return new TmdbMovie((IDictionary <string, object>)dd); case "tv": return new TmdbShow((IDictionary <string, object>)dd); case "person": return new TmdbPerson((IDictionary <string, object>)dd); } } } return null; } )); }
public void Rate(double rating, TmdbSession session = null) { if (0.5d > rating || 10d < rating) { throw new ArgumentOutOfRangeException(nameof(rating)); } var args = new JsonObject(); if (null != session) { args.Add("session_id", session.Id); } else { args.Add("guest_session_id", Tmdb.GuestSessionId); } var payload = new JsonObject(); payload.Add("value", rating); Tmdb.Invoke(string.Concat("/", string.Join("/", PathIdentity), "/rating"), args, payload); }
public void ClearMovies(string sessionId) { if (null == sessionId) { throw new ArgumentNullException(nameof(sessionId)); } if (0 == sessionId.Length) { throw new ArgumentException(nameof(sessionId) + " must not be empty.", nameof(sessionId)); } var args = new JsonObject(); args.Add("session_id", sessionId); args.Add("confirm", true); var id = GetField("id", -1); if (-1 < id) { Tmdb.Invoke(string.Concat("/list/" + id.ToString() + "/remove_item"), args, httpMethod: "POST"); } }
public TmdbMovieList CreateMovieList(string name = null, string description = null, string language = null) { _CheckDisposed(); var args = new JsonObject(); args.Add("session_id", Id); var payload = new JsonObject(); if (null != name) { payload.Add("name", name); } if (null != description) { payload.Add("description", name); } if (null != language) { payload.Add("language", name); } var d = Tmdb.Invoke(string.Concat("/list/", Id), args, payload); if (null != d) { object o; if (d.TryGetValue("list_id", out o)) { var id = o as string; if (!string.IsNullOrEmpty(id)) { // create the object to initialize the movie list with var j = new JsonObject(); j.Add("id", id); return(new TmdbMovieList(j)); } } } return(null); }
// this isn't really a great idea since it sends a web request to get one bit of info // you can get all at once using the Movies property, albeit indirectly public bool ContainsMovie(TmdbMovie movie) { var args = new JsonObject(); args.Add("movie_id", movie.Id); var id = GetField("id", -1); // optimization IDictionary <string, object> d = null; if (-1 != id) { d = Tmdb.Invoke(string.Concat("/list/", id.ToString(), "/item_status", args)); } if (null != d) { object o; if (d.TryGetValue("item_present", out o) && o is bool && (bool)o) { return(true); } } return(false); }
public bool DeleteMovieList(TmdbMovieList list) { _CheckDisposed(); if (null == list) { throw new ArgumentNullException(nameof(list)); } var args = new JsonObject(); args.Add("session_id", Id); var d = Tmdb.Invoke(string.Concat("/list/", Id), args, httpMethod: "DELETE"); if (null != d) { object o; if (d.TryGetValue("status_code", out o) && o is int && 13 == (int)o) { return(true); } } return(false); }