Beispiel #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);
        }
Beispiel #2
0
        public Collection <ApiTvShow> GetTvShows()
        {
            var shows = new Collection <ApiTvShow>();

            var properties = new JsonArray(new[] { "title", "art", "plot", "genre", "fanart", "thumbnail", "rating", "mpaa", "studio", "playcount", "premiered", "episode", "file" });
            var param      = new JsonObject();

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

            if (result != null)
            {
                if (result.Contains("tvshows"))
                {
                    foreach (JsonObject genre in (JsonArray)result["tvshows"])
                    {
                        try
                        {
                            var clearlogo = "NONE";
                            var banner    = "NONE";
                            // go through art and see.

                            JsonObject results = (JsonObject)genre["art"];

                            if (results != null)
                            {
                                if (results["clearlogo"] != null)
                                {
                                    clearlogo = results["clearlogo"].ToString();
                                }
                                if (results["banner"] != null)
                                {
                                    banner = results["banner"].ToString();
                                }
                            }



                            var tvShow = new ApiTvShow
                            {
                                Title      = genre["title"].ToString(),
                                Plot       = genre["plot"].ToString(),
                                Rating     = genre["rating"].ToString(),
                                IdScraper  = "",
                                Mpaa       = genre["mpaa"].ToString(),
                                Genre      = _parent.JsonArrayToString((JsonArray)genre["genre"]),
                                Studio     = _parent.JsonArrayToString((JsonArray)genre["studio"]),
                                IdShow     = (long)(JsonNumber)genre["tvshowid"],
                                TotalCount = (long)(JsonNumber)genre["episode"],
                                Path       = genre["file"].ToString(),
                                Premiered  = genre["premiered"].ToString(),
                                Thumb      = genre["thumbnail"].ToString(),
                                Fanart     = genre["fanart"].ToString(),
                                Logo       = clearlogo,
                                Banner     = banner,
                                Hash       = Xbmc.Hash(genre["thumbnail"].ToString())
                            };
                            shows.Add(tvShow);
                        }
                        catch (Exception ex)
                        {
                            _parent.Log("GetTVShows : Exception Caught: Json seems to equal :" + ex);
                        }
                    }
                }
            }
            return(shows);
        }
Beispiel #3
0
 public void StopAsync()
 {
     _parent.Log("Cancelling downloads");
     _workerDownloads.CancelAsync();
 }
Beispiel #4
0
        public void RefreshNowPlaying()
        {
            lock (Locker)
            {
                if (_parent.MpcLoaded)
                {
                    var result  = _parent.MpcHcRemote.GetStatus();
                    var result2 = new ArrayList();
                    MpcHcRemote.ParseCSVFields(result2, result);
                    var data = (string[])result2.ToArray(typeof(string));
                    if (data.Length > 6)
                    {
                        _nowPlaying.MediaType = "Video";
                        _nowPlaying.Title     = "Media Player Classic";
                        _nowPlaying.Time      = new TimeSpan(0, 0, 0, Convert.ToInt32("0" + data[2]) / 1000);
                        _nowPlaying.Duration  = new TimeSpan(0, 0, 0, Convert.ToInt32("0" + data[4]) / 1000);
                        var percent = Math.Floor(100.0 * Convert.ToInt32("0" + data[2], CultureInfo.InvariantCulture) / Convert.ToInt32("0" + data[4], CultureInfo.InvariantCulture));
                        if (Double.IsNaN(percent))
                        {
                            percent = 0;
                        }
                        _nowPlaying.Volume   = Convert.ToInt32("0" + data[7], CultureInfo.InvariantCulture);
                        _nowPlaying.IsMuted  = data[6] == "1";
                        _nowPlaying.Progress = (int)percent;

                        if (data[1] == "Playing")
                        {
                            _parent.Log("XBMC PLAYER REMOTE:   Playing given Changing NowPlaying to true " + data[1]);
                            _nowPlaying.IsPlaying = true;
                            _nowPlaying.IsPaused  = false;
                        }
                        if (data[1] == "Paused")
                        {
                            _parent.Log("XBMC PLAYER REMOTE:   Paused given Changing NowPlaying to true " + data[1]);
                            _nowPlaying.IsPaused  = true;
                            _nowPlaying.IsPlaying = !_nowPlaying.IsPaused;
                        }
                    }
                    if (_parent.MpcLoaded == false)
                    {
                        _nowPlaying.FileName  = "Glenn MPC Stopped";
                        _nowPlaying.Title     = "";
                        _nowPlaying.IsPlaying = false;
                        _nowPlaying.IsPaused  = false;
                    }
                }
                else
                {
                    if (!_parent.IsConnected())
                    {
                        _nowPlaying.FileName  = "";
                        _nowPlaying.Title     = "";
                        _nowPlaying.IsPlaying = false;
                        _nowPlaying.IsPaused  = false;
                        _parent.Log("XBMC PLAYER REMOTE:   Returning as no !Player Connected");

                        return;
                    }



                    //_parent.Log("XBMC PLAYER REMOTE:   Check with MPC Doesnt make it here");
                    var GUIproperties = new JsonObject();
                    GUIproperties["properties"] = new[]
                    {
                        "currentwindow"
                    };

                    var menuresult = (JsonObject)_parent.JsonCommand("GUI.GetProperties", GUIproperties);
                    var GUIdeeper  = (JsonObject)menuresult["currentwindow"];
                    _nowPlaying.CurrentMenuLabel = GUIdeeper["label"].ToString();
                    _nowPlaying.CurrentMenuID    = GUIdeeper["id"].ToString();


                    var current = -1;
                    var players = (JsonArray)_parent.JsonCommand("Player.GetActivePlayers", null);


                    if (players.Count > 0)
                    {
                        foreach (JsonObject player in players)
                        {
                            if (player["type"].ToString() == "picture")
                            {
                                continue;
                            }
                            current = Int32.Parse(player["playerid"].ToString());
                            _nowPlaying.MediaType = (string)player["type"];
                        }
                    }

                    if (current == -1)
                    {
                        _nowPlaying.FileName  = "";
                        _nowPlaying.Title     = "";
                        _nowPlaying.IsPlaying = false;
                        _nowPlaying.IsPaused  = false;
                        return;
                    }



                    var items = new JsonObject();
                    items["playerid"]   = current;
                    items["properties"] = new[] {
                        "file",
                        "comment",
                        "tvshowid",
                        "albumartist",
                        "duration",
                        "streamdetails",
                        //"id",
                        "album",
                        //"votes",
                        // "mpaa",
                        // "writer",
                        //"albumid",
                        //"type",
                        "genre",
                        "year",
                        //"plotoutline",
                        "track",
                        "artist",
                        //"season",
                        //"imdbnumber",
                        // "studio",
                        //"showlink",
                        "showtitle",
                        "episode",
                        "season",
                        "plot",
                        "director",
                        "studio",
                        "rating",
                        //"productioncode",
                        //"country",
                        //"premiered",
                        //"originaltitle",
                        //"artistid",
                        //"firstaired",
                        "tagline",
                        "thumbnail",
                        "fanart",
                        "art"
                        //"top250",
                        //"trailer"
                    };

                    var properties = new JsonObject();
                    properties["playerid"]   = current;
                    properties["properties"] = new[] {
                        "totaltime",
                        "percentage",
                        "time",
                        "speed"
                    };

                    var appproperties = new JsonObject();
                    appproperties["properties"] = new[]
                    {
                        "muted",
                        "volume"
                    };

                    var result1 = (JsonObject)_parent.JsonCommand("Player.GetProperties", properties);
                    var result2 = (JsonObject)_parent.JsonCommand("Player.GetItem", items);
                    var result3 = (JsonObject)_parent.JsonCommand("Application.GetProperties", appproperties);


                    if (result1 == null || result2 == null || result3 == null)
                    {
                        _nowPlaying.FileName  = "";
                        _nowPlaying.Title     = "";
                        _nowPlaying.IsPlaying = false;
                        _nowPlaying.IsPaused  = false;
                        return;
                    }

                    result2 = (JsonObject)(result2)["item"];

                    var clearlogo = "NONE";
                    var banner    = "NONE";
                    // go through art and see.

                    JsonObject artresults = (JsonObject)result2["art"];

                    if (artresults != null)
                    {
                        if (artresults["clearlogo"] != null)
                        {
                            clearlogo = artresults["clearlogo"].ToString();
                        }
                        if (artresults["banner"] != null)
                        {
                            banner = artresults["banner"].ToString();
                        }
                    }



                    if (_nowPlaying.MediaType == "video")
                    {
                        if (result2["type"].ToString() == "channel")  //if PVR Needs to go high otherwise exception
                        {
                            _nowPlaying.MediaType  = "Pvr";
                            _nowPlaying.IsNewMedia = true;
                            _nowPlaying.FileName   = result2["label"].ToString();
                            _nowPlaying.ThumbURL   = result2["thumbnail"].ToString();
                            _nowPlaying.FanartURL  = result2["fanart"].ToString();
                            _nowPlaying.LogoURL    = clearlogo;
                            _nowPlaying.Title      = result2["label"].ToString();
                            _nowPlaying.IsPaused   = Convert.ToInt32("0" + result1["speed"].ToString().Replace("-", "")) == 0;
                            _nowPlaying.IsPlaying  = !_nowPlaying.IsPaused;
                            var pvrtime  = (JsonObject)result1["time"];
                            var pvrtotal = (JsonObject)result1["totaltime"];
                            _nowPlaying.Time     = new TimeSpan(0, Convert.ToInt32("0" + pvrtime["hours"]), Convert.ToInt32("0" + pvrtime["minutes"]), Convert.ToInt32("0" + pvrtime["seconds"]));
                            _nowPlaying.Duration = new TimeSpan(0, Convert.ToInt32("0" + pvrtotal["hours"]), Convert.ToInt32("0" + pvrtotal["minutes"]), Convert.ToInt32("0" + pvrtotal["seconds"]));
                            _nowPlaying.Progress = Convert.ToInt32("0" + result1["percentage"].ToString().Split('.')[0]);
                            _nowPlaying.Volume   = Convert.ToInt32("0" + result3["volume"]);
                            _nowPlaying.IsMuted  = (bool)result3["muted"];
                            return;
                        }
                    }

                    _nowPlaying.IsPaused  = Convert.ToInt32("0" + result1["speed"].ToString().Replace("-", "")) == 0;
                    _nowPlaying.IsPlaying = !_nowPlaying.IsPaused;
                    var time  = (JsonObject)result1["time"];
                    var total = (JsonObject)result1["totaltime"];
                    _nowPlaying.Time     = new TimeSpan(0, Convert.ToInt32("0" + time["hours"]), Convert.ToInt32("0" + time["minutes"]), Convert.ToInt32("0" + time["seconds"]));
                    _nowPlaying.Duration = new TimeSpan(0, Convert.ToInt32("0" + total["hours"]), Convert.ToInt32("0" + total["minutes"]), Convert.ToInt32("0" + total["seconds"]));
                    _nowPlaying.Progress = Convert.ToInt32("0" + result1["percentage"].ToString().Split('.')[0]);
                    _nowPlaying.Volume   = Convert.ToInt32("0" + result3["volume"]);
                    _nowPlaying.IsMuted  = (bool)result3["muted"];

                    _parent.MpcLoaded = _nowPlaying.Duration == new TimeSpan(0, 0, 0, 1);

                    _nowPlaying.FileName = result2["file"].ToString();

                    if (_nowPlaying.MediaType == "audio")
                    {
                        _nowPlaying.MediaType = "Audio";
                        _nowPlaying.Genre     = _parent.JsonArrayToString((JsonArray)result2["genre"]);
                        _nowPlaying.Title     = result2["label"].ToString();

                        if (_nowPlaying.Track > 0)
                        {
                            _nowPlaying.Track = Convert.ToInt32("0" + result2["track"]);
                        }
                        else
                        {
                            _nowPlaying.Track = 0;
                        }

                        if (_nowPlaying.Year > 0)
                        {
                            _nowPlaying.Year = Convert.ToInt32("0" + result2["year"]);
                        }
                        else
                        {
                            _nowPlaying.Year = 0;
                        }


                        _nowPlaying.Artist = _parent.JsonArrayToString((JsonArray)result2["artist"]);
                        _parent.Log("Kodi Remote AUDIO: Artist Equals:" + _nowPlaying.Artist);
                        _nowPlaying.Album     = result2["album"].ToString();
                        _nowPlaying.ThumbURL  = result2["thumbnail"].ToString();
                        _nowPlaying.FanartURL = result2["fanart"].ToString();

                        // add to remove theme files


                        _parent.Log("---THEME MP3 NOWPLAYING FILENAME EQUALS:" + _nowPlaying.FileName);
                        if (_nowPlaying.FileName.EndsWith("theme.mp3"))
                        {
                            _nowPlaying.FileName   = "";
                            _nowPlaying.Title      = "";
                            _nowPlaying.IsPlaying  = false;
                            _nowPlaying.IsPaused   = false;
                            _nowPlaying.IsNewMedia = false;
                            _parent.Log("Kodi Remote:   Theme.mp3 playing stopping" + _nowPlaying.FileName);
                            return;
                        }
                    }

                    if (_nowPlaying.MediaType == "video")
                    {
                        _nowPlaying.MediaType = result2["type"].ToString() == "episode" ? "TvShow" : "Movie";


                        JsonObject    streamdetails = (JsonObject)result2["streamdetails"];
                        List <string> MovieIcons    = new List <string>();

                        MovieIcons = GetMovieIcons(streamdetails);

                        _nowPlaying.MovieIcons    = String.Join(",", MovieIcons);
                        _nowPlaying.Genre         = _parent.JsonArrayToString((JsonArray)result2["genre"]);
                        _nowPlaying.Title         = result2["label"].ToString();
                        _nowPlaying.Year          = Convert.ToInt32("0" + result2["year"]);
                        _nowPlaying.SeasonNumber  = Convert.ToInt32("0" + result2["season"].ToString().Replace("-", ""));
                        _nowPlaying.EpisodeNumber = Convert.ToInt32("0" + result2["episode"].ToString().Replace("-", ""));
                        _nowPlaying.ShowTitle     = result2["showtitle"].ToString();
                        _nowPlaying.Plot          = result2["plot"].ToString();
                        _nowPlaying.Director      = _parent.JsonArrayToString((JsonArray)result2["director"]);
                        _nowPlaying.Studio        = _parent.JsonArrayToString((JsonArray)result2["studio"]);
                        _nowPlaying.Tagline       = result2["tagline"].ToString();
                        _nowPlaying.Rating        = result2["rating"].ToString();
                        _nowPlaying.ThumbURL      = result2["thumbnail"].ToString();
                        _nowPlaying.FanartURL     = result2["fanart"].ToString();
                        _nowPlaying.LogoURL       = clearlogo;
                    }
                }
            }
        }