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); } }
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); }