From 69caf72808555653967b47ff2650778f7705d5cd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Sun, 2 Oct 2016 10:38:01 -0500 Subject: [PATCH] added in songlist uploader Signed-off-by: Matt Bruce --- FirebaseKaraoke/FirebaseController.cs | 31 -------------- Herse.Models/Herse.Models.csproj | 2 +- Herse.Models/MostPlayedSong.cs | 15 ------- Herse.Models/SongList.cs | 28 ++++++++++++ SongCrawler/Program.cs | 61 +++++++++++++++++++++++++-- 5 files changed, 86 insertions(+), 51 deletions(-) delete mode 100644 Herse.Models/MostPlayedSong.cs create mode 100644 Herse.Models/SongList.cs diff --git a/FirebaseKaraoke/FirebaseController.cs b/FirebaseKaraoke/FirebaseController.cs index 9429ba0..abe8c32 100644 --- a/FirebaseKaraoke/FirebaseController.cs +++ b/FirebaseKaraoke/FirebaseController.cs @@ -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 mostPlays = _client.Get(MostPlayedPath).ResultAs>(); - if (mostPlays == null) mostPlays = new List(); - - //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); - - } } } diff --git a/Herse.Models/Herse.Models.csproj b/Herse.Models/Herse.Models.csproj index 47564ed..09be270 100644 --- a/Herse.Models/Herse.Models.csproj +++ b/Herse.Models/Herse.Models.csproj @@ -44,7 +44,6 @@ - @@ -52,6 +51,7 @@ + diff --git a/Herse.Models/MostPlayedSong.cs b/Herse.Models/MostPlayedSong.cs deleted file mode 100644 index af42dd3..0000000 --- a/Herse.Models/MostPlayedSong.cs +++ /dev/null @@ -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; } - } -} diff --git a/Herse.Models/SongList.cs b/Herse.Models/SongList.cs new file mode 100644 index 0000000..1cb8eb1 --- /dev/null +++ b/Herse.Models/SongList.cs @@ -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 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; } + } +} diff --git a/SongCrawler/Program.cs b/SongCrawler/Program.cs index d30778e..c642777 100644 --- a/SongCrawler/Program.cs +++ b/SongCrawler/Program.cs @@ -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 = client.Get(firepath).ResultAs>(); + if (songList != null) + Console.WriteLine(string.Format("{0} songList loaded", songList.Count)); + else + songList = new List(); + + List localSongList = JsonConvert.DeserializeObject>(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; @@ -43,7 +95,7 @@ namespace SongCrawler files.AddRange(FindFiles("zip", songpath)); files.AddRange(FindFiles("mp4", songpath)); - Song song = null; + Song song = null; int i = 0; foreach (string filepath in files) { @@ -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)