Fix cleaning library in ImportListSyncService

pull/8774/head
Bogdan 12 months ago
parent 1c26dd4aca
commit 5c46c75ce7

@ -50,7 +50,7 @@ namespace NzbDrone.Core.ImportLists.ImportListMovies
_importListMovieRepository.InsertMany(listMovies.Where(l => l.Id == 0).ToList()); _importListMovieRepository.InsertMany(listMovies.Where(l => l.Id == 0).ToList());
_importListMovieRepository.UpdateMany(listMovies.Where(l => l.Id > 0).ToList()); _importListMovieRepository.UpdateMany(listMovies.Where(l => l.Id > 0).ToList());
_importListMovieRepository.DeleteMany(existingListMovies.Where(l => !listMovies.Any(x => x.TmdbId == l.TmdbId)).ToList()); _importListMovieRepository.DeleteMany(existingListMovies.Where(l => listMovies.All(x => x.TmdbId != l.TmdbId)).ToList());
return listMovies; return listMovies;
} }

@ -20,6 +20,7 @@ namespace NzbDrone.Core.ImportLists
private readonly IAddMovieService _addMovieService; private readonly IAddMovieService _addMovieService;
private readonly IConfigService _configService; private readonly IConfigService _configService;
private readonly IImportExclusionsService _exclusionService; private readonly IImportExclusionsService _exclusionService;
private readonly IImportListMovieService _listMovieService;
public ImportListSyncService(IImportListFactory importListFactory, public ImportListSyncService(IImportListFactory importListFactory,
IFetchAndParseImportList listFetcherAndParser, IFetchAndParseImportList listFetcherAndParser,
@ -27,6 +28,7 @@ namespace NzbDrone.Core.ImportLists
IAddMovieService addMovieService, IAddMovieService addMovieService,
IConfigService configService, IConfigService configService,
IImportExclusionsService exclusionService, IImportExclusionsService exclusionService,
IImportListMovieService listMovieService,
Logger logger) Logger logger)
{ {
_importListFactory = importListFactory; _importListFactory = importListFactory;
@ -34,6 +36,7 @@ namespace NzbDrone.Core.ImportLists
_movieService = movieService; _movieService = movieService;
_addMovieService = addMovieService; _addMovieService = addMovieService;
_exclusionService = exclusionService; _exclusionService = exclusionService;
_listMovieService = listMovieService;
_logger = logger; _logger = logger;
_configService = configService; _configService = configService;
} }
@ -57,10 +60,11 @@ namespace NzbDrone.Core.ImportLists
return; return;
} }
// if (!result.AnyFailure) if (!result.AnyFailure)
// { {
// CleanLibrary(result.Movies.ToList()); CleanLibrary();
// } }
ProcessReports(result); ProcessReports(result);
} }
@ -79,7 +83,7 @@ namespace NzbDrone.Core.ImportLists
} }
// Check to see if movie excluded // Check to see if movie excluded
var excludedMovie = listExclusions.Where(s => s.TmdbId == report.TmdbId).SingleOrDefault(); var excludedMovie = listExclusions.SingleOrDefault(s => s.TmdbId == report.TmdbId);
if (excludedMovie != null) if (excludedMovie != null)
{ {
@ -171,17 +175,20 @@ namespace NzbDrone.Core.ImportLists
} }
} }
private void CleanLibrary(List<ImportListMovie> listMovies) private void CleanLibrary()
{ {
var moviesToUpdate = new List<Movie>();
if (_configService.ListSyncLevel == "disabled") if (_configService.ListSyncLevel == "disabled")
{ {
return; return;
} }
var listMovies = _listMovieService.GetAllListMovies();
// TODO use AllMovieTmdbIds here? // TODO use AllMovieTmdbIds here?
var moviesInLibrary = _movieService.GetAllMovies(); var moviesInLibrary = _movieService.GetAllMovies();
var moviesToUpdate = new List<Movie>();
foreach (var movie in moviesInLibrary) foreach (var movie in moviesInLibrary)
{ {
var movieExists = listMovies.Any(c => c.TmdbId == movie.TmdbId || c.ImdbId == movie.ImdbId); var movieExists = listMovies.Any(c => c.TmdbId == movie.TmdbId || c.ImdbId == movie.ImdbId);
@ -206,8 +213,6 @@ namespace NzbDrone.Core.ImportLists
_logger.Info("{0} was in your library, but not found in your lists --> Removing from library and deleting files", movie); _logger.Info("{0} was in your library, but not found in your lists --> Removing from library and deleting files", movie);
_movieService.DeleteMovie(movie.Id, true); _movieService.DeleteMovie(movie.Id, true);
break; break;
default:
break;
} }
} }
} }

Loading…
Cancel
Save