added favorites
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
0097334902
commit
08224b0801
@ -34,6 +34,10 @@ namespace KaraokePlayer.Classes
|
|||||||
{
|
{
|
||||||
get { return string.Format("controllers/{0}/player/queue/0/", this.Id); }
|
get { return string.Format("controllers/{0}/player/queue/0/", this.Id); }
|
||||||
}
|
}
|
||||||
|
private string FavoritesPath
|
||||||
|
{
|
||||||
|
get { return string.Format("controllers/{0}/favorites/", this.Id); }
|
||||||
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public Song CurrentSong { get; set; }
|
public Song CurrentSong { get; set; }
|
||||||
@ -92,13 +96,14 @@ namespace KaraokePlayer.Classes
|
|||||||
|
|
||||||
private void CurrentSongDidChange()
|
private void CurrentSongDidChange()
|
||||||
{
|
{
|
||||||
var response = _client.Get(CurrentSongPath);
|
var response = _client.Get(CurrentSongPath);
|
||||||
var item = response.ResultAs<QueueItem>();
|
var item = response.ResultAs<QueueItem>();
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
if (CurrentSong == null || CurrentSong.Path != item.Song.Path)
|
if (CurrentSong == null || CurrentSong.Path != item.Song.Path)
|
||||||
{
|
{
|
||||||
CurrentSong = item.Song;
|
CurrentSong = item.Song;
|
||||||
_songChanged(new ControllerSongChangedEventArgs(item.Song));
|
_songChanged(new ControllerSongChangedEventArgs(item.Song));
|
||||||
|
UpdateFavorites(item.Song);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,5 +113,35 @@ namespace KaraokePlayer.Classes
|
|||||||
_state = newstate;
|
_state = newstate;
|
||||||
_stateChanged(new ControllerStateChangedEventArgs(newstate));
|
_stateChanged(new ControllerStateChangedEventArgs(newstate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateFavorites(Song song)
|
||||||
|
{
|
||||||
|
//get favorites
|
||||||
|
FavoriteSong favorite = null;
|
||||||
|
List<FavoriteSong> favorites = _client.Get(FavoritesPath).ResultAs<List<FavoriteSong>>();
|
||||||
|
if (favorites == null) favorites = new List<FavoriteSong>();
|
||||||
|
|
||||||
|
//unique song is based on the path
|
||||||
|
favorite = favorites.SingleOrDefault(f => f.Path == song.Path);
|
||||||
|
if (favorite == 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);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
favorite.Count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//take the top 100 songs
|
||||||
|
var top100 = favorites.OrderByDescending(f => f.Count).Take(100);
|
||||||
|
_client.Set(FavoritesPath, top100);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
Herse.Models/FavoriteSong.cs
Normal file
15
Herse.Models/FavoriteSong.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Herse.Models
|
||||||
|
{
|
||||||
|
public class FavoriteSong : Song
|
||||||
|
{
|
||||||
|
[JsonProperty("count")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -44,6 +44,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="FavoriteSong.cs" />
|
||||||
<Compile Include="FileType.cs" />
|
<Compile Include="FileType.cs" />
|
||||||
<Compile Include="PlayerState.cs" />
|
<Compile Include="PlayerState.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user