Remove missing media (#40)

* remove movies that are no longer present on disk

* remove missing episodes, empty seasons, empty shows
This commit is contained in:
Jason Dove
2021-03-06 12:43:38 +00:00
committed by GitHub
parent 363eb2c276
commit 51cdb372b9
8 changed files with 164 additions and 8 deletions
@@ -13,5 +13,7 @@ namespace ErsatzTV.Core.Interfaces.Repositories
Task<bool> Update(Movie movie);
Task<int> GetMovieCount();
Task<List<MovieMetadata>> GetPagedMovies(int pageNumber, int pageSize);
Task<IEnumerable<string>> FindMoviePaths(LibraryPath libraryPath);
Task<Unit> DeleteByPath(LibraryPath libraryPath, string path);
}
}
@@ -27,6 +27,9 @@ namespace ErsatzTV.Core.Interfaces.Repositories
Task<Either<BaseError, Show>> AddShow(int libraryPathId, string showFolder, ShowMetadata metadata);
Task<Either<BaseError, Season>> GetOrAddSeason(Show show, int libraryPathId, int seasonNumber);
Task<Either<BaseError, Episode>> GetOrAddEpisode(Season season, LibraryPath libraryPath, string path);
Task<Unit> DeleteEmptyShows();
Task<IEnumerable<string>> FindEpisodePaths(LibraryPath libraryPath);
Task<Unit> DeleteByPath(LibraryPath libraryPath, string path);
Task<Unit> DeleteEmptySeasons(LibraryPath libraryPath);
Task<Unit> DeleteEmptyShows(LibraryPath libraryPath);
}
}
@@ -71,6 +71,7 @@ namespace ErsatzTV.Core.Metadata
continue;
}
foreach (string file in allFiles.OrderBy(identity))
{
// TODO: optimize dbcontext use here, do we need tracking? can we make partial updates with dapper?
@@ -86,6 +87,15 @@ namespace ErsatzTV.Core.Metadata
}
}
foreach (string path in await _movieRepository.FindMoviePaths(libraryPath))
{
if (!_localFileSystem.FileExists(path))
{
_logger.LogInformation("Removing missing movie at {Path}", path);
await _movieRepository.DeleteByPath(libraryPath, path);
}
}
return Unit.Default;
}
@@ -63,7 +63,17 @@ namespace ErsatzTV.Core.Metadata
_ => Task.FromResult(Unit.Default));
}
await _televisionRepository.DeleteEmptyShows();
foreach (string path in await _televisionRepository.FindEpisodePaths(libraryPath))
{
if (!_localFileSystem.FileExists(path))
{
_logger.LogInformation("Removing missing episode at {Path}", path);
await _televisionRepository.DeleteByPath(libraryPath, path);
}
}
await _televisionRepository.DeleteEmptySeasons(libraryPath);
await _televisionRepository.DeleteEmptyShows(libraryPath);
return Unit.Default;
}