From b7369213f2dd7be8d9c195a0c298f84f8a740bbc Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Sun, 20 Nov 2016 17:47:21 -0600 Subject: [PATCH] updated Signed-off-by: Matt Bruce --- SongCrawler/Program.cs | 154 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 3 deletions(-) diff --git a/SongCrawler/Program.cs b/SongCrawler/Program.cs index c642777..ce687de 100644 --- a/SongCrawler/Program.cs +++ b/SongCrawler/Program.cs @@ -19,10 +19,12 @@ namespace SongCrawler { static void Main(string[] args) { - if(args.Last() == "-sl") + //FindDuplicates(args); + if (args.Last() == "-sl") { UploadSongList(args); - } else + } + else { CrawlSongs(args); } @@ -91,9 +93,9 @@ namespace SongCrawler songs = new List(); List files = new List(); + files.AddRange(FindFiles("mp4", songpath)); files.AddRange(FindFiles("mp3", songpath)); files.AddRange(FindFiles("zip", songpath)); - files.AddRange(FindFiles("mp4", songpath)); Song song = null; int i = 0; @@ -115,6 +117,152 @@ namespace SongCrawler } + private static void CrawlNoDupeSongs(string[] args) + { + if (args.Length != 2) + { + Console.WriteLine("usage: songcrawler partyid songspath"); + return; + } + string controller = args[0]; + string songpath = args[1]; + IFirebaseConfig config = new FirebaseConfig + { + AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"], + BasePath = ConfigurationManager.AppSettings["Firebase.Path"] + }; + FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config); + string firepath = string.Format("controllers/{0}/songs", controller); + Console.WriteLine("Loading current library"); + List songs = new List(); + + List files = new List(); + files.AddRange(FindFiles("mp4", songpath)); + files.AddRange(FindFiles("mp3", songpath)); + files.AddRange(FindFiles("zip", songpath)); + + Song song = null; + int i = 0; + foreach (string filepath in files) + { + i++; + try + { + song = MakeSong(filepath); + Console.WriteLine(string.Format("{0:000000}/{1} - {2}", i, files.Count(), song.Title)); + if (!songs.Any(s => s.Title.ToLower() == song.Title.ToLower() && s.Artist.ToLower() == song.Artist.ToLower())) songs.Add(song); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + Console.WriteLine(string.Format("{0:000000}/{1} unique songs", songs.Count(), files.Count())); + client.Set(firepath, songs); + } + + private static void FindDuplicates(string[] args) + { + string songpath = @"D:\KaraokeData\Karaoke"; // args[0]; + List songs = songs = new List(); + + List files = new List(); + files.AddRange(FindFiles("mp3", songpath)); + files.AddRange(FindFiles("zip", songpath)); + files.AddRange(FindFiles("mp4", songpath)); + + Song song = null; + int i = 0; + foreach (string filepath in files) + { + i++; + try + { + song = MakeSong(filepath); + Console.WriteLine(string.Format("{0:000000}/{1} - {2}", i, files.Count, song.Title)); + songs.Add(song); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + i = 0; + Dictionary> dupes = new Dictionary>(); + foreach (var localsong in songs) + { + i++; + Console.WriteLine(string.Format("Checking for {0:000000}/{1}) {2} - {3}", i, files.Count, localsong.Artist, localsong.Title)); + if (!string.IsNullOrEmpty(localsong.Artist) && !string.IsNullOrEmpty(localsong.Title)) + { + string key = localsong.Artist + " - " + localsong.Title; + if (dupes.ContainsKey(key) == false) + { + var dsongs = songs.Where(s => s.Title.ToLower() == localsong.Title.ToLower() && s.Artist.ToLower() == localsong.Artist.ToLower()); + if (dsongs.Count() > 1) + { + List d = new List(); + d.AddRange(dsongs.ToList()); + dupes.Add(key, d); + } + } + } + } + File.WriteAllText(@"D:\dupliates.json", JsonConvert.SerializeObject(dupes.OrderBy(o => o.Key))); + } + private static void DisableDuplicates(string[] args) + { + if (args.Length != 1) + { + Console.WriteLine("usage: songcrawler partyid songspath"); + return; + } + string controller = args[0]; + IFirebaseConfig config = new FirebaseConfig + { + AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"], + BasePath = ConfigurationManager.AppSettings["Firebase.Path"] + }; + FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config); + string firepath = string.Format("controllers/{0}/songs", controller); + Console.WriteLine("Loading current library"); + List songs = client.Get(firepath).ResultAs>(); + + Dictionary> dupes = new Dictionary>(); + + int i = 0; + foreach (var localsong in songs) + { + i++; + Console.WriteLine(string.Format("Checking for {0:000000}/{1}) {2} - {3}", i, songs.Count, localsong.Artist, localsong.Title)); + if (!string.IsNullOrEmpty(localsong.Artist) && !string.IsNullOrEmpty(localsong.Title) && localsong.Disabled == false && localsong.Path.Contains(".mp4")) + { + string key = localsong.Artist + " - " + localsong.Title; + if (dupes.ContainsKey(key) == false) + { + var dsongs = songs.Where(s => + s.Path != localsong.Path && + s.Title.ToLower() == localsong.Title.ToLower() && + s.Artist.ToLower() == localsong.Artist.ToLower() && + localsong.Disabled == false); + + if (dsongs.Count() > 1) + { + List d = new List(); + d.AddRange(dsongs.ToList()); + dupes.Add(key, d); + } + foreach (var item in dsongs) + { + item.Disabled = true; + } + } + } + } + client.Set(firepath, songs); + } + private static Song MakeSong(string filepath) {