예제 #1
0
        public async Task <GameInfo> GetGameInfo(BasicInfo info)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    info.Link = info.Link.Replace("https://", "http://");
                    var html    = info.Link;
                    var web     = new HtmlWeb();
                    var htmlDoc = await web.LoadFromWebAsync(html);

                    var region = htmlDoc.DocumentNode.SelectSingleNode("//img[@class=\"img narrow-border\"]") != null
                        ? htmlDoc.DocumentNode.SelectSingleNode("//img[@class=\"img narrow-border\"]")
                                 .GetAttributeValue("alt", "world")
                        : "world";

                    var genre       = htmlDoc.DocumentNode.SelectSingleNode("//span[@itemprop=\"genre\"]")?.InnerText;
                    var description = htmlDoc.DocumentNode.SelectSingleNode("//h3[text()=\"How To Play\"]")?.NextSibling
                                      .InnerText;
                    var dateString =
                        string.Concat(htmlDoc.DocumentNode.SelectNodes("//p")
                                      .First(p => p.InnerText.Contains("Original Release Date: "))?.InnerText.Skip(24) ??
                                      "none".Skip(0))?.Split('\n')?[0];
                    DateTime date;
                    var      replaced = dateString.Substring(0, 4)
                                        .Replace("nd", "")
                                        .Replace("th", "")
                                        .Replace("rd", "")
                                        .Replace("st", "")
                                        + dateString.Substring(4);
                    DateTime.TryParseExact(replaced, "d MMM yyyy",
                                           new CultureInfo("en-us"), DateTimeStyles.AssumeLocal,
                                           out date);
                    var publisher = htmlDoc.DocumentNode.SelectNodes("//span")
                                    .First(span => span.InnerText.Contains("Publisher: ")).InnerText.Skip(13);
                    var consoleStr = htmlDoc.DocumentNode.SelectNodes("//p")
                                     .First(p => p.InnerText.Contains("Machine Compatibility: ")).InnerText.Substring(23);
                    var consoles = consoleStr.Split(',');
                    var console  = consoles.FirstOrDefault(c => (GetSupportedSystems()).Contains(c));
                    var imgs     = htmlDoc.DocumentNode.SelectNodes("//img")
                                   .Where(img => img.GetAttributeValue("src", "none").Contains("ills_thumbs"))
                                   .Select(imgNode => imgNode.GetAttributeValue("src", "none")).Select(value =>
                                                                                                       new RegionalInfo <GameImage>(region, new GameImage {
                        ImgType = "UNKNOWN", ImgURL = value
                    })).ToList();
                    var cover = htmlDoc.DocumentNode.SelectSingleNode("//div[text()=\"Front Cover\"]") != null
                        ? htmlDoc.DocumentNode.SelectSingleNode("//div[text()=\"Front Cover\"]").ChildNodes.FindFirst("a")
                                .GetAttributeValue("href", "none")
                        : null;

                    if (cover == null)
                    {
                        imgs.Add(new RegionalInfo <GameImage>(region, new GameImage
                        {
                            ImgType = "COVER_UNTREATED",
                            ImgURL  = cover
                        }));
                    }

                    var game = new GameInfo
                    {
                        Id          = GetName() + "-" + info.Id,
                        Console     = console,
                        Genres      = genre,
                        Description = new List <RegionalInfo <string> > {
                            new RegionalInfo <string>(region, description)
                        },
                        Editor      = string.Concat(publisher),
                        ReleaseDate = new List <RegionalInfo <string> >
                        {
                            new RegionalInfo <string>(region,
                                                      $"{date:yyyy-MM-dd}")
                        },
                        Names = new List <RegionalInfo <string> > {
                            new RegionalInfo <string>(region, info.Name)
                        },
                        Images       = imgs,
                        Link         = info.Link,
                        ScrapDate    = DateTime.Now,
                        Provider     = GetName(),
                        InternalId   = info.ScrapEditorID,
                        LastEditTime = DateTime.Now
                    };
                    return(game);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Thread.Sleep(1000);
                }
            }
            throw new Exception("Error while making request !");
        }
예제 #2
0
        public async Task <GameInfo> ScrapGame(BasicInfo info)
        {
            var provider = _providers.First(x => x.GetName() == info.Provider);

            return(await provider.GetGameInfo(info));
        }