public async Task <Either <DomainError, ImmutableList <AnimeInfo> > > GetLibrary() { try { var web = new HtmlWeb(); var doc = await web.LoadFromWebAsync(AniChartLibrary); var seasonInfoString = HttpUtility.HtmlDecode(GetInnerTextOrEmpty(doc.DocumentNode, "//h1[@class='calendar']")); var(season, year, yearStr) = GetSeasonInformation(seasonInfoString); var feeTitles = await GetFeedTitles(); return(doc.DocumentNode .SelectNodes("//div[contains(@class,'g_bubblewrap') and contains(@class,'container')]/div[contains(@class,'g_bubble') and contains(@class,'box')]") .Select(n => MapFromCard(n, yearStr)) .Select(aic => new AnimeInfo( NonEmptyString.FromString(IdHelpers.GenerateAnimeId(season.Value, yearStr, aic.Title)), NonEmptyString.FromString(aic.Title), NonEmptyString.FromString(aic.Synopsis), NonEmptyString.FromString(Helpers.TryGetFeedTitle(feeTitles, aic.Title)), new SeasonInformation(season, year), aic.Date, false)) .ToImmutableList()); } catch (Exception e) { return(ExceptionError.FromException(e, "AnichartLibrary")); } }
private static BlobImageInfo CreateDomainInformation(ImageInfo imageInfo, Season season, int year) { var title = imageInfo.Title ?? string.Empty; var partition = IdHelpers.GenerateAnimePartitionKey(season, (ushort)year); var id = IdHelpers.GenerateAnimeId(season.ToString(), year.ToString(), title); var directory = $"{year.ToString()}/{season.Value}"; var blobName = IdHelpers.CleanAndFormatAnimeTitle(title); return(new BlobImageInfo(partition, id, directory, blobName, imageInfo.Url ?? string.Empty)); }
public async Task <Either <DomainError, ImmutableList <AnimeInfo> > > GetLibrary() { try { var web = new HtmlWeb(); var doc = web.Load(LiveChartLibrary); var seasonInfoString = HttpUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//h1").InnerText); var(season, year) = GetSeasonInformation(seasonInfoString); var yearStr = OptionUtils.UnpackOption(year.Value, (ushort)DateTime.Today.Year).ToString(); var feeTitles = await GetFeedTitles(); var results = await Task.WhenAll(doc.DocumentNode .SelectNodes("//main[@class='chart']/article[@class='anime']/div[@class='anime-card']") .AsParallel() .Where(FilterLeftover) .Select(async x => await MapFromCard(x)) .Select(x => new AnimeInfo( NonEmptyString.FromString(IdHelpers.GenerateAnimeId(season.Value, yearStr, x.Item1)), NonEmptyString.FromString(x.Item1), NonEmptyString.FromString(x.Item2), NonEmptyString.FromString(Helpers.TryGetFeedTitle(feeTitles, x.Item1)), new SeasonInformation(season, year), x.Item3, false))); return(results.ToImmutableList()); } catch (Exception e) { return(ExceptionError.FromException(e, "Library")); } }