예제 #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);
            }
        }
        private ICollection <XbmcTvEpisode> getTvEpisodes(int tvshowId, int season, int start, int end, params string[] fields)
        {
            this.client.LogMessage("XbmcVideoLibrary.GetTvEpisodes()");

            if (tvshowId < 0)
            {
                throw new ArgumentException("Invalid TvShow Id (" + tvshowId + ")");
            }
            if (season < 0)
            {
                throw new ArgumentException("Invalid Season (" + season + ")");
            }

            JObject args = new JObject();

            args.Add(new JProperty("tvshowid", tvshowId));
            args.Add(new JProperty("season", season));
            if (fields != null && fields.Length > 0)
            {
                string[] fieldCopy = new string[fields.Length + 5];
                fieldCopy[0] = "episodeid";
                fieldCopy[0] = "title";
                fieldCopy[1] = "season";
                fieldCopy[1] = "episode";
                fieldCopy[2] = "showtitle";
                Array.Copy(fields, 0, fieldCopy, 5, fields.Length);
                args.Add(new JProperty("fields", fieldCopy));
            }
            else
            {
                args.Add(new JProperty("fields", XbmcTvEpisode.Fields));
            }
            if (start >= 0)
            {
                args.Add(new JProperty("start", start));
            }
            if (end >= 0)
            {
                args.Add(new JProperty("end", end));
            }

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

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

                return(null);
            }

            List <XbmcTvEpisode> episodes = new List <XbmcTvEpisode>();

            foreach (JObject item in (JArray)query["episodes"])
            {
                episodes.Add(XbmcTvEpisode.FromJson(item));
            }

            return(episodes);
        }
예제 #3
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);
            }
        }
예제 #4
0
        public ICollection <XbmcTvEpisode> GetRecentlyAddedTvEpisodes(int start, int end, params string[] fields)
        {
            this.client.LogMessage("XbmcVideoLibrary.GetRecentlyAddedTvEpisodes()");

            JObject args = new JObject();

            if (fields != null && fields.Length > 0)
            {
                string[] fieldCopy = new string[fields.Length + 5];
                //fieldCopy[0] = "episodeid";
                //fieldCopy[0] = "title";
                //fieldCopy[1] = "season";
                //fieldCopy[1] = "episode";
                //fieldCopy[2] = "showtitle";
                fieldCopy[0] = "id";
                fieldCopy[1] = "title";
                fieldCopy[2] = "season";
                fieldCopy[3] = "episode";
                fieldCopy[4] = "showtitle";
                Array.Copy(fields, 0, fieldCopy, 5, fields.Length);
                args.Add(new JProperty("fields", fieldCopy));
            }
            else
            {
                args.Add(new JProperty("fields", XbmcTvEpisode.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.GetRecentlyAddedEpisodes", args) as JObject;

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

                return(null);
            }

            List <XbmcTvEpisode> episodes = new List <XbmcTvEpisode>();

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

            return(episodes);
        }
예제 #5
0
        public bool Play(XbmcTvEpisode episode)
        {
            this.client.LogMessage("XbmcGeneral.Play(episode)");

            if (episode == null)
            {
                throw new ArgumentNullException("episode");
            }
            if (episode.Id < 0)
            {
                throw new ArgumentException("Invalid episode ID");
            }

            JObject args = new JObject();

            args.Add(new JProperty("episodeid", episode.Id));

            return(this.client.Call("XBMC.Play", args) != null);
        }
예제 #6
0
        private static List<string> buildTvEpisodeInfo(ICollection<string> patterns, XbmcTvEpisode episode)
        {
            Dictionary<string, string> data = new Dictionary<string, string>(12);
            data.Add("title", episode.Title);
            data.Add("episode", episode.Episodes.ToString());
            data.Add("season", episode.Season.ToString());
            data.Add("show", episode.ShowTitle);
            data.Add("year", episode.Year.ToString());
            data.Add("rating", episode.Rating.ToString("0.#"));
            data.Add("duration", episode.Duration.TotalMinutes.ToString("0"));
            data.Add("mpaa", episode.Mpaa);
            data.Add("studio", episode.Studio);
            data.Add("director", episode.Director);
            data.Add("writer", episode.Writer);
            data.Add("plot", episode.Plot);

            return buildInfoText(patterns, data);
        }
예제 #7
0
        public bool Play(XbmcTvEpisode episode)
        {
            this.client.LogMessage("XbmcGeneral.Play(episode)");

            if (episode == null)
            {
                throw new ArgumentNullException("episode");
            }
            if (episode.Id < 0)
            {
                throw new ArgumentException("Invalid episode ID");
            }

            JObject args = new JObject();
            args.Add(new JProperty("episodeid", episode.Id));

            return (this.client.Call("XBMC.Play", args) != null);
        }