public List <RomData> GetRomsData(int console, Dictionary <string, string> imageMap = null) { List <RomData> InnerList = new List <RomData>(); if (imageMap == null) { imageMap = new Dictionary <string, string>(); } var document = new HtmlWeb(); var html = document.LoadFromWebAsync(GetBasePath() + GetConsolesLinks()[Convert.ToInt32(console)]).Result; var container = html.DocumentNode.Descendants().Where(ax => ax.Name == "tbody").ToList(); var children = container[0].ChildNodes.Where((node) => node.Name == "tr").ToList(); int foundCount = 0; foreach (var child in children) { var romCols = child.ChildNodes.Where(ax => ax.Name == "td").ToList(); if (romCols.Count > 0) { var nameRow = romCols[0]; var sizeRow = romCols[1]; if (!ExtractionHelpers.IsNameValid(nameRow.InnerText)) { continue; } var linkElement = nameRow.ChildNodes.Where(ax => ax.Name == "a").First(); var link = linkElement.Attributes["href"].Value; var name = ExtractionHelpers.ExtractName(link, console); var thumbnail = ExtractionHelpers.ExtractThumbnail(console, name, imageMap); string region = ExtractionHelpers.ExtractRegion(name); if (thumbnail != null) { foundCount++; InnerList.Add(new RomData { Console = ((Enums.Consoles)console).ToString().Replace('_', ' '), Name = name, Portrait = thumbnail, Region = region }); } } } Console.WriteLine(foundCount + " Portraits found of " + children.Count + " Roms -> " + (children.Count - foundCount) + "Portraits not found"); return(InnerList); }
public List <RomData> GetRomsData(int consoleCode, Dictionary <string, string> imageMap = null) { List <string> unmatch = new List <string>(); List <RomData> InnerList = new List <RomData>(); if (imageMap == null) { imageMap = new Dictionary <string, string>(); } var document = new HtmlWeb(); var url = GetBasePath() + GetConsolesLinks()[Convert.ToInt32(consoleCode)]; var html = document.LoadFromWebAsync(url).Result; var container = html.DocumentNode.Descendants().Where(ax => ax.Name == "pre").ToList(); var children = container[0].ChildNodes; var anchorTexts = children.Where(ax => ax.Name == "a").ToList(); var infoTexts = children.Where(ax => ax.Name == "#text").ToList(); int foundCount = 0; for (int i = 0; i < anchorTexts.Count; i++) { string name = ExtractionHelpers.ClearName(Path.GetFileNameWithoutExtension(anchorTexts[i].Attributes["href"].Value), consoleCode); if (!ExtractionHelpers.IsNameValid(name)) { continue; } string portrait = ExtractionHelpers.ExtractThumbnail(consoleCode, name, imageMap); string region = ExtractionHelpers.ExtractRegion(name); string infolink = Constants.InfoRepoBaseUrl + ConsolesConstants.ConsoleSlugs[consoleCode] + "/" + name.Trim() + ".json"; string romSize = ExtractionHelpers.ExtractSize(infoTexts[i].InnerText); string romDownloadUrl = anchorTexts[i].Attributes["href"].Value; if (!infolink.EndsWith("/") && name.Trim() != "" && !infolink.StartsWith(".") && !infolink.EndsWith(".txt") && portrait != null) { foundCount++; InnerList.Add(new RomData { Name = name, Portrait = portrait, Region = region, DownloadLink = url + romDownloadUrl, Console = ((Enums.Consoles)consoleCode).ToString().Replace('_', ' '), Size = romSize }); } } Console.WriteLine(foundCount + " Portraits found of " + anchorTexts.Count + " " + (anchorTexts.Count - foundCount) + "Portraits not found"); return(InnerList); }