コード例 #1
0
        public Either <DomainError, ImmutableList <FeedInfo> > GetFeed(Resolution resolution)
        {
            try
            {
                var sources = new List <LinkType> {
                    LinkType.TorrentFile, LinkType.Magnet
                }
                .SelectMany(type => GetFeedInformation(Resolution.Hd, type))
                .Where(f => f.PublicationDate >= DateTime.Today)
                .GroupBy(i => i.AnimeTitle);

                var resultList =
                    from source in sources
                    let links = source.Select(x => new TorrentLink(x.Type, x.Link)).ToImmutableList()
                                let baseElement = source.First()
                                                  select new FeedInfo(
                        NonEmptyString.FromString(baseElement.AnimeTitle),
                        NonEmptyString.FromString(baseElement.FeedTitle),
                        baseElement.PublicationDate,
                        links,
                        baseElement.EpisodeInfo);
                return(resultList.ToImmutableList());
            }
            catch (Exception e)
            {
                return(Left <DomainError, ImmutableList <FeedInfo> >(
                           ExceptionError.FromException(e, $"Erai_Feed_Exception")));
            }
        }
コード例 #2
0
        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"));
            }
        }
コード例 #3
0
        public void ShouldMapWhenDateIsNone()
        {
            var animeInfo = new AnimeInfo(
                NonEmptyString.FromString("a"),
                NonEmptyString.FromString("title"),
                NonEmptyString.FromString(null),
                NonEmptyString.FromString("test"),
                new SeasonInformation(Season.Spring, new Year(2015)),
                None,
                false);


            var sut = AnimeInfoMappers.ProjectToStorageModel(animeInfo);

            Assert.Null(sut.Date);
        }
コード例 #4
0
        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"));
            }
        }
コード例 #5
0
 internal static Validation <ValidationError, NonEmptyString> IdListMustHaveElements(string animeId) =>
 !string.IsNullOrEmpty(animeId)
         ? Success <ValidationError, NonEmptyString>(NonEmptyString.FromString(animeId))
         : Fail <ValidationError, NonEmptyString>(ValidationError.Create("AnimeId", new[] { "AnimeId must have a value" }));