Exemple #1
0
 public Xbmc()
 {
     File          = new XbmcFile(this);
     VideoLibrary  = new XbmcVideoLibrary(this);
     AudioLibrary  = new XbmcAudioLibrary(this);
     AudioPlayer   = new XbmcAudioPlayer(this);
     PicturePlayer = new XbmcPicturePlayer(this);
     VideoPlayer   = new XbmcVideoPlayer(this);
     Player        = new XbmcPlayer(this);
     SystemRunning = new XbmcSystem(this);
     Remote        = new XbmcRemote(this);
     MpcHcRemote   = new MpcHcRemote(this);
     ApiName       = "XFJ";
 }
Exemple #2
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",
                        "title",
                        "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;

                            if (result2["showtitle"] != null && result2["showtitle"].ToString() != "")
                            {
                                var Title = ReplaceSquare(result2["showtitle"].ToString());
                                _nowPlaying.Title = Title;
                            }
                            else if (result2["title"] != null & result2["title"].ToString() != "")
                            {
                                var Title = ReplaceSquare(result2["title"].ToString());
                                _nowPlaying.Title = Title;
                            }
                            else
                            {
                                var Title = ReplaceSquare(result2["label"].ToString());
                                _nowPlaying.Title = Title;
                            }



                            _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"]);

                        var Title = ReplaceSquare(result2["label"].ToString());
                        _nowPlaying.Title = Title;

                        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:nowPlaying_artist:" + _nowPlaying.Artist);
                        _nowPlaying.Album = result2["album"].ToString();
                        _parent.Log("KODI-Remote:nowPlaying_album" + _nowPlaying.Album);

                        _nowPlaying.ThumbURL = result2["thumbnail"].ToString();
                        _parent.Log("KODI-Remote:nowPlaying_thumbnail:" + _nowPlaying.ThumbURL);

                        if (_nowPlaying.ThumbURL != "" && result2["fanart"].ToString() == "")
                        // if thumbnail not blank  and fanart is blank
                        {
                            _nowPlaying.FanartURL = result2["thumbnail"].ToString();
                            _parent.Log("KODI-Remote:nowPlaying_fanart Modified to Thumb:" + _nowPlaying.FanartURL);
                            _parent.Log("KODI-Remote:nowPlaying_fanart Prior Fanart Received was::" + result2["fanart"].ToString());
                        }
                        else
                        {
                            _nowPlaying.FanartURL = result2["fanart"].ToString();
                            _parent.Log("KODI-Remote:nowPlaying_fanart Not Modified:" + _nowPlaying.FanartURL);
                        }



                        //_nowPlaying.FanartURL = result2["fanart"].ToString();

                        //   _parent.Log("KODI-Remote:nowPlaying_fanart:" + _nowPlaying.FanartURL);
                        // 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"]);

                        var Title = ReplaceSquare(result2["label"].ToString());
                        _nowPlaying.Title = Title;


                        _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();

                        // Change here to using Thumb if Fanart blank

                        if (_nowPlaying.ThumbURL != "" && result2["fanart"].ToString() == "")
                        // if thumbnail not blank  and fanart is blank
                        {
                            _nowPlaying.FanartURL = result2["thumbnail"].ToString();
                            _parent.Log("KODI-Remote:nowPlaying_fanart Modified to Thumb:" + _nowPlaying.FanartURL);
                            _parent.Log("KODI-Remote:nowPlaying_fanart Prior Fanart Received was::" + result2["fanart"].ToString());
                        }
                        else
                        {
                            _nowPlaying.FanartURL = result2["fanart"].ToString();
                            _parent.Log("KODI-Remote:nowPlaying_fanart Not Modified:" + _nowPlaying.FanartURL);
                        }

                        _nowPlaying.LogoURL = clearlogo;
                    }
                }
            }
        }