Fixed: Exclude OS X Metadata files when scanning for files

Fixes #533
pull/4/head
Mark McDowall 10 years ago
parent 6e7a2af86b
commit c3acfe34fe

@ -27,6 +27,11 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
@"C:\Test\movie"
};
GivenFiles();
}
private void GivenFiles()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<String>(), SearchOption.AllDirectories))
.Returns(_files);
@ -69,8 +74,20 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
public void should_return_video_files_only()
{
var path = @"C:\Test\";
var test = Subject.GetVideoFiles(path);
Subject.GetVideoFiles(path).Should().HaveCount(4);
}
[Test]
public void should_exclude_osx_metadata_files()
{
var path = @"C:\Test\";
_files = new [] { "._24 The Status Quo Combustion.mp4", "24 The Status Quo Combustion.mp4" };
GivenFiles();
Subject.GetVideoFiles(path).Should().HaveCount(1);
}
}
}

@ -60,6 +60,7 @@ namespace NzbDrone.Core.MediaFiles
private static readonly Regex ExcludedSubFoldersRegex = new Regex(@"(extras|@eadir)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedFoldersRegex = new Regex(@"(?:\\|\/)(\..+)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public void Scan(Series series)
{
@ -124,7 +125,9 @@ namespace NzbDrone.Core.MediaFiles
var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
var filesOnDisk = _diskProvider.GetFiles(path, searchOption);
var mediaFileList = filesOnDisk.Where(c => MediaFileExtensions.Extensions.Contains(Path.GetExtension(c).ToLower())).ToList();
var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file).ToLower()))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
.ToList();
_logger.Debug("{0} video files were found in {1}", mediaFileList.Count, path);
return mediaFileList.ToArray();
@ -133,7 +136,8 @@ namespace NzbDrone.Core.MediaFiles
private IEnumerable<string> FilterFiles(Series series, IEnumerable<string> videoFiles)
{
return videoFiles.Where(file => !ExcludedSubFoldersRegex.IsMatch(series.Path.GetRelativePath(file)))
.Where(file => !ExcludedFoldersRegex.IsMatch(file));
.Where(file => !ExcludedFoldersRegex.IsMatch(file))
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)));
}
private void SetPermissions(String path)

Loading…
Cancel
Save