diff --git a/Handlers/MPDHandler.cs b/Handlers/MPDHandler.cs index 676cf81..9f87700 100644 --- a/Handlers/MPDHandler.cs +++ b/Handlers/MPDHandler.cs @@ -20,6 +20,17 @@ using MpcNET.Types; namespace unison { + public class Statistics + { + public int Songs { get; set; } + public int Albums { get; set; } + public int Artists { get; set; } + public string TotalPlaytime { get; set; } + public string Uptime { get; set; } + public string TotalTimePlayed { get; set; } + public string DatabaseUpdate { get; set; } + } + public class MPDHandler { private bool _connected; @@ -36,6 +47,7 @@ namespace unison private MpdStatus _currentStatus; private IMpdFile _currentSong; private BitmapFrame _cover; + public Statistics _stats; private readonly System.Timers.Timer _elapsedTimer; private DispatcherTimer _retryTimer; @@ -58,6 +70,8 @@ namespace unison Initialize(null, null); + _stats = new Statistics(); + _retryTimer = new DispatcherTimer(); _retryTimer.Interval = TimeSpan.FromSeconds(5); _retryTimer.Tick += Initialize; @@ -417,6 +431,7 @@ namespace unison public MpdStatus GetStatus() => _currentStatus; public BitmapFrame GetCover() => _cover; public string GetVersion() => _version; + public Statistics GetStats() => _stats; public double GetCurrentTime() => _currentTime; public bool IsConnected() => _connected; @@ -479,5 +494,25 @@ namespace unison CommandList commandList = new CommandList(new IMpcCommand[] { new ClearCommand(), new AddCommand(Uri), new PlayCommand(0) }); SendCommand(commandList); } + + public async void QueryStats() + { + Dictionary response = await SafelySendCommandAsync(new StatsCommand()); + + _stats.Songs = int.Parse(response["songs"]); + _stats.Albums = int.Parse(response["albums"]); + _stats.Artists = int.Parse(response["artists"]); + + TimeSpan time; + time = TimeSpan.FromSeconds(int.Parse(response["uptime"])); + _stats.Uptime = time.ToString(@"dd\:hh\:mm\:ss"); + time = TimeSpan.FromSeconds(int.Parse(response["db_playtime"])); + _stats.TotalPlaytime = time.ToString(@"dd\:hh\:mm\:ss"); + time = TimeSpan.FromSeconds(int.Parse(response["playtime"])); + _stats.TotalTimePlayed = time.ToString(@"dd\:hh\:mm\:ss"); + + DateTime date = new DateTime(1970, 1, 1).AddSeconds(int.Parse(response["db_update"])).ToLocalTime(); + _stats.DatabaseUpdate = date.ToString("dd/MM/yyyy @ HH:mm"); + } } } \ No newline at end of file diff --git a/Resources/Resources.Designer.cs b/Resources/Resources.Designer.cs index d6a0eac..71e5d58 100644 --- a/Resources/Resources.Designer.cs +++ b/Resources/Resources.Designer.cs @@ -501,6 +501,78 @@ namespace unison.Resources { } } + /// + /// Looks up a localized string similar to Stats. + /// + public static string Stats { + get { + return ResourceManager.GetString("Stats", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Albums:. + /// + public static string Stats_Albums { + get { + return ResourceManager.GetString("Stats_Albums", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Artists:. + /// + public static string Stats_Artists { + get { + return ResourceManager.GetString("Stats_Artists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Last database update:. + /// + public static string Stats_LastDatabaseUpdate { + get { + return ResourceManager.GetString("Stats_LastDatabaseUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Songs:. + /// + public static string Stats_Songs { + get { + return ResourceManager.GetString("Stats_Songs", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Total playtime:. + /// + public static string Stats_TotalPlaytime { + get { + return ResourceManager.GetString("Stats_TotalPlaytime", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Total time played:. + /// + public static string Stats_TotalTimePlayed { + get { + return ResourceManager.GetString("Stats_TotalTimePlayed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to MPD uptime:. + /// + public static string Stats_Uptime { + get { + return ResourceManager.GetString("Stats_Uptime", resourceCulture); + } + } + /// /// Looks up a localized string similar to Stop Snapcast. /// diff --git a/Resources/Resources.fr-FR.resx b/Resources/Resources.fr-FR.resx index b967c6d..894aee0 100644 --- a/Resources/Resources.fr-FR.resx +++ b/Resources/Resources.fr-FR.resx @@ -264,6 +264,30 @@ Démarrer Snapcast + + Stats + + + Albums : + + + Artistes : + + + Mise à jour de la base de données : + + + Morceaux : + + + Temps total : + + + Temps d'écoute écoulé : + + + MPD lancé depuis : + Stopper Snapcast diff --git a/Resources/Resources.resx b/Resources/Resources.resx index fa872bb..0969be0 100644 --- a/Resources/Resources.resx +++ b/Resources/Resources.resx @@ -264,6 +264,30 @@ Start Snapcast + + Stats + + + Albums: + + + Artists: + + + Last database update: + + + Songs: + + + Total playtime: + + + Total time played: + + + MPD uptime: + Stop Snapcast diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs index 115fdbf..bee00c7 100644 --- a/Views/MainWindow.xaml.cs +++ b/Views/MainWindow.xaml.cs @@ -137,6 +137,9 @@ namespace unison DefaultState(); } } + + _mpd.QueryStats(); + _settingsWin.UpdateStats(); } private void DefaultState(bool LostConnection = false) diff --git a/Views/Settings.xaml b/Views/Settings.xaml index d688dce..e498f59 100644 --- a/Views/Settings.xaml +++ b/Views/Settings.xaml @@ -14,12 +14,10 @@ - - - - - - + + + + @@ -46,13 +44,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - - + @@ -82,17 +102,15 @@ - - - - - - + + + + - + diff --git a/Views/Settings.xaml.cs b/Views/Settings.xaml.cs index 2ee47bd..ac98bcd 100644 --- a/Views/Settings.xaml.cs +++ b/Views/Settings.xaml.cs @@ -88,6 +88,18 @@ namespace unison SnapcastPort.Text = (string)Application.Current.FindResource("snapcastPort"); } + public void UpdateStats() + { + MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"]; + StatSong.Text = mpd.GetStats().Songs.ToString(); + StatAlbum.Text = mpd.GetStats().Albums.ToString(); + StatArtist.Text = mpd.GetStats().Artists.ToString(); + StatTotalPlaytime.Text = mpd.GetStats().TotalPlaytime.ToString(); + StatUptime.Text = mpd.GetStats().Uptime.ToString(); + StatTotalTimePlayed.Text = mpd.GetStats().TotalTimePlayed.ToString(); + StatDatabaseUpdate.Text = mpd.GetStats().DatabaseUpdate.ToString(); + } + public void SaveSettings() { Properties.Settings.Default.mpd_host = MpdHost.Text;