diff --git a/BillboardPlaylistUpdater/App.config b/BillboardPlaylistUpdater/App.config new file mode 100644 index 0000000..5ea4469 --- /dev/null +++ b/BillboardPlaylistUpdater/App.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BillboardPlaylistUpdater/BillboardPlaylistUpdater.csproj b/BillboardPlaylistUpdater/BillboardPlaylistUpdater.csproj new file mode 100644 index 0000000..bc48389 --- /dev/null +++ b/BillboardPlaylistUpdater/BillboardPlaylistUpdater.csproj @@ -0,0 +1,111 @@ + + + + + Debug + AnyCPU + {AE892DF7-C43E-422A-B82E-29B5E6E0341C} + Exe + Properties + BillboardPlaylistUpdater + BillboardPlaylistUpdater + v4.5.2 + 512 + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll + True + + + ..\packages\FireSharp.2.0.4\lib\portable-net45+sl5+wp8+win8\FireSharp.dll + True + + + ..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll + True + + + ..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll + True + + + ..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll + True + + + ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + True + + + + + + + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll + True + + + ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll + True + + + + + + + + + + + + + + + + + + + + {f02eda00-aa8f-47ef-ac7f-66dc315aa13d} + Herse.Models + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/BillboardPlaylistUpdater/Program.cs b/BillboardPlaylistUpdater/Program.cs new file mode 100644 index 0000000..d332240 --- /dev/null +++ b/BillboardPlaylistUpdater/Program.cs @@ -0,0 +1,155 @@ +using AngleSharp.Parser.Html; +using FireSharp.Config; +using FireSharp.Interfaces; +using Herse.Models; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace BillboardPlaylistUpdater +{ + class Program + { + + static void Main(string[] args) + { + 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(); + + + SongList pop = Download("Pop-Songs","http://www.billboard.com/charts/pop-songs"); + SongList rock = Download("Rock-Songs","http://www.billboard.com/charts/rock-songs"); + SongList country = Download("Country-Songs", "http://www.billboard.com/charts/country-songs"); + SongList hiphop = Download("R-B-Hip-Hop-Songs", "http://www.billboard.com/charts/r-b-hip-hop-songs"); + + List localSongList = new List(); + localSongList.Add(pop); + localSongList.Add(rock); + localSongList.Add(country); + localSongList.Add(hiphop); + + foreach (SongList sl in localSongList) + { + try + { + Console.WriteLine(string.Format("Checking for {0}", sl.Title)); + var found = songList.Where(s => s.Title.ToLower() == sl.Title.ToLower()); + if(found != null) + { + var items = found.ToList(); + foreach (var item in items) + { + songList.Remove(item); + } + } + songList.Add(sl); + + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + client.Set(firepath, songList); + + } + + static SongList Download(string listName, string url) + { + DateTime now = DateTime.Now; + string title = now.Year + " - " + listName; + + Console.WriteLine("Downloading " + title); + + string html = DownloadHtml(url); + + SongList list = null; + List songs = Parse(title, html); + if (songs != null) + { + list = new SongList(); + list.Title = title; + list.Songs = songs; + } + return list; + } + + static List Parse(string name, string html) + { + List songs = null; + var parser = new HtmlParser(); + var document = parser.Parse(html); + var articles = document.QuerySelectorAll("article.chart-row"); + if(articles.Count() > 0) { + Console.WriteLine("Found " + articles.Count() + " Songs"); + songs = new List(); + } + var i = 1; + foreach (var article in articles) + { + var title = article.QuerySelector("h2.chart-row__song"); + var artist = article.QuerySelector("a.chart-row__artist"); + var position = article.QuerySelector("span.chart-row__current-week"); + if (artist == null) + { + artist = article.QuerySelector("h3.chart-row__artist"); + } + if(title != null && artist != null && position != null) + { + SongListSong song = new SongListSong(); + song.Artist = artist.InnerHtml.Trim().Replace("\n",""); + song.Title = title.InnerHtml.Trim().Replace("\n",""); + song.Position = Int32.Parse(position.InnerHtml.Trim()); + songs.Add(song); + } else + { + Console.WriteLine("couldn't find objects in " + title + " for Song #" + i); + } + i++; + } + Console.Write("Parsed " + songs.Count() + " Songs"); + return songs; + } + + static string DownloadHtml(string url) + { + string data = null; + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + if(response.StatusCode == HttpStatusCode.OK) + { + Stream receiveStream = response.GetResponseStream(); + StreamReader readStream = null; + if(response.CharacterSet == null) + { + readStream = new StreamReader(receiveStream); + }else + { + readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); + } + data = readStream.ReadToEnd(); + + response.Close(); + readStream.Close(); + } + return data; + } + } +} diff --git a/BillboardPlaylistUpdater/Properties/AssemblyInfo.cs b/BillboardPlaylistUpdater/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..398ecc2 --- /dev/null +++ b/BillboardPlaylistUpdater/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("BillboardPlaylistUpdater")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BillboardPlaylistUpdater")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ae892df7-c43e-422a-b82e-29b5e6e0341c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BillboardPlaylistUpdater/packages.config b/BillboardPlaylistUpdater/packages.config new file mode 100644 index 0000000..d4752f7 --- /dev/null +++ b/BillboardPlaylistUpdater/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/KaraokePlayer.sln b/KaraokePlayer.sln index f2fdfed..f0ec294 100644 --- a/KaraokePlayer.sln +++ b/KaraokePlayer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CdgLib", "CdgLib\CdgLib.csproj", "{3203DFD2-DA5B-47B3-B009-18DD9C401FC3}" EndProject @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SongCrawler", "SongCrawler\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Herse.Models", "Herse.Models\Herse.Models.csproj", "{F02EDA00-AA8F-47EF-AC7F-66DC315AA13D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BillboardPlaylistUpdater", "BillboardPlaylistUpdater\BillboardPlaylistUpdater.csproj", "{AE892DF7-C43E-422A-B82E-29B5E6E0341C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {F02EDA00-AA8F-47EF-AC7F-66DC315AA13D}.Debug|Any CPU.Build.0 = Debug|Any CPU {F02EDA00-AA8F-47EF-AC7F-66DC315AA13D}.Release|Any CPU.ActiveCfg = Release|Any CPU {F02EDA00-AA8F-47EF-AC7F-66DC315AA13D}.Release|Any CPU.Build.0 = Release|Any CPU + {AE892DF7-C43E-422A-B82E-29B5E6E0341C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE892DF7-C43E-422A-B82E-29B5E6E0341C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE892DF7-C43E-422A-B82E-29B5E6E0341C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE892DF7-C43E-422A-B82E-29B5E6E0341C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE