updated billboard algo
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
946bdd9125
commit
2f4e76d0a8
@ -23,7 +23,7 @@ namespace BillboardPlaylistUpdater
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//args = new string[] { "mbrucedogs" };
|
||||
args = new string[] { "mbrucedogs" };
|
||||
if (args.Length != 1)
|
||||
{
|
||||
Console.WriteLine("usage: songcrawler partyid songspath");
|
||||
@ -74,12 +74,11 @@ namespace BillboardPlaylistUpdater
|
||||
|
||||
static void UpdateCurrentCharts()
|
||||
{
|
||||
SongList hot100 = Download("Hot 100", "http://www.billboard.com/charts/hot-100");
|
||||
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");
|
||||
|
||||
SongList hot100 = Download("Hot 100", "https://www.billboard.com/charts/hot-100");
|
||||
SongList pop = Download("Pop-Songs", "https://www.billboard.com/charts/pop-songs");
|
||||
SongList rock = Download("Rock-Songs", "https://www.billboard.com/charts/rock-songs");
|
||||
SongList country = Download("Country-Songs", "https://www.billboard.com/charts/country-songs");
|
||||
SongList hiphop = Download("R-B-Hip-Hop-Songs", "https://www.billboard.com/charts/r-b-hip-hop-songs");
|
||||
List<SongList> localSongList = new List<SongList>();
|
||||
localSongList.Add(pop);
|
||||
localSongList.Add(rock);
|
||||
@ -185,38 +184,42 @@ namespace BillboardPlaylistUpdater
|
||||
List<SongListSong> songs = null;
|
||||
var parser = new HtmlParser();
|
||||
var document = parser.Parse(html);
|
||||
var articles = document.QuerySelectorAll("article.chart-row");
|
||||
//2-?
|
||||
var articles = document.QuerySelectorAll("div.chart-list-item ");
|
||||
if (articles.Count() > 0)
|
||||
{
|
||||
Console.WriteLine("Found " + articles.Count() + " Songs");
|
||||
songs = new List<SongListSong>();
|
||||
}
|
||||
|
||||
//1
|
||||
var number1artist = document.QuerySelectorAll("div.chart-number-one__artist ").First().InnerHtml.TrimStart().TrimEnd();
|
||||
var number1title = document.QuerySelectorAll("div.chart-number-one__title ").First().InnerHtml.TrimStart().TrimEnd();
|
||||
var number1 = new SongListSong();
|
||||
number1.Artist = number1artist;
|
||||
number1.Title = number1title;
|
||||
number1.Position = 1;
|
||||
if (number1artist.Contains("href"))
|
||||
{
|
||||
var start = number1artist.IndexOf(">") + 1;
|
||||
var end = number1artist.IndexOf("<",1) - 1;
|
||||
var art = number1artist.Substring(start, end - start);
|
||||
number1.Artist = art.TrimStart().TrimEnd();
|
||||
}
|
||||
songs.Add(number1);
|
||||
|
||||
|
||||
var i = 1;
|
||||
foreach (var article in articles)
|
||||
{
|
||||
var title = article.QuerySelector("h2.chart-row__song");
|
||||
var artist = article.QuerySelector("span.chart-row__artist");
|
||||
var position = article.QuerySelector("span.chart-row__current-week");
|
||||
if (artist == null)
|
||||
{
|
||||
artist = article.QuerySelector("h3.chart-row__artist");
|
||||
}
|
||||
if (artist == null)
|
||||
{
|
||||
artist = article.QuerySelector("a.chart-row__artist");
|
||||
}
|
||||
if (title != null && artist != null && position != null)
|
||||
{
|
||||
SongListSong song = new SongListSong();
|
||||
song.Artist = WebUtility.HtmlDecode(artist.InnerHtml.Trim().Replace("\n", ""));
|
||||
song.Title = WebUtility.HtmlDecode(title.InnerHtml.Trim().Replace("\n", ""));
|
||||
song.Position = Int32.Parse(position.InnerHtml.Trim());
|
||||
var title = article.Attributes["data-title"].Value;
|
||||
var artist = article.Attributes["data-artist"].Value;
|
||||
var position = article.Attributes["data-rank"].Value;
|
||||
var song = new SongListSong();
|
||||
song.Artist = artist;
|
||||
song.Title = title;
|
||||
song.Position = Convert.ToInt32(position);
|
||||
songs.Add(song);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("couldn't find objects in " + title + " for Song #" + i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
Console.Write("Parsed " + songs.Count() + " Songs");
|
||||
@ -226,8 +229,13 @@ namespace BillboardPlaylistUpdater
|
||||
static string DownloadHtml(string url)
|
||||
{
|
||||
string data = null;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
||||
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = "GET";
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Stream receiveStream = response.GetResponseStream();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user