private async Task <string> GetPlayoutItemPath(PlayoutItem playoutItem) { MediaVersion version = playoutItem.MediaItem.GetHeadVersion(); MediaFile file = version.MediaFiles.Head(); string path = file.Path; return(playoutItem.MediaItem switch { PlexMovie plexMovie => await _plexPathReplacementService.GetReplacementPlexPath( plexMovie.LibraryPathId, path), PlexEpisode plexEpisode => await _plexPathReplacementService.GetReplacementPlexPath( plexEpisode.LibraryPathId, path), JellyfinMovie jellyfinMovie => await _jellyfinPathReplacementService.GetReplacementJellyfinPath( jellyfinMovie.LibraryPathId, path), JellyfinEpisode jellyfinEpisode => await _jellyfinPathReplacementService.GetReplacementJellyfinPath( jellyfinEpisode.LibraryPathId, path), EmbyMovie embyMovie => await _embyPathReplacementService.GetReplacementEmbyPath( embyMovie.LibraryPathId, path), EmbyEpisode embyEpisode => await _embyPathReplacementService.GetReplacementEmbyPath( embyEpisode.LibraryPathId, path), _ => path });
public static async Task SingleEpisodeCheck(bool useImdb, IQueryable <EmbyEpisode> allEpisodes, EpisodeRequests episode, SeasonRequests season, EmbyContent item, bool useTheMovieDb, bool useTvDb) { EmbyEpisode epExists = null; if (useImdb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.ImdbId == item.ImdbId); } if (useTheMovieDb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.TheMovieDbId == item.TheMovieDbId); } if (useTvDb) { epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.TvDbId == item.TvDbId); } if (epExists != null) { episode.Available = true; } }
public async Task <EmbyEpisode> Add(EmbyEpisode content) { await Db.EmbyEpisode.AddAsync(content); await InternalSaveChanges(); return(content); }
public async Task <RuleResult> Execute(SearchViewModel obj) { EmbyContent item = null; if (obj.ImdbId.HasValue()) { item = await EmbyContentRepository.GetByImdbId(obj.ImdbId); } if (item == null) { if (obj.TheMovieDbId.HasValue()) { item = await EmbyContentRepository.GetByTheMovieDbId(obj.TheMovieDbId); } if (item == null) { if (obj.TheTvDbId.HasValue()) { item = await EmbyContentRepository.GetByTvDbId(obj.TheTvDbId); } } } if (item != null) { obj.Available = true; obj.EmbyUrl = item.Url; if (obj.Type == RequestType.TvShow) { var search = (SearchTvShowViewModel)obj; // Let's go through the episodes now if (search.SeasonRequests.Any()) { var allEpisodes = EmbyContentRepository.GetAllEpisodes().Include(x => x.Series); foreach (var season in search.SeasonRequests) { foreach (var episode in season.Episodes) { EmbyEpisode epExists = null; epExists = await allEpisodes.FirstOrDefaultAsync(x => x.EpisodeNumber == episode.EpisodeNumber && x.SeasonNumber == season.SeasonNumber && x.Series.ProviderId == item.ProviderId.ToString()); if (epExists != null) { episode.Available = true; } } } } } } return(Success()); }
private async Task <Either <BaseError, bool> > UpdateSubtitles(EmbyEpisode episode, string localPath) { try { return(await _localSubtitlesProvider.UpdateSubtitles(episode, localPath, false)); } catch (Exception ex) { return(BaseError.New(ex.ToString())); } }
private async Task <Either <BaseError, Unit> > ProcessEpisodes( string showName, string seasonName, EmbyLibrary library, string ffmpegPath, string ffprobePath, List <EmbyPathReplacement> pathReplacements, EmbySeason season, List <EmbyItemEtag> existingEpisodes, List <EmbyEpisode> episodes, CancellationToken cancellationToken) { foreach (EmbyEpisode incoming in episodes) { if (cancellationToken.IsCancellationRequested) { return(new ScanCanceled()); } EmbyEpisode incomingEpisode = incoming; var updateStatistics = false; Option <EmbyItemEtag> maybeExisting = existingEpisodes.Find(ie => ie.ItemId == incoming.ItemId); if (maybeExisting.IsNone) { try { updateStatistics = true; incoming.LibraryPathId = library.Paths.Head().Id; _logger.LogDebug( "INSERT: Item id is new for show {Show} season {Season} episode {Episode}", showName, seasonName, incoming.EpisodeMetadata.HeadOrNone().Map(em => em.EpisodeNumber)); if (await _televisionRepository.AddEpisode(season, incoming)) { await _searchIndex.AddItems(_searchRepository, new List <MediaItem> { incoming }); } } catch (Exception ex) { updateStatistics = false; _logger.LogError( ex, "Error adding episode {Path}", incoming.MediaVersions.Head().MediaFiles.Head().Path); } } foreach (EmbyItemEtag existing in maybeExisting) { try { if (existing.Etag != incoming.Etag) { _logger.LogDebug( "UPDATE: Etag has changed for show {Show} season {Season} episode {Episode}", showName, seasonName, incoming.EpisodeMetadata.HeadOrNone().Map(em => em.EpisodeNumber)); updateStatistics = true; incoming.SeasonId = season.Id; incoming.LibraryPathId = library.Paths.Head().Id; Option <EmbyEpisode> maybeUpdated = await _televisionRepository.Update(incoming); foreach (EmbyEpisode updated in maybeUpdated) { await _searchIndex.UpdateItems(_searchRepository, new List <MediaItem> { updated }); incomingEpisode = updated; } } } catch (Exception ex) { updateStatistics = false; _logger.LogError( ex, "Error updating episode {Path}", incoming.MediaVersions.Head().MediaFiles.Head().Path); } } if (updateStatistics) { string localPath = _pathReplacementService.GetReplacementEmbyPath( pathReplacements, incoming.MediaVersions.Head().MediaFiles.Head().Path, false); _logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", localPath); Either <BaseError, bool> refreshResult = await _localStatisticsProvider.RefreshStatistics( ffmpegPath, ffprobePath, incomingEpisode, localPath); if (refreshResult.Map(t => t).IfLeft(false)) { refreshResult = await UpdateSubtitles(incomingEpisode, localPath); } foreach (BaseError error in refreshResult.LeftToSeq()) { _logger.LogWarning( "Unable to refresh {Attribute} for media item {Path}. Error: {Error}", "Statistics", localPath, error.Value); } } } return(Unit.Default); }