Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
        private ICollection <XbmcMusicVideo> GetMusicVideos(int artistId, int albumId, int start, int end, params string[] fields)
        {
            this.client.LogMessage("XbmcVideoLibrary.GetMusicVideos()");

            JObject args = new JObject();

            if (artistId >= 0)
            {
                args.Add(new JProperty("artistid", artistId));
            }
            if (albumId >= 0)
            {
                args.Add(new JProperty("albumid", albumId));
            }
            if (fields != null && fields.Length > 0)
            {
                string[] fieldCopy = new string[fields.Length + 4];
                fieldCopy[0] = "musicvideoid";
                fieldCopy[0] = "title";
                fieldCopy[1] = "artist";
                fieldCopy[1] = "album";
                Array.Copy(fields, 0, fieldCopy, 4, fields.Length);
                args.Add(new JProperty("fields", fieldCopy));
            }
            else
            {
                args.Add(new JProperty("fields", XbmcMusicVideo.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.GetMusicVideos", args) as JObject;

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

                return(null);
            }

            List <XbmcMusicVideo> musicVideos = new List <XbmcMusicVideo>();

            foreach (JObject item in (JArray)query["musicvideos"])
            {
                musicVideos.Add(XbmcMusicVideo.FromJson(item));
            }

            return(musicVideos);
        }
Ejemplo n.º 4
0
        public bool Play(XbmcMusicVideo musicVideo)
        {
            this.client.LogMessage("XbmcGeneral.Play(musicVideo)");

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

            JObject args = new JObject();

            args.Add(new JProperty("musicvideoid", musicVideo.Id));

            return(this.client.Call("XBMC.Play", args) != null);
        }
Ejemplo n.º 5
0
        private static List<string> buildMusicVideoInfo(ICollection<string> patterns, XbmcMusicVideo musicVideo)
        {
            Dictionary<string, string> data = new Dictionary<string, string>(10);
            data.Add("title", musicVideo.Title);
            data.Add("artist", musicVideo.Artist);
            data.Add("album", musicVideo.Album);
            data.Add("year", musicVideo.Year.ToString());
            data.Add("rating", musicVideo.Rating.ToString("0.#"));
            data.Add("genre", musicVideo.Genre);
            data.Add("duration", musicVideo.Duration.Minutes.ToString("0") + ":" + musicVideo.Duration.Seconds.ToString("00"));
            data.Add("studio", musicVideo.Studio);
            data.Add("director", musicVideo.Director);
            data.Add("plot", musicVideo.Plot);

            return buildInfoText(patterns, data);
        }
Ejemplo n.º 6
0
        public bool Play(XbmcMusicVideo musicVideo)
        {
            this.client.LogMessage("XbmcGeneral.Play(musicVideo)");

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

            JObject args = new JObject();
            args.Add(new JProperty("musicvideoid", musicVideo.Id));

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