예제 #1
0
        public bool Command(string cmd, string parameter)
        {
            HttpWebRequest request;
            var            returnContent = false;

            var uri = @"http://" + _parent.IP + ":" + _parent.MpcHcPort + "/command.html?wm_command=" + cmd;

            if (!String.IsNullOrEmpty(parameter))
            {
                uri += "&" + parameter;
            }
            try
            {
                request         = (HttpWebRequest)WebRequest.Create(new Uri(uri));
                request.Method  = "GET";
                request.Timeout = 1000;
                _parent.Log("MPCCOMMAND : " + cmd);
                _parent.Trace(uri);
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var reader = new StreamReader(stream, Encoding.UTF8))
                            {
                                var reqContent = reader.ReadToEnd();
                                _parent.Trace(reqContent);
                                returnContent = true;
                            }
                        }
                    }
                }
            }
            catch (WebException e)
            {
                _parent.Log("ERROR - MPCCOMMAND : " + cmd + " - " + e.Message);
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    _parent.MpcLoaded = false;
                }
            }
            return(returnContent);
        }
예제 #2
0
        public Collection <ApiTvSeason> GetTvSeasonsRefresh()
        {
            var seasons = new Collection <ApiTvSeason>();

            var properties = new JsonArray(new[] { "title" });
            var param      = new JsonObject();

            param["properties"] = properties;

            // First 100 Date sorted
            var param2 = new JsonObject();

            param2.Add("start", 0);
            param2.Add("end", 10);
            var param3 = new JsonObject();

            param3.Add("order", "descending");
            param3.Add("method", "dateadded");
            param.Add("sort", param3);
            param.Add("limits", param2);

            var result = (JsonObject)_parent.JsonCommand("VideoLibrary.GetTVShows", param);

            if (result != null)
            {
                if (result.Contains("tvshows"))
                {
                    foreach (JsonObject show in (JsonArray)result["tvshows"])
                    {
                        var properties2 =
                            new JsonArray(new[] { "tvshowid", "fanart", "thumbnail", "season", "showtitle", "episode" });
                        var param22 = new JsonObject();
                        param22["properties"] = properties2;
                        param22["tvshowid"]   = (long)(JsonNumber)show["tvshowid"];

                        var result2 = (JsonObject)_parent.JsonCommand("VideoLibrary.GetSeasons", param22);
                        if (result2 == null)
                        {
                            continue;
                        }
                        if (!result2.Contains("seasons"))
                        {
                            continue;
                        }
                        foreach (JsonObject genre in (JsonArray)result2["seasons"])
                        {
                            try
                            {
                                _parent.Trace("Kodi QuickRefresh Seasons:  SeasonNumber:" + (long)(JsonNumber)genre["season"]);
                                _parent.Trace("Kodi QuickRefresh Seasons:  IdShow:" + (long)(JsonNumber)genre["tvshowid"]);
                                _parent.Trace("Kodi QuickRefresh Seasons:  Show:" + genre["showtitle"].ToString());
                                _parent.Trace("Kodi QuickRefresh Seasons:  Thumb:" + genre["thumbnail"].ToString());
                                _parent.Trace("Kodi QuickRefresh Seasons:  EpisodeCount:" + (long)(JsonNumber)genre["episode"]);
                                _parent.Trace("Kodi QuickRefresh Seasons:  Fanart:" + genre["fanart"].ToString());
                                _parent.Trace("Kodi QuickRefresh Seasons:  Hash:" + genre["thumbnail"].ToString());

                                var tvShow = new ApiTvSeason
                                {
                                    SeasonNumber = (long)(JsonNumber)genre["season"],
                                    IdShow       = (long)(JsonNumber)genre["tvshowid"],
                                    Show         = genre["showtitle"].ToString(),
                                    Thumb        = genre["thumbnail"].ToString(),
                                    EpisodeCount = (long)(JsonNumber)genre["episode"],
                                    Fanart       = genre["fanart"].ToString(),
                                    Hash         = Xbmc.Hash(genre["thumbnail"].ToString())
                                };
                                seasons.Add(tvShow);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
            return(seasons);
        }
예제 #3
0
        public List <string> GetMovieIcons(JsonObject streamdetails)
        {
            List <string> MovieIcons = new List <string>();

            _parent.Trace("MovieIcons Generating List:");

            // Make sure not null;
            MovieIcons.Add("");

            try
            {
                var stringJsonResults = Jayrock.Json.Conversion.JsonConvert.ExportToString(streamdetails);

                _parent.Trace("MovieIcons" + stringJsonResults);
                var deserializer = new JavaScriptSerializer();
                StreamDetails.Rootobject ItemData = deserializer.Deserialize <StreamDetails.Rootobject>(stringJsonResults);



                //Container
                if (ItemData != null)
                {
                    if (ItemData.audio != null && ItemData.audio.Length > 0)
                    {
                        var isDefaultMediaStream = ItemData.audio.FirstOrDefault();

                        //Sorry Non-English Speakers defaults to English stream
                        // Check for Default Language for system - and uses that...

                        CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture;
                        var         DefaultLanguage = ci.TwoLetterISOLanguageName.ToString();

                        _parent.Trace("MovieIcons : Default System language:" + DefaultLanguage);
                        int CountStreams = 0;
                        if (ItemData.audio.Length > 0)
                        {
                            CountStreams = ItemData.audio.Where(i => i.language == DefaultLanguage).Count();
                            _parent.Trace("MovieIcons ItemData.audio not null : " + CountStreams);
                        }


                        try
                        {
                            if (CountStreams > 0)       //if default language stream use this
                            {
                                isDefaultMediaStream = ItemData.audio.FirstOrDefault(i => i.language == DefaultLanguage);
                                // added check - make sure is default stream being checked
                                // often multiples streams commentary etc with ac3 and other codecs - would not make sense to have all shown
                            }
                            else     // if (CountStreams <= 0)  //if no default language - often tv - use firstordefault stream...
                            {
                                if (ItemData.audio != null)
                                {
                                    isDefaultMediaStream = ItemData.audio.FirstOrDefault();
                                }
                            }



                            var MovieCodec = isDefaultMediaStream.codec;

                            if (MovieCodec != null && !string.IsNullOrEmpty(MovieCodec))
                            {
                                if (MovieCodec.Equals("dca") == true || MovieCodec.Equals("dts"))
                                {
                                    MovieIcons.Add("DTS");
                                    _parent.Trace("MovieIcons adding DTS Profile: DTS :  Codecequals" + MovieCodec.ToUpper().ToString());
                                }
                                else if (MovieCodec.Contains("dts") && !MovieCodec.Equals("dts"))
                                {
                                    string Profile = MovieCodec.ToString();
                                    Profile = Profile.Replace("dts", "dst");
                                    MovieIcons.Add(Profile.ToUpper());
                                    _parent.Trace("MovieIcons dca adding DST Plus Profile:" + Profile.ToUpper());
                                }
                                else
                                {
                                    MovieIcons.Add(MovieCodec.ToString());
                                    _parent.Trace("MovieIcons Adding Codec:" + MovieCodec.ToString());
                                }
                            }

                            var Channels = isDefaultMediaStream.channels;
                            if (Channels > 0)
                            {
                                MovieIcons.Add("Channels" + Channels.ToString());
                                _parent.Trace("MovieIcons Adding Channels:" + Channels.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            _parent.Trace("MovieIcons Exception Caught Within AudioStream Codec Check:" + ex);
                            // Don't return here - carry on for video icons...
                            //return MovieIcons;
                        }
                    }


                    var VideoInfo = ItemData.video.FirstOrDefault();

                    if (VideoInfo != null)
                    {
                        if (!string.IsNullOrWhiteSpace(VideoInfo.codec))
                        {
                            MovieIcons.Add("codec" + VideoInfo.codec.ToString());
                            _parent.Trace("MovieIcons Adding codec" + VideoInfo.codec.ToString());
                        }
                        if (VideoInfo.aspect > 0)
                        {
                            if (VideoInfo.aspect > 0)
                            {
                                MovieIcons.Add(VideoInfo.aspect.ToString("0.00") + ":1");
                                _parent.Trace("MovieIcons Adding Ratio:" + VideoInfo.aspect.ToString("0.00") + ":1");
                            }
                        }

                        if (VideoInfo.width.HasValue)
                        {
                            if (VideoInfo.width > 3800)
                            {
                                MovieIcons.Add("4K");
                                _parent.Trace("MoviesIcons Adding 4K");
                            }
                            else if (VideoInfo.width >= 1900)
                            {
                                MovieIcons.Add("1080p");
                                _parent.Trace("MoviesIcons Adding 1080p");
                            }
                            else if (VideoInfo.width >= 1270)
                            {
                                MovieIcons.Add("720p");
                                _parent.Trace("MoviesIcons Adding 720p");
                            }
                            else if (VideoInfo.width >= 700)
                            {
                                MovieIcons.Add("480P");
                                _parent.Trace("MoviesIcons Adding 480p");
                            }
                            else
                            {
                                MovieIcons.Add("SD");
                                _parent.Trace("MoviesIcons Adding SD");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _parent.Trace("MovieIcons Exception Caught Within VideoInfo Codec Check:" + ex);
                return(MovieIcons);
            }



            return(MovieIcons);
        }