public async Task <ICollection <AnimeStreamInfo> > GetAnimeStreamInfoAsync(CancellationToken cancellationToken) { HashSet <AnimeStreamInfo> streams = new HashSet <AnimeStreamInfo>(new ProjectionEqualityComparer <AnimeStreamInfo, string>(streamInfo => streamInfo.Url, StringComparer.OrdinalIgnoreCase)); HelperStreamInfoSource tvStreamSource = new HelperStreamInfoSource("https://www.hidive.com/tv", _webClient); ICollection <AnimeStreamInfo> tvAnime = await tvStreamSource.GetAnimeStreamInfoAsync(cancellationToken).ConfigureAwait(false); streams.UnionWith(tvAnime); HelperStreamInfoSource movieAndOvaStreamSource = new HelperStreamInfoSource("https://www.hidive.com/movies", _webClient); ICollection <AnimeStreamInfo> movieAndOvaAnime = await movieAndOvaStreamSource.GetAnimeStreamInfoAsync(cancellationToken).ConfigureAwait(false); streams.UnionWith(movieAndOvaAnime); return(streams.ToList()); }
public async Task <ICollection <AnimeStreamInfo> > GetAnimeStreamInfoAsync(CancellationToken cancellationToken) { HashSet <AnimeStreamInfo> streams = new HashSet <AnimeStreamInfo>(); const string urlTemplate = "https://www.funimation.com/shows/all-shows/?sort=show&p={0}"; for (int page = 1; ; page++) { if (page > 100) { throw new Exception("Funimation has more pages of anime than expected, something is possibly broken."); } string url = string.Format(CultureInfo.InvariantCulture, urlTemplate, page); HtmlParsingAnimeStreamInfoSource helperSource = new HelperStreamInfoSource(_webClient, url); try { ICollection <AnimeStreamInfo> streamsFromThisRequest = await helperSource.GetAnimeStreamInfoAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false); streams.UnionWith(streamsFromThisRequest); } catch (NoMatchingHtmlException) { if (streams.Count > 0) { break; } else { throw; } } } return(streams.ToList()); }