public async Task <TelevisionEpisodeCardResultsViewModel> Handle( QuerySearchIndexEpisodes request, CancellationToken cancellationToken) { SearchResult searchResult = await _searchIndex.Search( request.Query, (request.PageNumber - 1) *request.PageSize, request.PageSize); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); List <EpisodeMetadata> episodes = await _televisionRepository .GetEpisodesForCards(searchResult.Items.Map(i => i.Id).ToList()); var items = new List <TelevisionEpisodeCardViewModel>(); foreach (EpisodeMetadata episodeMetadata in episodes) { string localPath = await episodeMetadata.Episode.GetLocalPath( _plexPathReplacementService, _jellyfinPathReplacementService, _embyPathReplacementService, false); items.Add(ProjectToViewModel(episodeMetadata, maybeJellyfin, maybeEmby, true, localPath)); } return(new TelevisionEpisodeCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap)); }
public async Task <TelevisionEpisodeCardResultsViewModel> Handle( GetTelevisionEpisodeCards request, CancellationToken cancellationToken) { int count = await _televisionRepository.GetEpisodeCount(request.TelevisionSeasonId); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); List <EpisodeMetadata> episodes = await _televisionRepository .GetPagedEpisodes(request.TelevisionSeasonId, request.PageNumber, request.PageSize); var results = new List <TelevisionEpisodeCardViewModel>(); foreach (EpisodeMetadata episodeMetadata in episodes) { string localPath = await episodeMetadata.Episode.GetLocalPath( _plexPathReplacementService, _jellyfinPathReplacementService, _embyPathReplacementService, false); results.Add(ProjectToViewModel(episodeMetadata, maybeJellyfin, maybeEmby, false, localPath)); } return(new TelevisionEpisodeCardResultsViewModel(count, results, Option <SearchPageMap> .None)); }
public async Task <Option <TelevisionSeasonViewModel> > Handle( GetTelevisionSeasonById request, CancellationToken cancellationToken) { Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); return(await _televisionRepository.GetSeason(request.SeasonId) .MapT(s => ProjectToViewModel(s, maybeJellyfin, maybeEmby))); }
public async Task <Either <BaseError, List <EmbyMediaSource> > > Handle( SynchronizeEmbyMediaSources request, CancellationToken cancellationToken) { List <EmbyMediaSource> mediaSources = await _mediaSourceRepository.GetAllEmby(); foreach (EmbyMediaSource mediaSource in mediaSources) { // await _channel.WriteAsync(new SynchronizeEmbyAdminUserId(mediaSource.Id), cancellationToken); await _channel.WriteAsync(new SynchronizeEmbyLibraries(mediaSource.Id), cancellationToken); } return(mediaSources); }
public async Task <TelevisionSeasonCardResultsViewModel> Handle( GetTelevisionSeasonCards request, CancellationToken cancellationToken) { int count = await _televisionRepository.GetSeasonCount(request.TelevisionShowId); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); List <TelevisionSeasonCardViewModel> results = await _televisionRepository .GetPagedSeasons(request.TelevisionShowId, request.PageNumber, request.PageSize) .Map(list => list.Map(s => ProjectToViewModel(s, maybeJellyfin, maybeEmby)).ToList()); return(new TelevisionSeasonCardResultsViewModel(count, results, None)); }
public async Task <Option <TelevisionShowViewModel> > Handle( GetTelevisionShowById request, CancellationToken cancellationToken) { Option <Show> maybeShow = await _televisionRepository.GetShow(request.Id); return(await maybeShow.Match <Task <Option <TelevisionShowViewModel> > >( async show => { Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); List <string> mediaCodes = await _searchRepository.GetLanguagesForShow(show); List <string> languageCodes = await _searchRepository.GetAllLanguageCodes(mediaCodes); return ProjectToViewModel(show, languageCodes, maybeJellyfin, maybeEmby); }, () => Task.FromResult(Option <TelevisionShowViewModel> .None))); }
public async Task <MovieCardResultsViewModel> Handle( QuerySearchIndexMovies request, CancellationToken cancellationToken) { SearchResult searchResult = await _searchIndex.Search( request.Query, (request.PageNumber - 1) *request.PageSize, request.PageSize); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); List <MovieCardViewModel> items = await _movieRepository .GetMoviesForCards(searchResult.Items.Map(i => i.Id).ToList()) .Map(list => list.Map(m => ProjectToViewModel(m, maybeJellyfin, maybeEmby)).ToList()); return(new MovieCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap)); }
public async Task <Option <MovieViewModel> > Handle( GetMovieById request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); Option <Movie> maybeMovie = await _movieRepository.GetMovie(request.Id); Option <MediaVersion> maybeVersion = maybeMovie.Map(m => m.MediaVersions.HeadOrNone()).Flatten(); var languageCodes = new List <string>(); foreach (MediaVersion version in maybeVersion) { var mediaCodes = version.Streams .Filter(ms => ms.MediaStreamKind == MediaStreamKind.Audio) .Map(ms => ms.Language) .ToList(); languageCodes.AddRange(await dbContext.LanguageCodes.GetAllLanguageCodes(mediaCodes)); } foreach (Movie movie in maybeMovie) { string localPath = await movie.GetLocalPath( _plexPathReplacementService, _jellyfinPathReplacementService, _embyPathReplacementService, false); return(ProjectToViewModel(movie, localPath, languageCodes, maybeJellyfin, maybeEmby)); } return(None); }
public async Task <Either <BaseError, CollectionCardResultsViewModel> > Handle( GetCollectionCards request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); return(await dbContext.Collections .AsNoTracking() .Include(c => c.CollectionItems) .Include(c => c.MediaItems) .ThenInclude(i => i.LibraryPath) .Include(c => c.MediaItems) .ThenInclude(i => (i as Movie).MovieMetadata) .ThenInclude(mm => mm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as Movie).MediaVersions) .ThenInclude(mv => mv.MediaFiles) .Include(c => c.MediaItems) .ThenInclude(i => (i as Artist).ArtistMetadata) .ThenInclude(mvm => mvm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as MusicVideo).MusicVideoMetadata) .ThenInclude(mvm => mvm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as MusicVideo).Artist) .ThenInclude(a => a.ArtistMetadata) .Include(c => c.MediaItems) .ThenInclude(i => (i as MusicVideo).MediaVersions) .ThenInclude(mv => mv.MediaFiles) .Include(c => c.MediaItems) .ThenInclude(i => (i as Show).ShowMetadata) .ThenInclude(sm => sm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as Season).SeasonMetadata) .ThenInclude(sm => sm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as Season).Show) .ThenInclude(s => s.ShowMetadata) .Include(c => c.MediaItems) .ThenInclude(i => (i as Episode).EpisodeMetadata) .ThenInclude(em => em.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as Episode).EpisodeMetadata) .ThenInclude(em => em.Directors) .Include(c => c.MediaItems) .ThenInclude(i => (i as Episode).EpisodeMetadata) .ThenInclude(em => em.Writers) .Include(c => c.MediaItems) .ThenInclude(i => (i as Episode).Season) .ThenInclude(s => s.Show) .ThenInclude(s => s.ShowMetadata) .Include(c => c.MediaItems) .ThenInclude(i => (i as Episode).Season) .ThenInclude(s => s.SeasonMetadata) .Include(c => c.MediaItems) .ThenInclude(i => (i as Episode).MediaVersions) .ThenInclude(mv => mv.MediaFiles) .Include(c => c.MediaItems) .ThenInclude(i => (i as OtherVideo).OtherVideoMetadata) .ThenInclude(ovm => ovm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as OtherVideo).MediaVersions) .ThenInclude(mv => mv.MediaFiles) .Include(c => c.MediaItems) .ThenInclude(i => (i as Song).SongMetadata) .ThenInclude(ovm => ovm.Artwork) .Include(c => c.MediaItems) .ThenInclude(i => (i as Song).MediaVersions) .ThenInclude(mv => mv.MediaFiles) .SelectOneAsync(c => c.Id, c => c.Id == request.Id) .Map(c => c.ToEither(BaseError.New("Unable to load collection"))) .MapT(c => ProjectToViewModel(c, maybeJellyfin, maybeEmby))); }
private Task <Validation <BaseError, EmbyMediaSource> > EmbyMediaSourceMustExist() => _mediaSourceRepository.GetAllEmby().Map(list => list.HeadOrNone()) .Map( v => v.ToValidation <BaseError>( "Emby media source does not exist."));