mirror of https://github.com/lidarr/Lidarr
Fixed: Ignore '.unwanted' directory when importing.
This commit is contained in:
parent
099f24afea
commit
1c1549820b
|
@ -1,15 +1,17 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.Threading;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Download.Clients.Blackhole;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
||||
{
|
||||
|
@ -33,6 +35,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
|||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(c => c.GetFileSize(It.IsAny<string>()))
|
||||
.Returns(1000000);
|
||||
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
|
||||
}
|
||||
|
||||
protected void GivenChangedItem()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -10,6 +11,7 @@ using NzbDrone.Common.Http;
|
|||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Blackhole;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Test.Common;
|
||||
|
@ -48,6 +50,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
|||
Mocker.GetMock<ITorrentFileInfoReader>()
|
||||
.Setup(c => c.GetHashFromTorrentFile(It.IsAny<byte[]>()))
|
||||
.Returns("myhash");
|
||||
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny<string>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
|
||||
}
|
||||
|
||||
protected void GivenFailedDownload()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -10,6 +11,7 @@ using NzbDrone.Common.Disk;
|
|||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Blackhole;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
||||
|
@ -41,6 +43,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
|||
Mocker.GetMock<IDiskProvider>()
|
||||
.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>>()))
|
||||
.Returns<string, IEnumerable<string>>((b, s) => s.ToList());
|
||||
}
|
||||
|
||||
protected void GivenFailedDownload()
|
||||
|
|
|
@ -2,9 +2,11 @@ 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.Download;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
@ -13,7 +15,6 @@ using NzbDrone.Core.Qualities;
|
|||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
{
|
||||
|
@ -30,6 +31,9 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|||
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetAudioFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.FilterFiles(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>()))
|
||||
.Returns(_subFolders);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
|
@ -93,6 +93,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
|||
[TestCase("Plex Versions")]
|
||||
[TestCase(".secret")]
|
||||
[TestCase(".hidden")]
|
||||
[TestCase(".unwanted")]
|
||||
public void should_filter_certain_sub_folders(string subFolder)
|
||||
{
|
||||
var path = @"C:\Test\";
|
||||
|
@ -100,13 +101,9 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
|
|||
var specialFiles = GetFiles(path, subFolder).ToList();
|
||||
var allFiles = files.Concat(specialFiles);
|
||||
|
||||
var artist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.Path = path)
|
||||
.Build();
|
||||
|
||||
var filteredFiles = Subject.FilterFiles(artist, allFiles);
|
||||
var filteredFiles = Subject.FilterFiles(path, allFiles);
|
||||
filteredFiles.Should().NotContain(specialFiles);
|
||||
filteredFiles.Count.Should().BeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Crypto;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Download.Clients.Blackhole
|
||||
{
|
||||
|
@ -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 _diskProvider.GetDirectories(watchFolder))
|
||||
foreach (var folder in _diskScanService.FilterFiles(watchFolder, _diskProvider.GetDirectories(watchFolder)))
|
||||
{
|
||||
var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder));
|
||||
|
||||
|
@ -86,16 +86,16 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
|
|||
yield return newWatchItem;
|
||||
}
|
||||
|
||||
foreach (var videoFile in _diskScanService.GetAudioFiles(watchFolder, false))
|
||||
foreach (var audioFile in _diskScanService.FilterFiles(watchFolder, _diskScanService.GetAudioFiles(watchFolder, false)))
|
||||
{
|
||||
var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile));
|
||||
var title = FileNameBuilder.CleanFileName(Path.GetFileName(audioFile));
|
||||
|
||||
var newWatchItem = new WatchFolderItem
|
||||
{
|
||||
DownloadId = Path.GetFileName(videoFile) + "_" + _diskProvider.FileGetLastWrite(videoFile).Ticks,
|
||||
DownloadId = Path.GetFileName(audioFile) + "_" + _diskProvider.FileGetLastWrite(audioFile).Ticks,
|
||||
Title = title,
|
||||
|
||||
OutputPath = new OsPath(videoFile),
|
||||
OutputPath = new OsPath(audioFile),
|
||||
|
||||
Status = DownloadItemStatus.Completed,
|
||||
RemainingTime = TimeSpan.Zero
|
||||
|
@ -105,10 +105,10 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
|
|||
|
||||
if (PreCheckWatchItemExpiry(newWatchItem, oldWatchItem))
|
||||
{
|
||||
newWatchItem.TotalSize = _diskProvider.GetFileSize(videoFile);
|
||||
newWatchItem.Hash = GetHash(videoFile);
|
||||
newWatchItem.TotalSize = _diskProvider.GetFileSize(audioFile);
|
||||
newWatchItem.Hash = GetHash(audioFile);
|
||||
|
||||
if (_diskProvider.IsFileLocked(videoFile))
|
||||
if (_diskProvider.IsFileLocked(audioFile))
|
||||
{
|
||||
newWatchItem.Status = DownloadItemStatus.Downloading;
|
||||
}
|
||||
|
@ -193,4 +193,4 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
|
|||
return HashConverter.GetHash(data.ToString()).ToHexString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace NzbDrone.Core.Extras
|
|||
_logger.Debug("Looking for existing extra files in {0}", artist.Path);
|
||||
|
||||
var filesOnDisk = _diskScanService.GetNonAudioFiles(artist.Path);
|
||||
var possibleExtraFiles = _diskScanService.FilterFiles(artist, filesOnDisk);
|
||||
var possibleExtraFiles = _diskScanService.FilterFiles(artist.Path, filesOnDisk);
|
||||
|
||||
var filteredFiles = possibleExtraFiles;
|
||||
var importedFiles = new List<string>();
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
void Scan(Artist artist);
|
||||
string[] GetAudioFiles(string path, bool allDirectories = true);
|
||||
string[] GetNonAudioFiles(string path, bool allDirectories = true);
|
||||
List<string> FilterFiles(Artist artist, IEnumerable<string> files);
|
||||
List<string> FilterFiles(string basePath, IEnumerable<string> files);
|
||||
}
|
||||
|
||||
public class DiskScanService :
|
||||
|
@ -59,9 +59,8 @@ namespace NzbDrone.Core.MediaFiles
|
|||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
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 ExcludedSubFoldersRegex = new Regex(@"(?:\\|\/|^)(?:extras|@eadir|extrafanart|plex versions|\.[^\\/]+)(?:\\|\/|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
private static readonly Regex ExcludedFilesRegex = new Regex(@"^\._|^Thumbs\.db$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public void Scan(Artist artist)
|
||||
{
|
||||
|
@ -101,7 +100,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
}
|
||||
|
||||
var musicFilesStopwatch = Stopwatch.StartNew();
|
||||
var mediaFileList = FilterFiles(artist, GetAudioFiles(artist.Path)).ToList();
|
||||
var mediaFileList = FilterFiles(artist.Path, GetAudioFiles(artist.Path)).ToList();
|
||||
musicFilesStopwatch.Stop();
|
||||
_logger.Trace("Finished getting track files for: {0} [{1}]", artist, musicFilesStopwatch.Elapsed);
|
||||
|
||||
|
@ -158,9 +157,9 @@ namespace NzbDrone.Core.MediaFiles
|
|||
return mediaFileList.ToArray();
|
||||
}
|
||||
|
||||
public List<string> FilterFiles(Artist artist, IEnumerable<string> files)
|
||||
public List<string> FilterFiles(string basePath, IEnumerable<string> files)
|
||||
{
|
||||
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(artist.Path.GetRelativePath(file)))
|
||||
return files.Where(file => !ExcludedSubFoldersRegex.IsMatch(basePath.GetRelativePath(file)))
|
||||
.Where(file => !ExcludedFilesRegex.IsMatch(Path.GetFileName(file)))
|
||||
.ToList();
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
};
|
||||
}
|
||||
|
||||
var audioFiles = _diskScanService.GetAudioFiles(directoryInfo.FullName);
|
||||
var audioFiles = _diskScanService.FilterFiles(directoryInfo.FullName, _diskScanService.GetAudioFiles(directoryInfo.FullName));
|
||||
|
||||
if (downloadClientItem == null)
|
||||
{
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
|
|||
|
||||
if (artist == null)
|
||||
{
|
||||
var files = _diskScanService.GetAudioFiles(folder);
|
||||
var files = _diskScanService.FilterFiles(folder, _diskScanService.GetAudioFiles(folder));
|
||||
|
||||
return files.Select(file => ProcessFile(file, downloadId, folder)).Where(i => i != null).ToList();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue