Esempio n. 1
0
 public void PlaySong(ApiAudioSong audio)
 {
     if (audio == null)
     {
         return;
     }
     if (!_parent.IsConnected())
     {
         return;
     }
     _parent.Command("PlayFile(" + audio.Path + audio.FileName + ";0)");
 }
Esempio n. 2
0
        public void RefreshNowPlaying()
        {
            lock (Locker)
            {
                if (!_parent.IsConnected())
                {
                    return;
                }

                var infos = _parent.Command("GetCurrentlyPlaying");
                if (infos == null)
                {
                    return;
                }

                _currentInfo.Clear();

                foreach (var info in infos)
                {
                    var splitIndex = info.IndexOf(':') + 1;
                    if (splitIndex <= 2)
                    {
                        continue;
                    }
                    var key   = info.Substring(0, splitIndex - 1).Replace(" ", "").ToLower(CultureInfo.InvariantCulture);
                    var value = info.Substring(splitIndex, info.Length - splitIndex);
                    _currentInfo.Add(key, value);
                }
                if (GetInfo("thumb") != null)
                {
                    var thumbparts = GetInfo("thumb").Split('/');
                    var hash       = thumbparts[thumbparts.Length - 1].Trim().Replace(".tbn", "");
                    _currentInfo.Add("fanart", GetInfo("thumb").Replace("/" + hash[0] + "/", "/Fanart/"));
                }


                string[] aVolume   = null;
                string[] aProgress = null;

                if (GetInfo("playstatus") != null)
                {
                    aVolume = _parent.Command("GetVolume");
                    if (aVolume == null)
                    {
                        return;
                    }
                    aProgress = _parent.Command("GetPercentage");
                    if (aProgress == null)
                    {
                        return;
                    }
                }

                try
                {
                    _volume = aVolume != null?Convert.ToInt32("0" + aVolume[0], CultureInfo.InvariantCulture) : 0;
                }
                catch (Exception)
                {
                    _volume = 0;
                }

                _volume = Math.Min(100, _volume);
                try
                {
                    _progress = aProgress != null?Convert.ToInt32("0" + aProgress[0], CultureInfo.InvariantCulture) : 1;
                }
                catch (Exception)
                {
                    _progress = 1;
                }
                _progress = Math.Min(99, _progress);


                var nowPlaying = new ApiCurrently
                {
                    IsPlaying  = (GetInfo("playstatus") == "Playing") ? true : false,
                    IsPaused   = (GetInfo("playstatus") == "Paused") ? true : false,
                    IsNewMedia = _isNewMedia,
                    IsMuted    = (_volume == 0) ? true : false
                };

                if (GetInfo("showtitle") != null)
                {
                    nowPlaying.MediaType = "TvShow";
                }
                else if (GetInfo("title") != null)
                {
                    if (GetInfo("type") == "Audio")
                    {
                        nowPlaying.MediaType = "Audio";
                    }
                    if (GetInfo("type") == "Video")
                    {
                        nowPlaying.MediaType = "Movie";
                    }
                }
                else
                {
                    nowPlaying.MediaType = "Unknown";
                }

                nowPlaying.FileName = GetInfo("filename");
                nowPlaying.Title    = GetInfo("title");
                nowPlaying.Artist   = GetInfo("artist");
                nowPlaying.Album    = GetInfo("album");
                try
                {
                    nowPlaying.Year = Convert.ToInt32("0" + GetInfo("year"), CultureInfo.InvariantCulture);
                }
                catch
                {
                    nowPlaying.Year = 0;
                }
                try
                {
                    nowPlaying.Track = Convert.ToInt32("0" + GetInfo("track"), CultureInfo.InvariantCulture);
                }
                catch
                {
                    nowPlaying.Track = 0;
                }
                try
                {
                    nowPlaying.SeasonNumber = Convert.ToInt32("0" + GetInfo("season"), CultureInfo.InvariantCulture);
                }
                catch
                {
                    nowPlaying.SeasonNumber = 0;
                }
                try
                {
                    nowPlaying.EpisodeNumber = Convert.ToInt32("0" + GetInfo("episode"), CultureInfo.InvariantCulture);
                }
                catch
                {
                    nowPlaying.EpisodeNumber = 0;
                }

                nowPlaying.Genre     = GetInfo("genre");
                nowPlaying.ThumbURL  = GetInfo("thumb");
                nowPlaying.FanartURL = GetInfo("fanart");
                nowPlaying.ShowTitle = GetInfo("showtitle");
                nowPlaying.Plot      = GetInfo("plot");
                nowPlaying.Director  = GetInfo("director");
                nowPlaying.Volume    = GetVolume();
                nowPlaying.Progress  = GetProgress();

                nowPlaying.Studio  = GetInfo("studio");
                nowPlaying.Tagline = GetInfo("tagline");
                nowPlaying.Rating  = GetInfo("rating");

                var time = GetInfo("time");
                if (!string.IsNullOrEmpty(time))
                {
                    var splittime = time.Split(':');
                    switch (splittime.Length)
                    {
                    case 1:
                        nowPlaying.Time = new TimeSpan(0, 0, 0,
                                                       Convert.ToInt32("0" + splittime[0], CultureInfo.InvariantCulture));
                        break;

                    case 2:
                        nowPlaying.Time = new TimeSpan(0, 0,
                                                       Convert.ToInt32("0" + splittime[0], CultureInfo.InvariantCulture),
                                                       Convert.ToInt32("0" + splittime[1], CultureInfo.InvariantCulture));
                        break;

                    case 3:
                        nowPlaying.Time = new TimeSpan(0,
                                                       Convert.ToInt32("0" + splittime[0], CultureInfo.InvariantCulture),
                                                       Convert.ToInt32("0" + splittime[1], CultureInfo.InvariantCulture),
                                                       Convert.ToInt32("0" + splittime[2], CultureInfo.InvariantCulture));
                        break;

                    default:
                        nowPlaying.Time = new TimeSpan(0);
                        break;
                    }
                }

                var duration = GetInfo("duration");
                if (duration != null)
                {
                    var splitduration = duration.Split(':');
                    switch (splitduration.Length)
                    {
                    case 1:
                        nowPlaying.Duration = new TimeSpan(0, 0, 0,
                                                           Convert.ToInt32("0" + splitduration[0],
                                                                           CultureInfo.InvariantCulture));
                        break;

                    case 2:
                        nowPlaying.Duration = new TimeSpan(0, 0,
                                                           Convert.ToInt32("0" + splitduration[0],
                                                                           CultureInfo.InvariantCulture),
                                                           Convert.ToInt32("0" + splitduration[1],
                                                                           CultureInfo.InvariantCulture));
                        break;

                    case 3:
                        nowPlaying.Duration = new TimeSpan(0,
                                                           Convert.ToInt32("0" + splitduration[0],
                                                                           CultureInfo.InvariantCulture),
                                                           Convert.ToInt32("0" + splitduration[1],
                                                                           CultureInfo.InvariantCulture),
                                                           Convert.ToInt32("0" + splitduration[2],
                                                                           CultureInfo.InvariantCulture));
                        break;

                    default:
                        nowPlaying.Duration = new TimeSpan(0);
                        break;
                    }
                }

                var firstaired = GetInfo("firstaired");
                if (firstaired != null)
                {
                    var splitaired = firstaired.Split('-');
                    if (splitaired.Length > 1)
                    {
                        nowPlaying.FirstAired =
                            new DateTime(Convert.ToInt32("0" + splitaired[0], CultureInfo.InvariantCulture),
                                         Convert.ToInt32("0" + splitaired[1], CultureInfo.InvariantCulture),
                                         Convert.ToInt32("0" + splitaired[2], CultureInfo.InvariantCulture));
                    }
                }
                _nowPlaying = nowPlaying;
            }
        }