Example #1
0
        internal static XbmcVideo FromJson(JObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            try
            {
                // If there is a showtitle field and it has a value, the retrieved item is a XbmcTvEpisode
                if (obj["showtitle"] != null && !string.IsNullOrEmpty(JsonRpcClient.GetField <string>(obj, "showtitle")))
                {
                    return(XbmcTvEpisode.FromJson(obj));
                }
                // If there is a artist field and it has a vaue, the retrieved item is a XbmcMusicVideo
                if (obj["artist"] != null && !string.IsNullOrEmpty(JsonRpcClient.GetField <string>(obj, "artist")))
                {
                    return(XbmcMusicVideo.FromJson(obj));
                }

                // Otherwise it must be a movie
                return(XbmcMovie.FromJson(obj));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #2
0
        internal static XbmcVideo FromJson(JObject obj, JsonRpcClient logger)
        {
            if (obj == null)
            {
                return(null);
            }

            try
            {
                string type;
                if (obj["type"] == null)
                {
                    type = "unknown";
                }
                else
                {
                    type = JsonRpcClient.GetField <string>(obj, "type");
                }
                if (logger != null)
                {
                    logger.LogMessage("Trying to identify " + type);
                }

                if ("episode" == type)
                {
                    return(XbmcTvEpisode.FromJson(obj, logger));
                }

                if ("musicvideo" == type)
                {
                    return(XbmcMusicVideo.FromJson(obj, logger));
                }

                if ("movie" == type)
                {
                    return(XbmcMovie.FromJson(obj, logger));
                }

                // Otherwise try a movie
                //else if ()
                //{
                if (logger != null)
                {
                    logger.LogMessage("Trying to identify Unhandled type of media as movie");
                }
                return(XbmcMovie.FromJson(obj, logger));
                //}
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.LogErrorMessage("EXCEPTION in XbmcVideo.FromJson()!!!", ex);
                }
                return(null);
            }
        }
Example #3
0
        public ICollection <XbmcMovie> GetRecentlyAddedMovies(int start, int end, params string[] fields)
        {
            this.client.LogMessage("XbmcVideoLibrary.GetRecentlyAddedMovies()");

            JObject args = new JObject();

            if (fields != null && fields.Length > 0)
            {
                string[] fieldCopy = new string[fields.Length + 2];
                fieldCopy[0] = "movieid";
                fieldCopy[1] = "title";
                Array.Copy(fields, 0, fieldCopy, 2, fields.Length);
                args.Add(new JProperty("fields", fieldCopy));
            }
            else
            {
                args.Add(new JProperty("fields", XbmcMovie.Fields));
            }
            JObject limits = new JObject();

            if (start >= 0)
            {
                limits.Add(new JProperty("start", start));
            }
            if (end >= 0)
            {
                limits.Add(new JProperty("end", end));
            }
            args.Add(new JProperty("limits", limits));

            JObject query = this.client.Call("VideoLibrary.GetRecentlyAddedMovies", args) as JObject;

            if (query == null || query["movies"] == null)
            {
                this.client.LogErrorMessage("VideoLibrary.GetRecentlyAddedMovies(): Invalid response");

                return(null);
            }

            List <XbmcMovie> movies = new List <XbmcMovie>();

            foreach (JObject item in (JArray)query["movies"])
            {
                movies.Add(XbmcMovie.FromJson(item, this.client));
            }

            return(movies);
        }