Fixed: Skip various Extras directories during scan

This commit is contained in:
Qstick 2020-07-01 21:48:13 -04:00 committed by Mark McDowall
parent 9889ab7b48
commit 4be626a44c
7 changed files with 62 additions and 10 deletions

View File

@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.GetFileSize(It.IsAny<string>()))
.Returns(1000000);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
}

View File

@ -58,7 +58,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.GetHashFromTorrentFile(It.IsAny<byte[]>()))
.Returns("myhash");
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
}

View File

@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Setup(c => c.OpenWriteStream(It.IsAny<string>()))
.Returns(() => new FileStream(GetTempFilePath(), FileMode.Create));
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
}

View File

@ -171,6 +171,50 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _series, false), Times.Never());
}
[Test]
public void should_not_scan_various_extras_subfolders()
{
GivenSeriesFolder();
GivenFiles(new List<string>
{
Path.Combine(_series.Path, "Behind the Scenes", "file1.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Deleted Scenes", "file2.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Featurettes", "file3.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Interviews", "file4.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Samples", "file5.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Scenes", "file6.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Shorts", "file7.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Trailers", "file8.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Series Title S01E01 (1080p BluRay x265 10bit Tigole).mkv").AsOsAgnostic(),
});
Subject.Scan(_series);
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _series), Times.Once());
}
[Test]
public void should_not_scan_featurettes_subfolders()
{
GivenSeriesFolder();
GivenFiles(new List<string>
{
Path.Combine(_series.Path, "Featurettes", "An Epic Reborn.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Featurettes", "Deleted & Alternate Scenes.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Featurettes", "En Garde - Multi-Angle Dailies.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Featurettes", "Layer-By-Layer - Sound Design - Multiple Audio.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "Series Title S01E01 (1080p BluRay x265 10bit Tigole).mkv").AsOsAgnostic(),
});
Subject.Scan(_series);
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _series), Times.Once());
}
[Test]
public void should_clean_but_not_import_if_series_folder_does_not_exist_and_create_folder_enabled()
{

View File

@ -34,8 +34,8 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(_videoFiles);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
.Returns<string, IEnumerable<string>>((b,s) => s.ToList());
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
.Returns(_subFolders);

View File

@ -41,7 +41,7 @@ namespace NzbDrone.Core.Extras
_logger.Debug("Looking for existing extra files in {0}", series.Path);
var filesOnDisk = _diskScanService.GetNonVideoFiles(series.Path);
var possibleExtraFiles = _diskScanService.FilterPaths(series.Path, filesOnDisk);
var possibleExtraFiles = _diskScanService.FilterPaths(series.Path, filesOnDisk, false);
var filteredFiles = possibleExtraFiles;
var importedFiles = new List<string>();

View File

@ -25,7 +25,7 @@ namespace NzbDrone.Core.MediaFiles
void Scan(Series series);
string[] GetVideoFiles(string path, bool allDirectories = true);
string[] GetNonVideoFiles(string path, bool allDirectories = true);
List<string> FilterPaths(string basePath, IEnumerable<string> files);
List<string> FilterPaths(string basePath, IEnumerable<string> files, bool filterExtras = true);
}
public class DiskScanService :
@ -69,7 +69,8 @@ namespace NzbDrone.Core.MediaFiles
_logger = logger;
}
private static readonly Regex ExcludedSubFoldersRegex = new Regex(@"(?:\\|\/|^)(?:extras|@eadir|\.@__thumb|extrafanart|plex versions|\.[^\\/]+)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedExtrasSubFolderRegex = new Regex(@"(?:\\|\/|^)(?:extras|extrafanart|behind the scenes|deleted scenes|featurettes|interviews|scenes|samples|shorts|trailers)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedSubFoldersRegex = new Regex(@"(?:\\|\/|^)(?:@eadir|\.@__thumb|plex versions|\.[^\\/]+)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._|^Thumbs\.db$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public void Scan(Series series)
@ -217,11 +218,18 @@ namespace NzbDrone.Core.MediaFiles
return mediaFileList.ToArray();
}
public List<string> FilterPaths(string basePath, IEnumerable<string> paths)
public List<string> FilterPaths(string basePath, IEnumerable<string> paths, bool filterExtras = true)
{
return paths.Where(path => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(path)))
var filteredPaths = paths.Where(path => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(path)))
.Where(path => !ExcludedFilesRegex.IsMatch(Path.GetFileName(path)))
.ToList();
if (filterExtras)
{
filteredPaths = filteredPaths.Where(path => !ExcludedExtrasSubFolderRegex.IsMatch(basePath.GetRelativePath(path))).ToList();
}
return filteredPaths;
}
private void SetPermissions(string path)