Browse Source

ignore dot-underscore files (#346)

pull/350/head
Jason Dove 5 years ago committed by GitHub
parent
commit
640044814c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 42
      ErsatzTV.Core.Tests/Metadata/MovieFolderScannerTests.cs
  3. 7
      ErsatzTV.Core/Metadata/MovieFolderScanner.cs
  4. 7
      ErsatzTV.Core/Metadata/MusicVideoFolderScanner.cs
  5. 9
      ErsatzTV.Core/Metadata/TelevisionFolderScanner.cs

2
CHANGELOG.md

@ -4,6 +4,8 @@ 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/).
## [Unreleased] ## [Unreleased]
### Fixed
- Fix all local library scanners to ignore dot underscore files (`._`)
## [0.0.54-alpha] - 2021-08-21 ## [0.0.54-alpha] - 2021-08-21
### Added ### Added

42
ErsatzTV.Core.Tests/Metadata/MovieFolderScannerTests.cs

@ -405,6 +405,48 @@ namespace ErsatzTV.Core.Tests.Metadata
It.Is<Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)), It.Is<Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
Times.Once); Times.Once);
} }
[Test]
public async Task Should_Ignore_Dot_Underscore_Files(
[ValueSource(typeof(LocalFolderScanner), nameof(LocalFolderScanner.VideoFileExtensions))]
string videoExtension)
{
string moviePath = Path.Combine(
FakeRoot,
Path.Combine("Movie (2020)", $"Movie (2020){videoExtension}"));
MovieFolderScanner service = GetService(
new FakeFileEntry(moviePath) { LastWriteTime = DateTime.Now },
new FakeFileEntry(
Path.Combine(
Path.GetDirectoryName(moviePath) ?? string.Empty,
$"._Movie (2020){videoExtension}"))
);
var libraryPath = new LibraryPath
{ Id = 1, Path = FakeRoot, LibraryFolders = new List<LibraryFolder>() };
Either<BaseError, Unit> result = await service.ScanFolder(
libraryPath,
FFprobePath,
0,
1);
result.IsRight.Should().BeTrue();
_movieRepository.Verify(x => x.GetOrAdd(It.IsAny<LibraryPath>(), It.IsAny<string>()), Times.Once);
_movieRepository.Verify(x => x.GetOrAdd(libraryPath, moviePath), Times.Once);
_localStatisticsProvider.Verify(
x => x.RefreshStatistics(
FFprobePath,
It.Is<Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
Times.Once);
_localMetadataProvider.Verify(
x => x.RefreshFallbackMetadata(
It.Is<Movie>(i => i.MediaVersions.Head().MediaFiles.Head().Path == moviePath)),
Times.Once);
}
[Test] [Test]
public async Task Should_Ignore_Extra_Folders( public async Task Should_Ignore_Extra_Folders(

7
ErsatzTV.Core/Metadata/MovieFolderScanner.cs

@ -87,6 +87,7 @@ namespace ErsatzTV.Core.Metadata
var allFiles = filesForEtag var allFiles = filesForEtag
.Filter(f => VideoFileExtensions.Contains(Path.GetExtension(f))) .Filter(f => VideoFileExtensions.Contains(Path.GetExtension(f)))
.Filter(f => !Path.GetFileName(f).StartsWith("._"))
.Filter( .Filter(
f => !ExtraFiles.Any( f => !ExtraFiles.Any(
e => Path.GetFileNameWithoutExtension(f).EndsWith(e, StringComparison.OrdinalIgnoreCase))) e => Path.GetFileNameWithoutExtension(f).EndsWith(e, StringComparison.OrdinalIgnoreCase)))
@ -157,6 +158,12 @@ namespace ErsatzTV.Core.Metadata
List<int> ids = await _movieRepository.DeleteByPath(libraryPath, path); List<int> ids = await _movieRepository.DeleteByPath(libraryPath, path);
await _searchIndex.RemoveItems(ids); await _searchIndex.RemoveItems(ids);
} }
else if (Path.GetFileName(path).StartsWith("._"))
{
_logger.LogInformation("Removing dot underscore file at {Path}", path);
List<int> ids = await _movieRepository.DeleteByPath(libraryPath, path);
await _searchIndex.RemoveItems(ids);
}
} }
_searchIndex.Commit(); _searchIndex.Commit();

7
ErsatzTV.Core/Metadata/MusicVideoFolderScanner.cs

@ -134,6 +134,12 @@ namespace ErsatzTV.Core.Metadata
List<int> musicVideoIds = await _musicVideoRepository.DeleteByPath(libraryPath, path); List<int> musicVideoIds = await _musicVideoRepository.DeleteByPath(libraryPath, path);
await _searchIndex.RemoveItems(musicVideoIds); await _searchIndex.RemoveItems(musicVideoIds);
} }
else if (Path.GetFileName(path).StartsWith("._"))
{
_logger.LogInformation("Removing dot underscore file at {Path}", path);
List<int> musicVideoIds = await _musicVideoRepository.DeleteByPath(libraryPath, path);
await _searchIndex.RemoveItems(musicVideoIds);
}
} }
List<int> artistIds = await _artistRepository.DeleteEmptyArtists(libraryPath); List<int> artistIds = await _artistRepository.DeleteEmptyArtists(libraryPath);
@ -238,6 +244,7 @@ namespace ErsatzTV.Core.Metadata
var allFiles = _localFileSystem.ListFiles(musicVideoFolder) var allFiles = _localFileSystem.ListFiles(musicVideoFolder)
.Filter(f => VideoFileExtensions.Contains(Path.GetExtension(f))) .Filter(f => VideoFileExtensions.Contains(Path.GetExtension(f)))
.Filter(f => !Path.GetFileName(f).StartsWith("._"))
.ToList(); .ToList();
foreach (string subdirectory in _localFileSystem.ListSubdirectories(musicVideoFolder) foreach (string subdirectory in _localFileSystem.ListSubdirectories(musicVideoFolder)

9
ErsatzTV.Core/Metadata/TelevisionFolderScanner.cs

@ -124,6 +124,11 @@ namespace ErsatzTV.Core.Metadata
_logger.LogInformation("Removing missing episode at {Path}", path); _logger.LogInformation("Removing missing episode at {Path}", path);
await _televisionRepository.DeleteByPath(libraryPath, path); await _televisionRepository.DeleteByPath(libraryPath, path);
} }
else if (Path.GetFileName(path).StartsWith("._"))
{
_logger.LogInformation("Removing dot underscore file at {Path}", path);
await _televisionRepository.DeleteByPath(libraryPath, path);
}
} }
await _televisionRepository.DeleteEmptySeasons(libraryPath); await _televisionRepository.DeleteEmptySeasons(libraryPath);
@ -201,7 +206,9 @@ namespace ErsatzTV.Core.Metadata
string seasonPath) string seasonPath)
{ {
foreach (string file in _localFileSystem.ListFiles(seasonPath) foreach (string file in _localFileSystem.ListFiles(seasonPath)
.Filter(f => VideoFileExtensions.Contains(Path.GetExtension(f))).OrderBy(identity)) .Filter(f => VideoFileExtensions.Contains(Path.GetExtension(f)))
.Filter(f => !Path.GetFileName(f).StartsWith("._"))
.OrderBy(identity))
{ {
// TODO: figure out how to rebuild playlists // TODO: figure out how to rebuild playlists
Either<BaseError, Episode> maybeEpisode = await _televisionRepository Either<BaseError, Episode> maybeEpisode = await _televisionRepository

Loading…
Cancel
Save