Beispiel #1
0
        private static void GetMusicScores(string banapassId, RevScraperClient client)
        {
            Console.WriteLine("Getting songs...");
            IReadOnlyCollection <Uri> songUris = client.GetSongUris();

            Console.WriteLine($"Got {songUris.Count} songs.");

            List <MusicDetail> musicDetails = new List <MusicDetail>(songUris.Count);
            int i = 1;

            foreach (Uri songUri in songUris)
            {
                Console.WriteLine($"Getting song {i} of {songUris.Count}...");
                musicDetails.Add(client.GetMusicDetail(songUri));
                i++;
            }

            string musicScoresFilename = string.Format(CultureInfo.InvariantCulture, MusicScoresFilenamePattern, banapassId);

            Console.WriteLine($"Writing scores to {musicScoresFilename}...");

            using (FileStream stream = File.Open(musicScoresFilename, FileMode.Create))
            {
                using (StreamWriter streamWriter = new StreamWriter(stream, Encoding.UTF8))
                {
                    MusicDetail.SerializeHeadersToCSV(streamWriter);

                    foreach (MusicDetail musicDetail in musicDetails)
                    {
                        musicDetail.SerializeToCSV(streamWriter);
                    }
                }
            }
        }
Beispiel #2
0
        public static MusicDetail ParseFromElement(HtmlNode element, string id)
        {
            MusicDetail detail = new MusicDetail();
            detail.Id = id;

            HtmlNode container = element.ChildNodes[3];
            detail.Title = HtmlEntity.DeEntitize(container.ChildNodes[1].InnerText.Trim());
            detail.Artist = HtmlEntity.DeEntitize(container.ChildNodes[3].InnerText.Trim());
            detail.BPM = HtmlEntity.DeEntitize(container.ChildNodes[5].SelectSingleNode("text()").InnerText.Trim());

            return detail;
        }
        public MusicDetail GetMusicDetail(Uri uri)
        {
            string id             = _idRegex.Match(uri.ToString()).Groups[1].Value;
            string responseString = DownloadString(uri);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(responseString);

            HtmlNode    musicDetailElement = document.DocumentNode.SelectNodes("//div[contains(@class, 'pdMusicDetail')]")[0];
            MusicDetail musicDetail        = MusicDetail.ParseFromElement(musicDetailElement, id);

            HtmlNodeCollection charts = document.DocumentNode.SelectNodes("//div[@class='pdm-result']");

            foreach (HtmlNode chartElement in charts)
            {
                ChartScore chart = ChartScore.ParseFromElement(chartElement);
                musicDetail.AddChart(chart);
            }

            return(musicDetail);
        }