added billboard
Signed-off-by: Matt Bruce <Matt Bruce>
This commit is contained in:
parent
8a51dd0336
commit
9135b489b7
18
BillboardPlaylistUpdater/App.config
Normal file
18
BillboardPlaylistUpdater/App.config
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="Firebase.Secret" value="9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO" />
|
||||
<add key="Firebase.Path" value="https://herse.firebaseio.com/" />
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
111
BillboardPlaylistUpdater/BillboardPlaylistUpdater.csproj
Normal file
111
BillboardPlaylistUpdater/BillboardPlaylistUpdater.csproj
Normal file
@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{AE892DF7-C43E-422A-B82E-29B5E6E0341C}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BillboardPlaylistUpdater</RootNamespace>
|
||||
<AssemblyName>BillboardPlaylistUpdater</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FireSharp, Version=2.0.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FireSharp.2.0.4\lib\portable-net45+sl5+wp8+win8\FireSharp.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Herse.Models\Herse.Models.csproj">
|
||||
<Project>{f02eda00-aa8f-47ef-ac7f-66dc315aa13d}</Project>
|
||||
<Name>Herse.Models</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>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}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
155
BillboardPlaylistUpdater/Program.cs
Normal file
155
BillboardPlaylistUpdater/Program.cs
Normal file
@ -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> songList = client.Get(firepath).ResultAs<List<SongList>>();
|
||||
if (songList != null)
|
||||
Console.WriteLine(string.Format("{0} songList loaded", songList.Count));
|
||||
else
|
||||
songList = new List<SongList>();
|
||||
|
||||
|
||||
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<SongList> localSongList = new List<SongList>();
|
||||
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<SongListSong> songs = Parse(title, html);
|
||||
if (songs != null)
|
||||
{
|
||||
list = new SongList();
|
||||
list.Title = title;
|
||||
list.Songs = songs;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static List<SongListSong> Parse(string name, string html)
|
||||
{
|
||||
List<SongListSong> 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<SongListSong>();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
BillboardPlaylistUpdater/Properties/AssemblyInfo.cs
Normal file
36
BillboardPlaylistUpdater/Properties/AssemblyInfo.cs
Normal file
@ -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")]
|
||||
10
BillboardPlaylistUpdater/packages.config
Normal file
10
BillboardPlaylistUpdater/packages.config
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AngleSharp" version="0.9.9" targetFramework="net452" />
|
||||
<package id="FireSharp" version="2.0.4" targetFramework="net452" />
|
||||
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net452" />
|
||||
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net452" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net452" />
|
||||
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
|
||||
</packages>
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user