private async Task IndexNewMovies(string[] newFiles, Library library) { var newFilm = FileIndexer.IndexFilmFiles(newFiles, library.Id).ToList(); var details = await _metadataService.FindFilmDetails(newFilm, library) !; if (details.Any()) { await _deduplicationService.DeduplicateEntities(details, d => d.Genres); await _deduplicationService.DeduplicateEntities(details, d => d.ProductionCountries, pc => pc.Iso3166_1, ids => entity => ids.Contains(entity.Iso3166_1)); await _deduplicationService.DeduplicateEntities(details, d => d.SpokenLanguages, sl => sl.Iso639_1, ids => entity => ids.Contains(entity.Iso639_1)); var newProductionCompanyIds = await _deduplicationService.DeduplicateEntities(details, d => d.ProductionCompanies); var newMovieCollectionIds = await _deduplicationService.DeduplicateMovieCollections(details); await _deduplicationService.DeduplicateFilmMetadata(details); _context.FilmFiles.AddRange(newFilm); await _context.SaveChangesAsync(); await _distributedCache.ClearList("overview", "sys"); foreach (var detail in details) { _backgroundJobClient.Enqueue <ImageProcessor>(service => service.ProcessFilmDetails(detail.Id)); } foreach (var movieCollectionId in newMovieCollectionIds) { _backgroundJobClient.Enqueue <ImageProcessor>(service => service.ProcessMovieCollection(movieCollectionId)); } if (newProductionCompanyIds.Any()) { _backgroundJobClient.Enqueue <ImageProcessor>(service => service.ProcessProductionCompanies(newProductionCompanyIds)); } foreach (var filmFile in newFilm) { _backgroundJobClient.Enqueue <FileAnalysisService>( service => service.AnalyseFilmFile(filmFile.Id, library.Id)); } } }
public async Task RemoveDeletedMovies(int libraryId) { var currentFilePaths = await _databaseContext.FilmFiles.Where(f => f.PartOfLibraryId == libraryId).Select(e => new { e.Id, e.Path, e.FilmDetailsId }).ToListAsync(); var deletedIds = currentFilePaths .Where(file => file.FilmDetailsId == null || !File.Exists(file.Path)).Select(file => file.Id) .ToList(); if (deletedIds.Any()) { await RemoveWatchingProgress(deletedIds); await RemoveSubtitlePreferences(deletedIds); var toDelete = await _databaseContext.FilmFiles.Where(f => deletedIds.Contains(f.Id)).ToListAsync(); _databaseContext.RemoveRange(toDelete); await _databaseContext.SaveChangesAsync(); await _distributedCache.ClearList("overview", "sys"); _logger.LogInformation("Deleted {DeletedAmount} film from Library {LibaryId} because files were removed", toDelete.Count, libraryId); } }
public async Task <AdminLibraryDto> Handle(CreateLibraryCommand command, CancellationToken cancellationToken = default) { var lib = new Domain.Models.Library { Name = command.Name, Path = command.Path, Language = command.Language, Kind = command.Kind == "film" ? LibraryKind.Film : LibraryKind.Series }; _context.Libraries.Add(lib); await _context.SaveChangesAsync(cancellationToken); _logger.LogInformation("Created library {Name} with {Path}", lib.Name, lib.Path); await _distributedCache.ClearList("overview", "sys", cancellationToken); return(_mapper.Map <Domain.Models.Library, AdminLibraryDto>(lib) !); }
public async Task <bool> Handle(ReplaceImageCommand command, CancellationToken cancellationToken = default) { var task = command.DetailsType switch { DetailsType.Series => SetSeriesImage(command.DetailsId, command.ImageType, command.ImageExtension, command.ImageStream, cancellationToken), DetailsType.Season => SetSeasonImage(command.DetailsId, command.ImageType, command.ImageExtension, command.ImageStream, cancellationToken), DetailsType.Film => SetFilmImage(command.DetailsId, command.ImageType, command.ImageExtension, command.ImageStream, cancellationToken), DetailsType.Collection => SetCollectionImage(command.DetailsId, command.ImageType, command.ImageExtension, command.ImageStream, cancellationToken), _ => throw new ArgumentOutOfRangeException() }; var success = await task; if (!success) { return(false); } await _context.SaveChangesAsync(cancellationToken); await _distributedCache.ClearList("overview", "sys", cancellationToken); return(true); }
public async Task <bool> Handle(RemoveLibraryCommand command, CancellationToken cancellationToken = default) { var library = await _context.Libraries.FirstOrDefaultAsync(l => l.Id == command.LibraryId, cancellationToken); if (library == null) { return(false); } foreach (var user in await _context.Users.ToListAsync(cancellationToken)) { user.LibraryAccessIds?.Remove(command.LibraryId); } await _context.SaveChangesAsync(cancellationToken); _context.Libraries.Remove(library); await _context.SaveChangesAsync(CancellationToken.None); await _distributedCache.ClearList("overview", "sys", cancellationToken); _logger.LogInformation("Deleted library {LibraryName}", library.Name); return(true); }
public async Task Handle(ClearSessionsCommand command, CancellationToken cancellationToken = default) { await _distributedCache.ClearList(SessionPrefix, command.UserId.ToString(), cancellationToken); }