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)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
//args = new string[] { "mbrucedogs" };
|
args = new string[] { "mbrucedogs" };
|
||||||
if (args.Length != 1)
|
if (args.Length != 1)
|
||||||
{
|
{
|
||||||
Console.WriteLine("usage: songcrawler partyid songspath");
|
Console.WriteLine("usage: songcrawler partyid songspath");
|
||||||
@ -74,12 +74,11 @@ namespace BillboardPlaylistUpdater
|
|||||||
|
|
||||||
static void UpdateCurrentCharts()
|
static void UpdateCurrentCharts()
|
||||||
{
|
{
|
||||||
SongList hot100 = Download("Hot 100", "http://www.billboard.com/charts/hot-100");
|
SongList hot100 = Download("Hot 100", "https://www.billboard.com/charts/hot-100");
|
||||||
SongList pop = Download("Pop-Songs", "http://www.billboard.com/charts/pop-songs");
|
SongList pop = Download("Pop-Songs", "https://www.billboard.com/charts/pop-songs");
|
||||||
SongList rock = Download("Rock-Songs", "http://www.billboard.com/charts/rock-songs");
|
SongList rock = Download("Rock-Songs", "https://www.billboard.com/charts/rock-songs");
|
||||||
SongList country = Download("Country-Songs", "http://www.billboard.com/charts/country-songs");
|
SongList country = Download("Country-Songs", "https://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 hiphop = Download("R-B-Hip-Hop-Songs", "https://www.billboard.com/charts/r-b-hip-hop-songs");
|
||||||
|
|
||||||
List<SongList> localSongList = new List<SongList>();
|
List<SongList> localSongList = new List<SongList>();
|
||||||
localSongList.Add(pop);
|
localSongList.Add(pop);
|
||||||
localSongList.Add(rock);
|
localSongList.Add(rock);
|
||||||
@ -185,38 +184,42 @@ namespace BillboardPlaylistUpdater
|
|||||||
List<SongListSong> songs = null;
|
List<SongListSong> songs = null;
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
var document = parser.Parse(html);
|
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)
|
if (articles.Count() > 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Found " + articles.Count() + " Songs");
|
Console.WriteLine("Found " + articles.Count() + " Songs");
|
||||||
songs = new List<SongListSong>();
|
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;
|
var i = 1;
|
||||||
foreach (var article in articles)
|
foreach (var article in articles)
|
||||||
{
|
{
|
||||||
var title = article.QuerySelector("h2.chart-row__song");
|
var title = article.Attributes["data-title"].Value;
|
||||||
var artist = article.QuerySelector("span.chart-row__artist");
|
var artist = article.Attributes["data-artist"].Value;
|
||||||
var position = article.QuerySelector("span.chart-row__current-week");
|
var position = article.Attributes["data-rank"].Value;
|
||||||
if (artist == null)
|
var song = new SongListSong();
|
||||||
{
|
song.Artist = artist;
|
||||||
artist = article.QuerySelector("h3.chart-row__artist");
|
song.Title = title;
|
||||||
}
|
song.Position = Convert.ToInt32(position);
|
||||||
if (artist == null)
|
songs.Add(song);
|
||||||
{
|
|
||||||
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());
|
|
||||||
songs.Add(song);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("couldn't find objects in " + title + " for Song #" + i);
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
Console.Write("Parsed " + songs.Count() + " Songs");
|
Console.Write("Parsed " + songs.Count() + " Songs");
|
||||||
@ -226,8 +229,13 @@ namespace BillboardPlaylistUpdater
|
|||||||
static string DownloadHtml(string url)
|
static string DownloadHtml(string url)
|
||||||
{
|
{
|
||||||
string data = null;
|
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);
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
|
request.Method = "GET";
|
||||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||||
|
|
||||||
if (response.StatusCode == HttpStatusCode.OK)
|
if (response.StatusCode == HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
Stream receiveStream = response.GetResponseStream();
|
Stream receiveStream = response.GetResponseStream();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user