private void processBandHomonymsPage(EMParseBandHomonymsPage page, string band, string urlBand, List <string> existingAlbumsNamesYears) { int nbBandHomonyms = page.HomonymsURLs.Count; if (nbBandHomonyms == 0) // no homonyms { processBandPage(band, urlBand, existingAlbumsNamesYears); } else { // process all bands homonyms Tools.LogEvent(nbBandHomonyms + " HOMONYMS FOUND FOR BAND " + band); foreach (string homonymURL in page.HomonymsURLs) { processBandPage(band, homonymURL, existingAlbumsNamesYears); } } }
private void processBandFrontPage(string bandNameOrUrl, string existingBandURLSuffix = "") { string urlBand = ""; string logText = ""; bool isURL = Tools.IsStringURL(bandNameOrUrl); if (isURL) { // search by band URL Tools.LogEvent(" "); Tools.LogEvent("SEARCHING URL " + bandNameOrUrl + "..."); urlBand = bandNameOrUrl; // get band name from URL string sourceHTMLBandPage = Tools.GetWebPageSourceHTML(urlBand); if (String.IsNullOrEmpty(sourceHTMLBandPage)) { Tools.LogEvent(" Page not found for " + bandNameOrUrl); return; } EMParseBandHomonymsPage page = new EMParseBandHomonymsPage(sourceHTMLBandPage); string band = page.Band; if (String.IsNullOrEmpty(band)) // no homonyms { band = page.GetBandNameFromNonHomonymPage(); } if (String.IsNullOrEmpty(band)) { Tools.LogEvent(" Band name not found for " + bandNameOrUrl); return; } sendProcessBandParams(band); // search if band already exists // if yes, get existing band albums List <string> existingAlbumsNamesYears = new List <string>(); if (downloadNewAlbumsOnly_) { List <string> processedBandURLs = new List <string>(); foreach (GenreURL item in comboboxGenres.Items) { string genre = item.Genre; // skip sub-genres if (genre.StartsWith(" ")) { continue; } string genreURL = item.Url; string urlSite = "https://www.metalmusicarchives.com"; string urlGenre = urlSite + genreURL; string sourceHTML = Tools.GetWebPageSourceHTML(urlGenre); MMAParseGenreBands parsedGenreBands = new MMAParseGenreBands(sourceHTML); int indexExistingBand = 0; foreach (string existingBand in parsedGenreBands.GenreBands) { if (existingBand.Equals(band, StringComparison.OrdinalIgnoreCase)) { // ok, found in genre, check if already processed string bandURLSuffix = parsedGenreBands.GenreBandsURLs[indexExistingBand]; // check if band already processed bool processed = false; foreach (string processedBandURL in processedBandURLs) { if (String.Compare(bandURLSuffix, processedBandURL, StringComparison.OrdinalIgnoreCase) == 0) { processed = true; break; } } // skip if already processed if (processed) { continue; } // get existing band albums processedBandURLs.Add(bandURLSuffix); existingAlbumsNamesYears.AddRange(getExistingAlbums(band, bandURLSuffix)); } indexExistingBand++; } } } // process band homonyms processBandHomonymsPage(page, band, urlBand, existingAlbumsNamesYears); } else { // search by band prefix sendProcessBandParams(bandNameOrUrl); logText = String.IsNullOrEmpty(existingBandURLSuffix) ? "BAND " + bandNameOrUrl + " NOT EXISTING" : " "; Tools.LogEvent(logText); Tools.LogEvent("PROCESSING BAND " + bandNameOrUrl + "..."); // build URL suffix string bandSuffix = bandNameOrUrl.Replace(' ', '_'); urlBand = "https://www.metal-archives.com/bands/" + bandSuffix; logText = downloadNewAlbumsOnly_ ? " Searching new albums of " + bandNameOrUrl + "..." : " Searching all albums of " + bandNameOrUrl + "..."; Tools.LogEvent(logText); // parse existing albums List <string> existingAlbumsNamesYears = getExistingAlbums(bandNameOrUrl, existingBandURLSuffix); // search for band homonyms string sourceHTMLBandPage = Tools.GetWebPageSourceHTML(urlBand); if (String.IsNullOrEmpty(sourceHTMLBandPage)) { Tools.LogEvent(" Page not found for " + bandNameOrUrl); return; } // process band homonyms EMParseBandHomonymsPage page = new EMParseBandHomonymsPage(sourceHTMLBandPage); string band = String.IsNullOrEmpty(page.Band) ? bandNameOrUrl : page.Band; processBandHomonymsPage(page, band, urlBand, existingAlbumsNamesYears); } }