refactored favorites to mostplayed

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2016-09-05 19:18:41 -05:00
parent 6923b5f73a
commit e2d1859a8f
3 changed files with 23 additions and 23 deletions

View File

@ -39,9 +39,9 @@ namespace KaraokePlayer.Classes
{
get { return string.Format("controllers/{0}/player/queue/0/", this.Id); }
}
private string FavoritesPath
private string MostPlayedPath
{
get { return string.Format("controllers/{0}/favorites/", this.Id); }
get { return string.Format("controllers/{0}/mostPlayed/", this.Id); }
}
public string Id { get; set; }
@ -119,7 +119,7 @@ namespace KaraokePlayer.Classes
{
CurrentSong = item.Song;
_songChanged(new ControllerSongChangedEventArgs(item.Song));
UpdateFavorites(item.Song);
UpdateMostPlayed(item.Song);
}
}
@ -134,33 +134,33 @@ namespace KaraokePlayer.Classes
_stateChanged(new ControllerStateChangedEventArgs(newstate));
}
private void UpdateFavorites(Song song)
private void UpdateMostPlayed(Song song)
{
//get favorites
FavoriteSong favorite = null;
List<FavoriteSong> favorites = _client.Get(FavoritesPath).ResultAs<List<FavoriteSong>>();
if (favorites == null) favorites = new List<FavoriteSong>();
//get MostPlayed
MostPlayedSong mostPlayed = null;
List<MostPlayedSong> mostPlays = _client.Get(MostPlayedPath).ResultAs<List<MostPlayedSong>>();
if (mostPlays == null) mostPlays = new List<MostPlayedSong>();
//unique song is based on the path
favorite = favorites.SingleOrDefault(f => f.Path == song.Path);
if (favorite == null)
mostPlayed = mostPlays.SingleOrDefault(f => f.Path == song.Path);
if (mostPlayed == null)
{
favorite = new FavoriteSong();
favorite.Artist = song.Artist;
favorite.Title = song.Title;
favorite.Genre = song.Genre;
favorite.Path = song.Path;
favorite.Year = song.Year;
favorite.Count = 1;
favorites.Add(favorite);
mostPlayed = new MostPlayedSong();
mostPlayed.Artist = song.Artist;
mostPlayed.Title = song.Title;
mostPlayed.Genre = song.Genre;
mostPlayed.Path = song.Path;
mostPlayed.Year = song.Year;
mostPlayed.Count = 1;
mostPlays.Add(mostPlayed);
}
else {
favorite.Count += 1;
mostPlayed.Count += 1;
}
//take the top 100 songs
var top100 = favorites.OrderByDescending(f => f.Count).Take(100);
_client.Set(FavoritesPath, top100);
var top100 = mostPlays.OrderByDescending(f => f.Count).Take(100);
_client.Set(MostPlayedPath, top100);
}
}

View File

@ -44,7 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FavoriteSong.cs" />
<Compile Include="MostPlayedSong.cs" />
<Compile Include="FileType.cs" />
<Compile Include="PlayerState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Herse.Models
{
public class FavoriteSong : Song
public class MostPlayedSong : Song
{
[JsonProperty("count")]
public int Count { get; set; }