added in songlist uploader
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
eec21c6ea4
commit
69caf72808
@ -119,7 +119,6 @@ namespace KaraokePlayer.Classes
|
||||
{
|
||||
CurrentSong = item.Song;
|
||||
_songChanged(new ControllerSongChangedEventArgs(item.Song));
|
||||
UpdateMostPlayed(item.Song);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,35 +132,5 @@ namespace KaraokePlayer.Classes
|
||||
_state = newstate;
|
||||
_stateChanged(new ControllerStateChangedEventArgs(newstate));
|
||||
}
|
||||
|
||||
private void UpdateMostPlayed(Song song)
|
||||
{
|
||||
//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
|
||||
mostPlayed = mostPlays.SingleOrDefault(f => f.Path == song.Path);
|
||||
if (mostPlayed == null)
|
||||
{
|
||||
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 {
|
||||
mostPlayed.Count += 1;
|
||||
}
|
||||
|
||||
//take the top 100 songs
|
||||
var top100 = mostPlays.OrderByDescending(f => f.Count).Take(100);
|
||||
_client.Set(MostPlayedPath, top100);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MostPlayedSong.cs" />
|
||||
<Compile Include="FileType.cs" />
|
||||
<Compile Include="PlayerState.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@ -52,6 +51,7 @@
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="Singer.cs" />
|
||||
<Compile Include="Song.cs" />
|
||||
<Compile Include="SongList.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Herse.Models
|
||||
{
|
||||
public class MostPlayedSong : Song
|
||||
{
|
||||
[JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
||||
28
Herse.Models/SongList.cs
Normal file
28
Herse.Models/SongList.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Herse.Models
|
||||
{
|
||||
public class SongList
|
||||
{
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("songs")]
|
||||
public List<SongListSong> Songs { get; set; }
|
||||
}
|
||||
public class SongListSong
|
||||
{
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[JsonProperty("artist")]
|
||||
public string Artist { get; set; }
|
||||
|
||||
[JsonProperty("position")]
|
||||
public int Position { get; set; }
|
||||
}
|
||||
}
|
||||
@ -10,14 +10,66 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO.Compression;
|
||||
using System.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SongCrawler
|
||||
{
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if(args.Length != 2)
|
||||
if(args.Last() == "-sl")
|
||||
{
|
||||
UploadSongList(args);
|
||||
} else
|
||||
{
|
||||
CrawlSongs(args);
|
||||
}
|
||||
}
|
||||
|
||||
private static void UploadSongList(string[] args)
|
||||
{
|
||||
string songlistpath = args[0];
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Console.WriteLine("usage: songcrawler jsonpath");
|
||||
return;
|
||||
}
|
||||
IFirebaseConfig config = new FirebaseConfig
|
||||
{
|
||||
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
||||
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
||||
};
|
||||
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
||||
string firepath = "SongList";
|
||||
Console.WriteLine("Loading current library");
|
||||
List<SongList> songList = client.Get(firepath).ResultAs<List<SongList>>();
|
||||
if (songList != null)
|
||||
Console.WriteLine(string.Format("{0} songList loaded", songList.Count));
|
||||
else
|
||||
songList = new List<SongList>();
|
||||
|
||||
List<SongList> localSongList = JsonConvert.DeserializeObject<List<SongList>>(File.ReadAllText(songlistpath));
|
||||
|
||||
foreach (SongList sl in localSongList)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine(string.Format("Checking for {0}", sl.Title));
|
||||
if (!songList.Any(s => s.Title.ToLower() == sl.Title.ToLower())) songList.Add(sl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
client.Set(firepath, songList);
|
||||
}
|
||||
|
||||
private static void CrawlSongs(string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Console.WriteLine("usage: songcrawler partyid songspath");
|
||||
return;
|
||||
@ -52,14 +104,15 @@ namespace SongCrawler
|
||||
{
|
||||
song = MakeSong(filepath);
|
||||
Console.WriteLine(string.Format("{0:000000}/{1} - {2}", i, files.Count, song.Title));
|
||||
if(!songs.Any(s => s.Path == song.Path)) songs.Add(song);
|
||||
if (!songs.Any(s => s.Path.ToLower() == song.Path.ToLower())) songs.Add(song);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
client.Set(firepath, songs);
|
||||
|
||||
}
|
||||
|
||||
private static Song MakeSong(string filepath)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user