public void Setup() { _episodeMapper = Substitute.For <IEpisodeMapper>(); _sources = Substitute.For <ISources>(); _mappingList = Substitute.For <IMappingList>(); _embyData = Substitute.For <IEmbyItemData>(); _embyData.Identifier.Returns(new ItemIdentifier(67, 53, "Name")); _embyData.Language.Returns("en"); var aniDbSource = Substitute.For <IAniDbSource>(); _sources.AniDb.Returns(aniDbSource); var tvDbSource = Substitute.For <ITvDbSource>(); _sources.TvDb.Returns(tvDbSource); _tvDbSourceData = Substitute.For <ISourceData <TvDbEpisodeData> >(); _mediaItem = Substitute.For <IMediaItem>(); _mediaItem.EmbyData.Returns(_embyData); _mediaItem.ItemType.Returns(MediaItemTypes.Episode); SetUpTvDbEpisodeData(56, 67, 53); _noMappingResult = new ProcessFailedResult("", "", null, ""); _mappingList.GetSeriesMappingsFromTvDb(Arg.Any <int>(), Arg.Any <ProcessResultContext>()) .Returns(Left <ProcessFailedResult, IEnumerable <ISeriesMapping> >(_noMappingResult)); }
private MediaItem(IEmbyItemData embyData, IMediaItemType itemType, ImmutableDictionary <string, ISourceData> sourceData) { EmbyData = embyData; ItemType = itemType; _sourceData = sourceData; }
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())); })); }
public Task <Either <ProcessFailedResult, ISourceData> > LoadFrom(IEmbyItemData embyItemData) { var seasonIdentifier = embyItemData.Identifier; return(Right <ProcessFailedResult, ISourceData>(new IdentifierOnlySourceData(_sources.TvDb, Option <int> .None, seasonIdentifier)) .AsTask()); }
public Task <Either <ProcessFailedResult, ISourceData> > LoadFrom(IEmbyItemData embyItemData) { var resultContext = new ProcessResultContext(nameof(TvDbSeriesFromEmbyData), embyItemData.Identifier.Name, embyItemData.ItemType); return(this.tvDbClient.FindSeriesAsync(embyItemData.Identifier.Name) .ToEitherAsync(resultContext.Failed("Failed to find series in TvDb")) .MapAsync(s => this.CreateSourceData(s, embyItemData))); }
private Either <ProcessFailedResult, AniDbEpisodeData> GetAniDbEpisodeData(AniDbSeriesData aniDbSeriesData, IEmbyItemData embyItemData, ProcessResultContext resultContext) { return(this.aniDbEpisodeMatcher.FindEpisode(aniDbSeriesData.Episodes, embyItemData.Identifier.ParentIndex, embyItemData.Identifier.Index, embyItemData.Identifier.Name) .ToEither(resultContext.Failed("Failed to find episode in AniDb"))); }
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}'")))); }
/// <summary> /// Create a new <see cref="MediaItem" /> /// </summary> /// <param name="embyData">The name of the item as originally provided by Emby</param> /// <param name="itemType">The type of the media item</param> /// <param name="sourceData">The metadata from the source used to initially identify this media item</param> public MediaItem(IEmbyItemData embyData, IMediaItemType itemType, ISourceData sourceData) { if (sourceData == null) { throw new ArgumentNullException(nameof(sourceData)); } this.EmbyData = embyData ?? throw new ArgumentNullException(nameof(embyData)); this.ItemType = itemType; this.sourceData = ImmutableDictionary <string, ISourceData> .Empty.Add(sourceData.Source.Name, sourceData); }
public Task <Either <ProcessFailedResult, ISourceData> > LoadFrom(IEmbyItemData embyItemData) { var resultContext = new ProcessResultContext(nameof(AniDbSeriesFromEmbyData), embyItemData.Identifier.Name, embyItemData.ItemType); return(_aniDbClient.FindSeriesAsync(embyItemData.Identifier.Name) .ToEitherAsync(resultContext.Failed("Failed to find series in AniDb")) .BindAsync(s => { var title = _sources.AniDb.SelectTitle(s.Titles, embyItemData.Language, resultContext); return title.Map(t => CreateSourceData(s, embyItemData, t)); })); }
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, ISourceData> > LoadFrom(IEmbyItemData embyItemData) { var resultContext = new ProcessResultContext(nameof(AniDbSeasonFromEmbyData), embyItemData.Identifier.Name, embyItemData.ItemType); var aniDbSeries = this.sources.AniDb.GetSeriesData(embyItemData, resultContext); return(aniDbSeries.BindAsync(series => this.sources.AniDb.SelectTitle(series.Titles, embyItemData.Language, resultContext)) .MapAsync(seriesTitle => new ItemIdentifier(embyItemData.Identifier.Index.IfNone(1), embyItemData.Identifier.ParentIndex, seriesTitle)) .MapAsync(itemIdentifier => (ISourceData) new IdentifierOnlySourceData(this.sources.AniDb, Option <int> .None, itemIdentifier, embyItemData.ItemType))); }
public Task <Either <ProcessFailedResult, ISourceData> > LoadFrom(IEmbyItemData embyItemData) { var resultContext = new ProcessResultContext(nameof(AniDbEpisodeFromEmbyData), embyItemData.Identifier.Name, embyItemData.ItemType); return(_sources.AniDb.GetSeriesData(embyItemData, resultContext) .BindAsync(seriesData => GetAniDbEpisodeData(seriesData, embyItemData, resultContext)) .BindAsync(episodeData => { var title = _sources.AniDb.SelectTitle(episodeData.Titles, embyItemData.Language, resultContext); return title.Map(t => CreateSourceData(episodeData, t)); })); }
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))); }
private ISourceData CreateSourceData(AniDbSeriesData seriesData, IEmbyItemData embyItemData, string title) { return(new SourceData <AniDbSeriesData>(_sources.AniDb, seriesData.Id, new ItemIdentifier(embyItemData.Identifier.Index, Option <int> .None, title), seriesData)); }
private ISourceData CreateSourceData(TvDbSeriesData seriesData, IEmbyItemData embyItemData) { return(new SourceData <TvDbSeriesData>(_sources.TvDb.ForAdditionalData(), seriesData.Id, new ItemIdentifier(embyItemData.Identifier.Index, Option <int> .None, seriesData.SeriesName), seriesData)); }