Exemplo n.º 1
0
        private WebClient RpcRequest(string method, List<object> args, Callback callback, Errback errback)
        {
            var client = new WebClient();
            var uri = GetUri();
            client.Credentials = new NetworkCredential(this.userName, this.password);
            client.Headers[HttpRequestHeader.ContentType] = "application/json";
            client.UploadStringCompleted += (sender, e) =>
            {
                try
                {
                    var response = JObject.Parse(e.Result);

                    if (callback != null)
                    {
                        callback(response);
                    }
                }
                catch (WebException exception)
                {
                    if (errback != null)
                    {
                        errback(exception);
                    }
                    else
                    {
                        Debug.WriteLine("Error (" + uri + "): " + method);
                        Debug.WriteLine(exception);
                    }
                }
            };
            var body = BuildRequest(method, args);
            Debug.WriteLine("Request: " + uri + " | " + method + " " + body);
            client.UploadStringAsync(uri, body);
            return client;
        }
Exemplo n.º 2
0
 public void PlayMovie(int movieId, Callback callback = null, Errback errback = null)
 {
     var args = new List<object> { new Dictionary<string, object>() { {"movieid", movieId} } };
     RpcRequest("Player.Open", args, callback, errback);
 }
Exemplo n.º 3
0
        public void GetTvSeasons(int tvShowId, Callback callback, Errback errback = null, List<string> properties = null, Limits limits = null, Sort sort = null)
        {
            if (properties == null)
            {
                properties = new List<string> { "showtitle", "season", "fanart", "thumbnail", "episode", "playcount" };
            }

            if (limits == null)
            {
                limits = new Limits { start = 0, end = 100 };
            }

            if (sort == null)
            {
                sort = new Sort
                {
                    ignorearticle = true,
                    order = SortOrder.Ascending,
                    method = SortMethod.Year
                };
            }

            var args = new List<object> { tvShowId, properties, limits, sort };
            RpcRequest("VideoLibrary.GetSeasons", args, (data) =>
            {
                callback(data.SelectToken("result.seasons"));
            }, errback);
        }
Exemplo n.º 4
0
        public void GetTvShows(Callback callback, Errback errback = null, List<string> properties = null, Limits limits = null, Sort sort = null)
        {
            if (properties == null)
            {
                properties = new List<string> { "title", "genre", "thumbnail" };
            }

            if (limits == null)
            {
                limits = new Limits { start = 0, end = 100 };
            }

            if (sort == null)
            {
                sort = new Sort
                {
                    ignorearticle = true,
                    order = SortOrder.Ascending,
                    method = SortMethod.Title
                };
            }

            var args = new List<object> { properties, limits, sort };
            RpcRequest("VideoLibrary.GetTVShows", args, (data) =>
            {
                callback(data.SelectToken("result.tvshows"));
            }, errback);
        }
Exemplo n.º 5
0
        public void GetRecentlyAddedEpisodes(Callback callback, Errback errback = null, List<string> properties = null, Limits limits = null, Sort sort = null)
        {
            if (properties == null)
            {
                properties = new List<string> { "title", "showtitle", "fanart", "thumbnail", "firstaired" };
            }

            if (limits == null)
            {
                limits = new Limits { start = 0, end = 100 };
            }

            if (sort == null)
            {
                sort = new Sort
                {
                    ignorearticle = true,
                    order = SortOrder.Descending,
                    method = SortMethod.Date
                };
            }

            var args = new List<object> { properties, limits, sort };
            RpcRequest("VideoLibrary.GetRecentlyAddedEpisodes", args, (data) =>
            {
                callback(data.SelectToken("result.episodes"));
            }, errback);
        }