Exemplo n.º 1
0
        public async Task <Either <ProcessFailedResult, ISourceData> > LoadFrom(IEmbyItemData embyItemData)
        {
            var resultContext = new ProcessResultContext(nameof(AniDbEpisodeFromEmbyData), embyItemData.Identifier.Name,
                                                         embyItemData.ItemType);

            if (embyItemData.GetParentId(MediaItemTypes.Series, this.sources.AniDb).IsNone)
            {
                var tvDbSeriesId = embyItemData.GetParentId(MediaItemTypes.Series, this.sources.TvDb)
                                   .ToEither(resultContext.Failed("Failed to find TvDb series Id"));

                if (tvDbSeriesId.IsRight && embyItemData.Identifier.ParentIndex.IsSome)
                {
                    var aniDbSeriesId = await tvDbSeriesId.BindAsync(id => this.MapSeriesDataAsync(id, embyItemData.Identifier.ParentIndex.Single(), resultContext));

                    aniDbSeriesId.IfRight((anidbId) => {
                        var updatedParentIds = embyItemData.ParentIds.Concat(new List <EmbyItemId> {
                            new EmbyItemId(MediaItemTypes.Series, this.sources.AniDb.Name, anidbId)
                        });
                        embyItemData = new EmbyItemData(embyItemData.ItemType, embyItemData.Identifier, embyItemData.ExistingIds, embyItemData.Language, updatedParentIds);
                    });
                }
            }

            return(await this.sources.AniDb.GetSeriesData(embyItemData, resultContext)
                   .BindAsync(seriesData => this.GetAniDbEpisodeData(seriesData, embyItemData, resultContext))
                   .BindAsync(episodeData =>
            {
                var title = this.sources.AniDb.SelectTitle(episodeData.Titles, embyItemData.Language, resultContext);

                return title.Map(t => this.CreateSourceData(episodeData, t, embyItemData.Identifier.ParentIndex.Single()));
            }));
        }
Exemplo n.º 2
0
        private TvDbSeriesData SetUpTvDbSeriesData(int id)
        {
            var seriesData = TvDbTestData.Series(id);

            _embyData.GetParentId(MediaItemTypes.Series, _sources.TvDb).Returns(id);
            _sources.TvDb.GetSeriesData(_embyData, Arg.Any <ProcessResultContext>()).Returns(seriesData);

            return(seriesData);
        }
Exemplo n.º 3
0
 public Task <Either <ProcessFailedResult, AniDbSeriesData> > GetSeriesData(IEmbyItemData embyItemData,
                                                                            ProcessResultContext resultContext)
 {
     return(embyItemData.GetParentId(MediaItemTypes.Series, this)
            .ToEitherAsync(
                resultContext.Failed("No AniDb Id found on parent series"))
            .BindAsync(aniDbSeriesId => _aniDbClient.GetSeriesAsync(aniDbSeriesId)
                       .ToEitherAsync(
                           resultContext.Failed($"Failed to load parent series with AniDb Id '{aniDbSeriesId}'"))));
 }
        private AniDbSeriesData SetUpAniDbSeriesData(int id)
        {
            var seriesData = new AniDbSeriesData().WithStandardData();

            seriesData.Id = id;

            _embyData.GetParentId(MediaItemTypes.Series, _aniDbSource).Returns(id);
            _aniDbSource.GetSeriesData(_mediaItem.EmbyData, Arg.Any <ProcessResultContext>()).Returns(seriesData);

            return(seriesData);
        }
        public async Task LoadFrom_NoSeriesId_Fails()
        {
            _embyItemData.GetParentId(MediaItemTypes.Series, _sources.TvDb).Returns(Option <int> .None);

            var loader = new TvDbEpisodeFromEmbyData(_sources, _tvDbClient, _titleNormaliser);

            var result = await loader.LoadFrom(_embyItemData);

            result.IsLeft.Should().BeTrue();
            result.IfLeft(f => f.Reason.Should().Be("No TvDb Id found on parent series"));
        }
        public Task <Either <ProcessFailedResult, ISourceData> > LoadFrom(IEmbyItemData embyItemData)
        {
            var resultContext = new ProcessResultContext(nameof(TvDbEpisodeFromEmbyData), embyItemData.Identifier.Name,
                                                         embyItemData.ItemType);

            var seriesId = embyItemData.GetParentId(MediaItemTypes.Series, this.sources.TvDb);

            return(seriesId.ToEitherAsync(resultContext.Failed("No TvDb Id found on parent series"))
                   .BindAsync(id => this.tvDbClient.GetEpisodesAsync(id)
                              .ToEitherAsync(resultContext.Failed($"Failed to load parent series with TvDb Id '{id}'")))
                   .BindAsync(episodes => this.FindEpisode(episodes, embyItemData.Identifier.Name,
                                                           embyItemData.Identifier.Index, embyItemData.Identifier.ParentIndex, resultContext))
                   .MapAsync(this.CreateSourceData));
        }
        public Task <Either <ProcessFailedResult, TvDbSeriesData> > GetSeriesData(IEmbyItemData embyItemData,
                                                                                  ProcessResultContext resultContext)
        {
            Task <Either <ProcessFailedResult, int> > seriesId;

            if (embyItemData.ItemType == MediaItemTypes.Series)
            {
                seriesId = embyItemData.GetExistingId(Name)
                           .ToEitherAsync(resultContext.Failed("No TvDb Id found on this series"));
            }
            else
            {
                seriesId = embyItemData.GetParentId(MediaItemTypes.Series, this)
                           .ToEitherAsync(resultContext.Failed("No TvDb Id found on parent series"));
            }

            return(seriesId.BindAsync(tvDbSeriesId => GetSeriesData(tvDbSeriesId, resultContext)));
        }