Exclude .grab and Plex Version folders

New: Ignore .grab folder (Plex DVR)
New: Ignore Plex Versions folder (Media Optimizer)
Closes #1610
pull/6/head
Mark McDowall 8 years ago
parent 38b65ba27d
commit c6eb19c04d

@ -1,39 +1,47 @@
using System.IO; using System.Collections.Generic;
using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
{ {
public class GetVideoFilesFixture : CoreTest<DiskScanService> public class GetVideoFilesFixture : CoreTest<DiskScanService>
{ {
private string[] _files; private string[] _fileNames;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_files = new[] _fileNames = new[]
{ {
@"C:\Test\30 Rock1.mkv", @"30 Rock1.mkv",
@"C:\Test\30 Rock2.avi", @"30 Rock2.avi",
@"C:\Test\30 Rock3.MP4", @"30 Rock3.MP4",
@"C:\Test\30 Rock4.wMv", @"30 Rock4.wMv",
@"C:\Test\movie.exe", @"movie.exe",
@"C:\Test\movie" @"movie"
}; };
}
GivenFiles(); private IEnumerable<string> GetFiles(string folder, string subFolder = "")
{
return _fileNames.Select(f => Path.Combine(folder, subFolder, f));
} }
private void GivenFiles() private void GivenFiles(IEnumerable<string> files)
{ {
var filesToReturn = files.ToArray();
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories)) .Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories))
.Returns(_files); .Returns(filesToReturn);
} }
[Test] [Test]
@ -73,8 +81,31 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
public void should_return_video_files_only() public void should_return_video_files_only()
{ {
var path = @"C:\Test\"; var path = @"C:\Test\";
GivenFiles(GetFiles(path));
Subject.GetVideoFiles(path).Should().HaveCount(4); Subject.GetVideoFiles(path).Should().HaveCount(4);
} }
[TestCase("Extras")]
[TestCase("@eadir")]
[TestCase("extrafanart")]
[TestCase("Plex Versions")]
[TestCase(".secret")]
[TestCase(".hidden")]
public void should_filter_certain_sub_folders(string subFolder)
{
var path = @"C:\Test\";
var files = GetFiles(path).ToList();
var specialFiles = GetFiles(path, subFolder).ToList();
var allFiles = files.Concat(specialFiles);
var series = Builder<Series>.CreateNew()
.With(s => s.Path = path)
.Build();
var filteredFiles = Subject.FilterFiles(series, allFiles);
filteredFiles.Should().NotContain(specialFiles);
filteredFiles.Count.Should().BeGreaterThan(0);
}
} }
} }

@ -1,12 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.RootFolderTests namespace NzbDrone.Core.Test.RootFolderTests
@ -102,6 +106,49 @@ namespace NzbDrone.Core.Test.RootFolderTests
.Returns(path); .Returns(path);
Assert.Throws<InvalidOperationException>(() => Subject.Add(new RootFolder { Path = path })); Assert.Throws<InvalidOperationException>(() => Subject.Add(new RootFolder { Path = path }));
}
[TestCase("$recycle.bin")]
[TestCase("system volume information")]
[TestCase("recycler")]
[TestCase("lost+found")]
[TestCase(".appledb")]
[TestCase(".appledesktop")]
[TestCase(".appledouble")]
[TestCase("@eadir")]
[TestCase(".grab")]
public void should_get_root_folder_with_subfolders_excluding_special_sub_folders(string subFolder)
{
var rootFolder = Builder<RootFolder>.CreateNew()
.With(r => r.Path = @"C:\Test\TV")
.Build();
var subFolders = new[]
{
"Series1",
"Series2",
"Series3",
subFolder
};
var folders = subFolders.Select(f => Path.Combine(@"C:\Test\TV", f)).ToArray();
Mocker.GetMock<IRootFolderRepository>()
.Setup(s => s.Get(It.IsAny<int>()))
.Returns(rootFolder);
Mocker.GetMock<ISeriesService>()
.Setup(s => s.GetAllSeries())
.Returns(new List<Series>());
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(rootFolder.Path))
.Returns(folders);
var unmappedFolders = Subject.Get(rootFolder.Id).UnmappedFolders;
unmappedFolders.Count.Should().BeGreaterThan(0);
unmappedFolders.Should().NotContain(u => u.Name == subFolder);
} }
} }
} }

@ -60,7 +60,7 @@ namespace NzbDrone.Core.MediaFiles
_logger = logger; _logger = logger;
} }
private static readonly Regex ExcludedSubFoldersRegex = new Regex(@"(?:\\|\/|^)(extras|@eadir|extrafanart|\..+)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex ExcludedSubFoldersRegex = new Regex(@"(?:\\|\/|^)(extras|@eadir|extrafanart|plex\sversions|\..+)(?:\\|\/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._|Thumbs\.db", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._|Thumbs\.db", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public void Scan(Series series) public void Scan(Series series)

@ -37,7 +37,8 @@ namespace NzbDrone.Core.RootFolders
".appledb", ".appledb",
".appledesktop", ".appledesktop",
".appledouble", ".appledouble",
"@eadir" "@eadir",
".grab"
}; };
@ -131,8 +132,10 @@ namespace NzbDrone.Core.RootFolders
private List<UnmappedFolder> GetUnmappedFolders(string path) private List<UnmappedFolder> GetUnmappedFolders(string path)
{ {
_logger.Debug("Generating list of unmapped folders"); _logger.Debug("Generating list of unmapped folders");
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
throw new ArgumentException("Invalid path provided", nameof(path)); throw new ArgumentException("Invalid path provided", nameof(path));
}
var results = new List<UnmappedFolder>(); var results = new List<UnmappedFolder>();
var series = _seriesRepository.All().ToList(); var series = _seriesRepository.All().ToList();
@ -143,8 +146,8 @@ namespace NzbDrone.Core.RootFolders
return results; return results;
} }
var seriesFolders = _diskProvider.GetDirectories(path).ToList(); var possibleSeriesFolders = _diskProvider.GetDirectories(path).ToList();
var unmappedFolders = seriesFolders.Except(series.Select(s => s.Path), PathEqualityComparer.Instance).ToList(); var unmappedFolders = possibleSeriesFolders.Except(series.Select(s => s.Path), PathEqualityComparer.Instance).ToList();
foreach (string unmappedFolder in unmappedFolders) foreach (string unmappedFolder in unmappedFolders)
{ {

Loading…
Cancel
Save