1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Skip various Extras directories during scan

Fixes: #4487
This commit is contained in:
Qstick 2020-07-01 21:48:13 -04:00
parent 8f791853ad
commit 4f22d135d6
7 changed files with 61 additions and 15 deletions

View File

@ -36,7 +36,7 @@ protected void GivenCompletedItem()
.Setup(c => c.GetFileSize(It.IsAny<string>()))
.Returns(1000000);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
}

View File

@ -51,7 +51,7 @@ public void Setup()
.Setup(c => c.GetHashFromTorrentFile(It.IsAny<byte[]>()))
.Returns("myhash");
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
}

View File

@ -42,7 +42,7 @@ public void Setup()
.Setup(c => c.OpenWriteStream(It.IsAny<string>()))
.Returns(() => new FileStream(GetTempFilePath(), FileMode.Create));
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<bool>()))
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
}

View File

@ -155,6 +155,50 @@ public void should_not_scan_extras_subfolder()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _movie), Times.Once());
}
[Test]
public void should_not_scan_various_extras_subfolders()
{
GivenMovieFolder();
GivenFiles(new List<string>
{
Path.Combine(_movie.Path, "Behind the Scenes", "file1.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Deleted Scenes", "file2.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Featurettes", "file3.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Interviews", "file4.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Samples", "file5.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Scenes", "file6.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Shorts", "file7.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Trailers", "file8.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "The Count of Monte Cristo (2002) (1080p BluRay x265 10bit Tigole).mkv").AsOsAgnostic(),
});
Subject.Scan(_movie);
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _movie), Times.Once());
}
[Test]
public void should_not_scan_featurettes_subfolders()
{
GivenMovieFolder();
GivenFiles(new List<string>
{
Path.Combine(_movie.Path, "Featurettes", "An Epic Reborn.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Featurettes", "Deleted & Alternate Scenes.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Featurettes", "En Garde - Multi-Angle Dailies.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "Featurettes", "Layer-By-Layer - Sound Design - Multiple Audio.mkv").AsOsAgnostic(),
Path.Combine(_movie.Path, "The Count of Monte Cristo (2002) (1080p BluRay x265 10bit Tigole).mkv").AsOsAgnostic(),
});
Subject.Scan(_movie);
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _movie), Times.Once());
}
[Test]
public void should_not_create_if_movie_folder_does_not_exist_and_create_folder_disabled()
{

View File

@ -36,7 +36,7 @@ public void Setup()
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(_videoFiles);
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(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>()))

View File

@ -41,7 +41,7 @@ public void Handle(MovieScannedEvent message)
_logger.Debug("Looking for existing extra files in {0}", movie.Path);
var filesOnDisk = _diskScanService.GetNonVideoFiles(movie.Path);
var possibleExtraFiles = _diskScanService.FilterFiles(movie.Path, filesOnDisk);
var possibleExtraFiles = _diskScanService.FilterFiles(movie.Path, filesOnDisk, false);
var filteredFiles = possibleExtraFiles;
var importedFiles = new List<string>();

View File

@ -24,7 +24,7 @@ public interface IDiskScanService
void Scan(Movie movie);
string[] GetVideoFiles(string path, bool allDirectories = true);
string[] GetNonVideoFiles(string path, bool allDirectories = true);
List<string> FilterFiles(string basePath, IEnumerable<string> files);
List<string> FilterFiles(string basePath, IEnumerable<string> files, bool filterExtras = true);
}
public class DiskScanService :
@ -39,8 +39,6 @@ public class DiskScanService :
private readonly IMediaFileTableCleanupService _mediaFileTableCleanupService;
private readonly IRootFolderService _rootFolderService;
private readonly IEventAggregator _eventAggregator;
private readonly IMediaFileService _movieFileRepository;
private readonly IRenameMovieFileService _renameMovieFiles;
private readonly Logger _logger;
public DiskScanService(IDiskProvider diskProvider,
@ -51,8 +49,6 @@ public DiskScanService(IDiskProvider diskProvider,
IMediaFileTableCleanupService mediaFileTableCleanupService,
IRootFolderService rootFolderService,
IEventAggregator eventAggregator,
IMediaFileService movieFileRepository,
IRenameMovieFileService renameMovieFiles,
Logger logger)
{
_diskProvider = diskProvider;
@ -63,12 +59,11 @@ public DiskScanService(IDiskProvider diskProvider,
_mediaFileTableCleanupService = mediaFileTableCleanupService;
_rootFolderService = rootFolderService;
_eventAggregator = eventAggregator;
_movieFileRepository = movieFileRepository;
_renameMovieFiles = renameMovieFiles;
_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(Movie movie)
@ -176,11 +171,18 @@ public string[] GetNonVideoFiles(string path, bool allDirectories = true)
return mediaFileList.ToArray();
}
public List<string> FilterFiles(string basePath, IEnumerable<string> files)
public List<string> FilterFiles(string basePath, IEnumerable<string> files, bool filterExtras = true)
{
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file)))
var filteredFiles = files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file)))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
.ToList();
if (filterExtras)
{
filteredFiles = filteredFiles.Where(file => !ExcludedExtrasSubFolderRegex.IsMatch(basePath.GetRelativePath(file))).ToList();
}
return filteredFiles;
}
private void SetPermissions(string path)