Fixed: Filter direct excluded subfolders of the selected directory during manual import
This commit is contained in:
parent
ccdfdd1049
commit
a348d98dd9
|
@ -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.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
|||
.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.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,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.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ 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.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterPaths(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns<string, IEnumerable<string>>((b,s) => s.ToList());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
|||
var specialFiles = GetFiles(path, subFolder).ToList();
|
||||
var allFiles = files.Concat(specialFiles);
|
||||
|
||||
var filteredFiles = Subject.FilterFiles(path, allFiles);
|
||||
var filteredFiles = Subject.FilterPaths(path, allFiles);
|
||||
filteredFiles.Should().NotContain(specialFiles);
|
||||
filteredFiles.Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
|
|||
|
||||
private IEnumerable<WatchFolderItem> GetDownloadItems(string watchFolder, Dictionary<string, WatchFolderItem> lastWatchItems, TimeSpan waitPeriod)
|
||||
{
|
||||
foreach (var folder in _diskScanService.FilterFiles(watchFolder, _diskProvider.GetDirectories(watchFolder)))
|
||||
foreach (var folder in _diskScanService.FilterPaths(watchFolder, _diskProvider.GetDirectories(watchFolder)))
|
||||
{
|
||||
var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder));
|
||||
|
||||
|
@ -86,7 +86,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
|
|||
yield return newWatchItem;
|
||||
}
|
||||
|
||||
foreach (var videoFile in _diskScanService.FilterFiles(watchFolder, _diskScanService.GetVideoFiles(watchFolder, false)))
|
||||
foreach (var videoFile in _diskScanService.FilterPaths(watchFolder, _diskScanService.GetVideoFiles(watchFolder, false)))
|
||||
{
|
||||
var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile));
|
||||
|
||||
|
|
|
@ -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.FilterFiles(series.Path, filesOnDisk);
|
||||
var possibleExtraFiles = _diskScanService.FilterPaths(series.Path, filesOnDisk);
|
||||
|
||||
var filteredFiles = possibleExtraFiles;
|
||||
var importedFiles = new List<string>();
|
||||
|
|
|
@ -16,7 +16,6 @@ using NzbDrone.Core.Messaging.Commands;
|
|||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
|
@ -25,7 +24,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> FilterFiles(string basePath, IEnumerable<string> files);
|
||||
List<string> FilterPaths(string basePath, IEnumerable<string> files);
|
||||
}
|
||||
|
||||
public class DiskScanService :
|
||||
|
@ -63,7 +62,7 @@ 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 ExcludedSubFoldersRegex = new Regex(@"(?:\\|\/|^)(?:extras|@eadir|\.@__thumb|extrafanart|plex versions|\.[^\\/]+)(?:\\|\/|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._|^Thumbs\.db$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public void Scan(Series series)
|
||||
|
@ -106,7 +105,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
}
|
||||
|
||||
var videoFilesStopwatch = Stopwatch.StartNew();
|
||||
var mediaFileList = FilterFiles(series.Path, GetVideoFiles(series.Path)).ToList();
|
||||
var mediaFileList = FilterPaths(series.Path, GetVideoFiles(series.Path)).ToList();
|
||||
videoFilesStopwatch.Stop();
|
||||
_logger.Trace("Finished getting episode files for: {0} [{1}]", series, videoFilesStopwatch.Elapsed);
|
||||
|
||||
|
@ -166,10 +165,10 @@ namespace NzbDrone.Core.MediaFiles
|
|||
return mediaFileList.ToArray();
|
||||
}
|
||||
|
||||
public List<string> FilterFiles(string basePath, IEnumerable<string> files)
|
||||
public List<string> FilterPaths(string basePath, IEnumerable<string> paths)
|
||||
{
|
||||
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file)))
|
||||
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
|
||||
return paths.Where(path => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(path)))
|
||||
.Where(path => !ExcludedFilesRegex.IsMatch(Path.GetFileName(path)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
}
|
||||
|
||||
var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name);
|
||||
var videoFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetVideoFiles(directoryInfo.FullName));
|
||||
var videoFiles = _diskScanService.FilterPaths(directoryInfo.FullName, _diskScanService.GetVideoFiles(directoryInfo.FullName));
|
||||
|
||||
if (downloadClientItem == null)
|
||||
{
|
||||
|
|
|
@ -138,8 +138,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
|
|||
|
||||
if (series == null)
|
||||
{
|
||||
var files = _diskScanService.FilterFiles(baseFolder, _diskScanService.GetVideoFiles(baseFolder, false));
|
||||
var subfolders = _diskScanService.FilterFiles(baseFolder, _diskProvider.GetDirectories(baseFolder));
|
||||
// Filter paths based on the rootFolder, so files in subfolders that should be ignored are ignored.
|
||||
// It will lead to some extra directories being checked for files, but it saves the processing of them and is cleaner than
|
||||
// teaching FilterPaths to know whether it's processing a file or a folder and changing it's filtering based on that.
|
||||
|
||||
var files = _diskScanService.FilterPaths(rootFolder, _diskScanService.GetVideoFiles(baseFolder, false));
|
||||
var subfolders = _diskScanService.FilterPaths(rootFolder, _diskProvider.GetDirectories(baseFolder));
|
||||
|
||||
var processedFiles = files.Select(file => ProcessFile(rootFolder, baseFolder, file, downloadId));
|
||||
var processedFolders = subfolders.SelectMany(subfolder => ProcessFolder(rootFolder, subfolder, downloadId, null, filterExistingFiles));
|
||||
|
|
Loading…
Reference in New Issue