private async Task <R4UCard> AddImageFromConsole(R4UCard card, InspectionOptions options) { var modifiedCard = card.Clone(); Log.Information("Please enter a new image URL: "); var newURIString = Console.ReadLine(); try { Log.Information("Validating URL..."); var newURI = new Uri(newURIString); Log.Information("Looks good; validating image... (will not check if the image itself is correct!)"); using (Image img = Image.Load(await newURI.WithImageHeaders().GetStreamAsync())) { Log.Information("Image can be loaded. Is the ratio reasonable?"); var aspectRatio = (img.Width * 1.0d) / img.Height; var flooredAspectRatio = Math.Floor(aspectRatio * 100); if (flooredAspectRatio < 70 || flooredAspectRatio > 72) { Log.Information("Image Ratio ({aspectRatio}) isn't correct (it must be approx. 0.71428571428); Failed inspection.", aspectRatio); return(null); } else { if (img.Width < 400) { Log.Warning("The image is of low quality; this may not be good for exporting purposes. Continue? [Y/N] (Default is N)"); if (!ConsoleUtils.Prompted(options.IsNonInteractive, options.NoWarning)) { return(null); } } modifiedCard.Images.Add(newURI); Log.Information("All preliminary tests passed. Modified {card}.", card.Serial); } } } catch (UnknownImageFormatException) { Log.Error("The URL does not point to a valid image. Inspection failed."); return(null); } catch (Exception e) { Log.Error("{e}", e); return(null); } return(modifiedCard); }
private async Task <R4UCard> Process(R4UCard card) { if (!HasMissingInformation(card)) { return(card); } var updatedCard = card.Clone(); var url = rebirthURLPrefix .SetQueryParam("cardno", updatedCard.Serial.Replace("+", "+")) // ; Log.Debug("Opening Link: {url}", url); var document = await url.WithReferrer("https://rebirth-fy.com/cardlist/").GetHTMLAsync(); var flavorJPText = document.QuerySelector(".cardlist-flavor").GetInnerText(); var rulesTextJPText = document.QuerySelector(".cardlist-free").GetInnerText().Trim(); var imageLink = document.QuerySelector(".cardlist-img").FindChild <IHtmlImageElement>().Source; var rulesTextEnumerable = effectMatcher.Matches(rulesTextJPText); Log.Information("Flavor JP: {jp}", flavorJPText); Log.Information("Rules Text JP: {jp}", rulesTextJPText); if (!String.IsNullOrWhiteSpace(flavorJPText)) { updatedCard.Flavor ??= new MultiLanguageString(); updatedCard.Flavor.JP = flavorJPText; } updatedCard.Effect = rulesTextEnumerable.Select((m, i) => { var result = card.Effect[i].Clone(); result.JP = m.Value; return(result); }).ToArray(); updatedCard.Images.Add(new Uri(imageLink)); Log.Information("After editing: {@card}", updatedCard); return(updatedCard); }