Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
 public void Close()
 {
     if (!_isDisposed)
     {
         var payload = new JsonObject();
         payload.Add("session_id", Id);
         Tmdb.Invoke("/authentication/session", null, payload, httpMethod: "DELETE");
     }
     _isDisposed = true;
 }
Ejemplo n.º 4
0
 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)));
 }
Ejemplo n.º 5
0
        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);
                }
            }
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
        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)));
        }
Ejemplo n.º 8
0
        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)));
        }
Ejemplo n.º 9
0
        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)));
        }
Ejemplo n.º 10
0
        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)));
        }
Ejemplo n.º 11
0
 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;
     }
 }
Ejemplo n.º 12
0
        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);
                }
            }
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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>)));
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
        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);
                }
            }
        }
Ejemplo n.º 17
0
        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)));
        }
Ejemplo n.º 18
0
        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);
                }
            }
        }
Ejemplo n.º 19
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 20
0
        // 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);
        }
Ejemplo n.º 21
0
        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;
            }
                                                   ));
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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");
            }
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        // 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);
        }
Ejemplo n.º 26
0
        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);
        }