Browse Source

properly unflag local movies that are now present on disk (#1076)

pull/1077/head
Jason Dove 4 years ago committed by GitHub
parent
commit
e2b3c1ce8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 1
      ErsatzTV.Core/Interfaces/Repositories/IMediaItemRepository.cs
  3. 28
      ErsatzTV.Core/Metadata/MovieFolderScanner.cs
  4. 13
      ErsatzTV.Infrastructure/Data/Repositories/MediaItemRepository.cs

3
CHANGELOG.md

@ -1,4 +1,4 @@
# Changelog  Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed ### Fixed
- Fix many transcoding failures caused by the colorspace filter - Fix many transcoding failures caused by the colorspace filter
- Fix song playback with VAAPI and NVENC - Fix song playback with VAAPI and NVENC
- Fix edge case where some local movies would not automatically be restored from trash
### Changed ### Changed
- Upgrade to dotnet 7 - Upgrade to dotnet 7

1
ErsatzTV.Core/Interfaces/Repositories/IMediaItemRepository.cs

@ -10,4 +10,5 @@ public interface IMediaItemRepository
Task<List<int>> FlagFileNotFound(LibraryPath libraryPath, string path); Task<List<int>> FlagFileNotFound(LibraryPath libraryPath, string path);
Task<Unit> FlagNormal(MediaItem mediaItem); Task<Unit> FlagNormal(MediaItem mediaItem);
Task<Either<BaseError, Unit>> DeleteItems(List<int> mediaItemIds); Task<Either<BaseError, Unit>> DeleteItems(List<int> mediaItemIds);
Task<List<string>> GetAllTrashedItems(LibraryPath libraryPath);
} }

28
ErsatzTV.Core/Metadata/MovieFolderScanner.cs

@ -18,6 +18,7 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
private readonly IClient _client; private readonly IClient _client;
private readonly IFallbackMetadataProvider _fallbackMetadataProvider; private readonly IFallbackMetadataProvider _fallbackMetadataProvider;
private readonly ILibraryRepository _libraryRepository; private readonly ILibraryRepository _libraryRepository;
private readonly IMediaItemRepository _mediaItemRepository;
private readonly ILocalFileSystem _localFileSystem; private readonly ILocalFileSystem _localFileSystem;
private readonly ILocalMetadataProvider _localMetadataProvider; private readonly ILocalMetadataProvider _localMetadataProvider;
private readonly ILocalSubtitlesProvider _localSubtitlesProvider; private readonly ILocalSubtitlesProvider _localSubtitlesProvider;
@ -64,6 +65,7 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
_searchRepository = searchRepository; _searchRepository = searchRepository;
_fallbackMetadataProvider = fallbackMetadataProvider; _fallbackMetadataProvider = fallbackMetadataProvider;
_libraryRepository = libraryRepository; _libraryRepository = libraryRepository;
_mediaItemRepository = mediaItemRepository;
_mediator = mediator; _mediator = mediator;
_client = client; _client = client;
_logger = logger; _logger = logger;
@ -79,6 +81,8 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
{ {
try try
{ {
List<string> allTrashedItems = await _mediaItemRepository.GetAllTrashedItems(libraryPath);
decimal progressSpread = progressMax - progressMin; decimal progressSpread = progressMax - progressMin;
var foldersCompleted = 0; var foldersCompleted = 0;
@ -133,15 +137,25 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
.Filter(f => f.Path == movieFolder) .Filter(f => f.Path == movieFolder)
.HeadOrNone(); .HeadOrNone();
// skip folder if etag matches bool etagMatches = await knownFolder.Map(f => f.Etag ?? string.Empty).IfNoneAsync(string.Empty) == etag;
if (await knownFolder.Map(f => f.Etag ?? string.Empty).IfNoneAsync(string.Empty) == etag) if (etagMatches)
{ {
continue; if (allFiles.Any(allTrashedItems.Contains))
{
_logger.LogDebug("Previously trashed items are now present in folder {Folder}", movieFolder);
}
else
{
// etag matches and no trashed items are now present, continue to next folder
continue;
}
}
else
{
_logger.LogDebug(
"UPDATE: Etag has changed for folder {Folder}",
movieFolder);
} }
_logger.LogDebug(
"UPDATE: Etag has changed for folder {Folder}",
movieFolder);
foreach (string file in allFiles.OrderBy(identity)) foreach (string file in allFiles.OrderBy(identity))
{ {

13
ErsatzTV.Infrastructure/Data/Repositories/MediaItemRepository.cs

@ -82,6 +82,19 @@ public class MediaItemRepository : IMediaItemRepository
return ids; return ids;
} }
public async Task<List<string>> GetAllTrashedItems(LibraryPath libraryPath)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
return await dbContext.Connection.QueryAsync<string>(
@"SELECT MF.Path
FROM MediaItem M
INNER JOIN MediaVersion MV on M.Id = COALESCE(MovieId, MusicVideoId, OtherVideoId, SongId, EpisodeId)
INNER JOIN MediaFile MF on MV.Id = MF.MediaVersionId
WHERE M.State IN (1,2) AND M.LibraryPathId = @LibraryPathId",
new { LibraryPathId = libraryPath.Id })
.Map(list => list.ToList());
}
public async Task<Unit> FlagNormal(MediaItem mediaItem) public async Task<Unit> FlagNormal(MediaItem mediaItem)
{ {
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();

Loading…
Cancel
Save