Browse Source

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

pull/1077/head
Jason Dove 3 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. 30
      ErsatzTV.Core/Metadata/MovieFolderScanner.cs
  4. 13
      ErsatzTV.Infrastructure/Data/Repositories/MediaItemRepository.cs

3
CHANGELOG.md

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
# Changelog
 Changelog
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/).
@ -7,6 +7,7 @@ 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
- Fix many transcoding failures caused by the colorspace filter
- Fix song playback with VAAPI and NVENC
- Fix edge case where some local movies would not automatically be restored from trash
### Changed
- Upgrade to dotnet 7

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

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

30
ErsatzTV.Core/Metadata/MovieFolderScanner.cs

@ -18,6 +18,7 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner @@ -18,6 +18,7 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
private readonly IClient _client;
private readonly IFallbackMetadataProvider _fallbackMetadataProvider;
private readonly ILibraryRepository _libraryRepository;
private readonly IMediaItemRepository _mediaItemRepository;
private readonly ILocalFileSystem _localFileSystem;
private readonly ILocalMetadataProvider _localMetadataProvider;
private readonly ILocalSubtitlesProvider _localSubtitlesProvider;
@ -64,6 +65,7 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner @@ -64,6 +65,7 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
_searchRepository = searchRepository;
_fallbackMetadataProvider = fallbackMetadataProvider;
_libraryRepository = libraryRepository;
_mediaItemRepository = mediaItemRepository;
_mediator = mediator;
_client = client;
_logger = logger;
@ -79,6 +81,8 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner @@ -79,6 +81,8 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
{
try
{
List<string> allTrashedItems = await _mediaItemRepository.GetAllTrashedItems(libraryPath);
decimal progressSpread = progressMax - progressMin;
var foldersCompleted = 0;
@ -133,16 +137,26 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner @@ -133,16 +137,26 @@ public class MovieFolderScanner : LocalFolderScanner, IMovieFolderScanner
.Filter(f => f.Path == movieFolder)
.HeadOrNone();
// skip folder if etag matches
if (await knownFolder.Map(f => f.Etag ?? string.Empty).IfNoneAsync(string.Empty) == etag)
bool etagMatches = 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;
}
}
_logger.LogDebug(
"UPDATE: Etag has changed for folder {Folder}",
movieFolder);
else
{
_logger.LogDebug(
"UPDATE: Etag has changed for folder {Folder}",
movieFolder);
}
foreach (string file in allFiles.OrderBy(identity))
{
// TODO: figure out how to rebuild playlists

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

@ -82,6 +82,19 @@ public class MediaItemRepository : IMediaItemRepository @@ -82,6 +82,19 @@ public class MediaItemRepository : IMediaItemRepository
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)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();

Loading…
Cancel
Save