From c6eb19c04d6a5ea01d0f471f1359c8ef51e90cd1 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 18 Jan 2017 20:14:51 -0800 Subject: [PATCH] Exclude .grab and Plex Version folders New: Ignore .grab folder (Plex DVR) New: Ignore Plex Versions folder (Media Optimizer) Closes #1610 --- .../GetVideoFilesFixture.cs | 59 ++++++++++++++----- .../RootFolderServiceFixture.cs | 47 +++++++++++++++ .../MediaFiles/DiskScanService.cs | 2 +- .../RootFolders/RootFolderService.cs | 9 ++- 4 files changed, 99 insertions(+), 18 deletions(-) diff --git a/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs index 014ebaac8..397314def 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs @@ -1,39 +1,47 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { public class GetVideoFilesFixture : CoreTest { - private string[] _files; + private string[] _fileNames; [SetUp] public void Setup() { - _files = new[] + _fileNames = new[] { - @"C:\Test\30 Rock1.mkv", - @"C:\Test\30 Rock2.avi", - @"C:\Test\30 Rock3.MP4", - @"C:\Test\30 Rock4.wMv", - @"C:\Test\movie.exe", - @"C:\Test\movie" + @"30 Rock1.mkv", + @"30 Rock2.avi", + @"30 Rock3.MP4", + @"30 Rock4.wMv", + @"movie.exe", + @"movie" }; - - GivenFiles(); } - private void GivenFiles() + private IEnumerable GetFiles(string folder, string subFolder = "") { + return _fileNames.Select(f => Path.Combine(folder, subFolder, f)); + } + + private void GivenFiles(IEnumerable files) + { + var filesToReturn = files.ToArray(); Mocker.GetMock() - .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) - .Returns(_files); + .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Returns(filesToReturn); } [Test] @@ -73,8 +81,31 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests public void should_return_video_files_only() { var path = @"C:\Test\"; + GivenFiles(GetFiles(path)); 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.CreateNew() + .With(s => s.Path = path) + .Build(); + + var filteredFiles = Subject.FilterFiles(series, allFiles); + filteredFiles.Should().NotContain(specialFiles); + filteredFiles.Count.Should().BeGreaterThan(0); + } } } diff --git a/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs b/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs index 483531975..c325f307a 100644 --- a/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs +++ b/src/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs @@ -1,12 +1,16 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using FizzWare.NBuilder; +using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Core.Configuration; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.RootFolderTests @@ -102,6 +106,49 @@ namespace NzbDrone.Core.Test.RootFolderTests .Returns(path); Assert.Throws(() => 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.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() + .Setup(s => s.Get(It.IsAny())) + .Returns(rootFolder); + + Mocker.GetMock() + .Setup(s => s.GetAllSeries()) + .Returns(new List()); + + Mocker.GetMock() + .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); } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index 84a75e8e6..bf7ac5f0c 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -60,7 +60,7 @@ namespace NzbDrone.Core.MediaFiles _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); public void Scan(Series series) diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 446b13670..b22353474 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -37,7 +37,8 @@ namespace NzbDrone.Core.RootFolders ".appledb", ".appledesktop", ".appledouble", - "@eadir" + "@eadir", + ".grab" }; @@ -131,8 +132,10 @@ namespace NzbDrone.Core.RootFolders private List GetUnmappedFolders(string path) { _logger.Debug("Generating list of unmapped folders"); + if (string.IsNullOrEmpty(path)) throw new ArgumentException("Invalid path provided", nameof(path)); + } var results = new List(); var series = _seriesRepository.All().ToList(); @@ -143,8 +146,8 @@ namespace NzbDrone.Core.RootFolders return results; } - var seriesFolders = _diskProvider.GetDirectories(path).ToList(); - var unmappedFolders = seriesFolders.Except(series.Select(s => s.Path), PathEqualityComparer.Instance).ToList(); + var possibleSeriesFolders = _diskProvider.GetDirectories(path).ToList(); + var unmappedFolders = possibleSeriesFolders.Except(series.Select(s => s.Path), PathEqualityComparer.Instance).ToList(); foreach (string unmappedFolder in unmappedFolders) {