From e635e816f62c7ae7bd52ddb54aba7401434e5a5e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 7 Mar 2013 13:49:00 +0900 Subject: [PATCH] moved moving of episode files into their own service. --- .../JobTests/RenameSeasonJobFixture.cs | 19 +--- .../EpisodeFileMoverFixture.cs} | 24 ++--- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 +- .../ProcessDownloadFixture.cs | 6 +- .../ProcessVideoFileFixture.cs | 2 +- .../Jobs/Implementations/RenameSeasonJob.cs | 10 +- .../Jobs/Implementations/RenameSeriesJob.cs | 14 ++- .../MediaFiles/EpisodeFileMovingService.cs | 97 +++++++++++++++++++ NzbDrone.Core/NzbDrone.Core.csproj | 1 + NzbDrone.Core/Providers/DiskScanProvider.cs | 73 +------------- .../Providers/PostDownloadProvider.cs | 9 +- 11 files changed, 135 insertions(+), 122 deletions(-) rename NzbDrone.Core.Test/{ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs => MediaFileTests/EpisodeFileMoverFixture.cs} (89%) create mode 100644 NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs diff --git a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs index 90daf432e..45b7a80a6 100644 --- a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs +++ b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs @@ -1,17 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using FizzWare.NBuilder; -using Moq; using NUnit.Framework; using NzbDrone.Core.Jobs.Implementations; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; -using NzbDrone.Core.Jobs; using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.JobTests @@ -22,7 +17,7 @@ namespace NzbDrone.Core.Test.JobTests private ProgressNotification _testNotification; private Series _series; private IList _episodeFiles; - + [SetUp] public void Setup() { @@ -47,24 +42,18 @@ namespace NzbDrone.Core.Test.JobTests .Returns(_episodeFiles.ToList()); } - private void WithMovedFiles() - { - Mocker.GetMock() - .Setup(s => s.MoveEpisodeFile(It.IsAny(), false)) - .Returns(_episodeFiles.First()); - } [Test] public void should_throw_if_seriesId_is_zero() { - Assert.Throws(() => + Assert.Throws(() => Mocker.Resolve().Start(_testNotification, new { SeriesId = 0, SeasonNumber = 10 })); } [Test] public void should_throw_if_seasonId_is_less_than_zero() { - Assert.Throws(() => + Assert.Throws(() => Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.Id, SeasonNumber = -10 })); } @@ -76,6 +65,6 @@ namespace NzbDrone.Core.Test.JobTests ExceptionVerification.ExpectedWarns(1); } - + } } diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs b/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs similarity index 89% rename from NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs rename to NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs index 6094e0c12..ba74c8fd2 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/MoveEpisodeFileFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/EpisodeFileMoverFixture.cs @@ -1,30 +1,20 @@ -using System; -using System.Collections.Generic; -using System.IO; +using System.IO; using System.Linq; -using System.Linq.Expressions; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; -using NzbDrone.Core.Download; -using NzbDrone.Core.ExternalNotification; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Organizer; using NzbDrone.Core.Qualities; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers; - using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv; using NzbDrone.Test.Common; -using NzbDrone.Test.Common.AutoMoq; -namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests +namespace NzbDrone.Core.Test.MediaFileTests { - // ReSharper disable InconsistentNaming - public class MoveEpisodeFileFixture : CoreTest + public class EpisodeFileMoverFixture : CoreTest { [Test] public void should_not_move_file_if_source_and_destination_are_the_same_path() @@ -66,7 +56,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Returns(fi); //Act - var result = Mocker.Resolve().MoveEpisodeFile(file, false); + var result = Subject.MoveEpisodeFile(file, false); //Assert result.Should().BeNull(); @@ -119,7 +109,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(s => s.FileExists(currentFilename)) .Returns(true); - var result = Mocker.Resolve().MoveEpisodeFile(file, true); + var result = Subject.MoveEpisodeFile(file, true); } @@ -167,7 +157,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests .Setup(e => e.BuildFilePath(It.IsAny(), fakeEpisode.First().SeasonNumber, filename, ".mkv")) .Returns(fi); - var result = Mocker.Resolve().MoveEpisodeFile(file, true); + var result = Subject.MoveEpisodeFile(file, true); result.Should().BeNull(); ExceptionVerification.ExpectedErrors(1); diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index f2a92f00b..5be2117b0 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -153,6 +153,7 @@ + @@ -217,7 +218,6 @@ - diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs index 9aec10123..96acce702 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs @@ -233,7 +233,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.GetMock().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder)); Mocker.GetMock().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes()); Mocker.GetMock().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles); - Mocker.GetMock().Setup(s => s.MoveEpisodeFile(It.IsAny(), true)).Returns(new EpisodeFile()); + Mocker.GetMock().Setup(s => s.MoveEpisodeFile(It.IsAny(), true)).Returns(new EpisodeFile()); Mocker.Resolve().ProcessDownload(droppedFolder); @@ -298,7 +298,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.GetMock().Setup(s => s.GetByTitle("office")).Returns(fakeSeries); Mocker.GetMock().Setup(s => s.CleanUpDropFolder(droppedFolder.FullName)); - Mocker.GetMock().Setup(s => s.MoveEpisodeFile(It.IsAny(), true)).Returns(new EpisodeFile()); + Mocker.GetMock().Setup(s => s.MoveEpisodeFile(It.IsAny(), true)).Returns(new EpisodeFile()); Mocker.GetMock().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes()); Mocker.GetMock().Setup(s => s.DeleteFolder(droppedFolder.FullName, true)); Mocker.GetMock().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true); @@ -330,7 +330,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.Resolve().ProcessDownload(droppedFolder); //Assert - Mocker.GetMock().Verify(c => c.MoveEpisodeFile(It.IsAny(), true), + Mocker.GetMock().Verify(c => c.MoveEpisodeFile(It.IsAny(), true), Times.Exactly(fakeEpisodeFiles.Count)); Mocker.VerifyAllMocks(); } diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs index 5145753e9..128755675 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs @@ -136,7 +136,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.Resolve().ProcessVideoFile(file); //Assert - Mocker.GetMock().Verify(s => s.MoveEpisodeFile(It.IsAny(), true), Times.Once()); + Mocker.GetMock().Verify(s => s.MoveEpisodeFile(It.IsAny(), true), Times.Once()); ExceptionVerification.IgnoreWarns(); } diff --git a/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs index 140a922e5..b6553ff33 100644 --- a/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs +++ b/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs @@ -6,7 +6,6 @@ using NzbDrone.Common.Eventing; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Jobs.Implementations @@ -14,19 +13,18 @@ namespace NzbDrone.Core.Jobs.Implementations public class RenameSeasonJob : IJob { private readonly IMediaFileService _mediaFileService; - private readonly DiskScanProvider _diskScanProvider; private readonly ISeriesRepository _seriesRepository; private readonly IEventAggregator _eventAggregator; + private readonly IMoveEpisodeFiles _episodeFilesMover; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public RenameSeasonJob(IMediaFileService mediaFileService, DiskScanProvider diskScanProvider, - ISeriesRepository seriesRepository, IEventAggregator eventAggregator) + public RenameSeasonJob(IMediaFileService mediaFileService, ISeriesRepository seriesRepository, IEventAggregator eventAggregator, IMoveEpisodeFiles episodeFilesMover) { _mediaFileService = mediaFileService; - _diskScanProvider = diskScanProvider; _seriesRepository = seriesRepository; _eventAggregator = eventAggregator; + _episodeFilesMover = episodeFilesMover; } public string Name @@ -68,7 +66,7 @@ namespace NzbDrone.Core.Jobs.Implementations try { var oldFile = new EpisodeFile(episodeFile); - var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile); + var newFile = _episodeFilesMover.MoveEpisodeFile(episodeFile); if (newFile != null) { diff --git a/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs index 75a3c552c..d6ea87778 100644 --- a/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs +++ b/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs @@ -6,7 +6,6 @@ using NzbDrone.Common.Eventing; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Jobs.Implementations @@ -14,19 +13,18 @@ namespace NzbDrone.Core.Jobs.Implementations public class RenameSeriesJob : IJob { private readonly IMediaFileService _mediaFileService; - private readonly DiskScanProvider _diskScanProvider; private readonly ISeriesRepository _seriesRepository; private readonly IEventAggregator _eventAggregator; + private readonly IMoveEpisodeFiles _moveEpisodeFiles; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RenameSeriesJob(IMediaFileService mediaFileService, DiskScanProvider diskScanProvider, - ISeriesRepository seriesRepository,IEventAggregator eventAggregator) + public RenameSeriesJob(IMediaFileService mediaFileService, ISeriesRepository seriesRepository, IEventAggregator eventAggregator, IMoveEpisodeFiles moveEpisodeFiles) { _mediaFileService = mediaFileService; - _diskScanProvider = diskScanProvider; _seriesRepository = seriesRepository; _eventAggregator = eventAggregator; + _moveEpisodeFiles = moveEpisodeFiles; } public string Name @@ -50,10 +48,10 @@ namespace NzbDrone.Core.Jobs.Implementations else { - seriesToRename = new List{ _seriesRepository.Get((int)options.SeriesId) }; + seriesToRename = new List { _seriesRepository.Get((int)options.SeriesId) }; } - foreach(var series in seriesToRename) + foreach (var series in seriesToRename) { notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title); @@ -74,7 +72,7 @@ namespace NzbDrone.Core.Jobs.Implementations try { var oldFile = new EpisodeFile(episodeFile); - var newFile = _diskScanProvider.MoveEpisodeFile(episodeFile); + var newFile = _moveEpisodeFiles.MoveEpisodeFile(episodeFile); if (newFile != null) { diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs new file mode 100644 index 000000000..5a7ef9ba6 --- /dev/null +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -0,0 +1,97 @@ +using System; +using System.IO; +using System.Linq; +using NLog; +using NzbDrone.Common; +using NzbDrone.Common.Eventing; +using NzbDrone.Core.Download; +using NzbDrone.Core.Organizer; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.MediaFiles +{ + public interface IMoveEpisodeFiles + { + EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false); + } + + public class MoveEpisodeFiles : IMoveEpisodeFiles + { + private readonly ISeriesRepository _seriesRepository; + private readonly IEpisodeService _episodeService; + private readonly IBuildFileNames _buildFileNames; + private readonly IMediaFileService _mediaFileService; + private readonly IEventAggregator _eventAggregator; + private readonly DiskProvider _diskProvider; + private readonly Logger _logger; + + public MoveEpisodeFiles(ISeriesRepository seriesRepository, IEpisodeService episodeService, IBuildFileNames buildFileNames, IMediaFileService mediaFileService, IEventAggregator eventAggregator, DiskProvider diskProvider, Logger logger) + { + _seriesRepository = seriesRepository; + _episodeService = episodeService; + _buildFileNames = buildFileNames; + _mediaFileService = mediaFileService; + _eventAggregator = eventAggregator; + _diskProvider = diskProvider; + _logger = logger; + } + + public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false) + { + if (episodeFile == null) + throw new ArgumentNullException("episodeFile"); + + var series = _seriesRepository.Get(episodeFile.SeriesId); + var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id); + string newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile); + var newFile = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); + + //Only rename if existing and new filenames don't match + if (DiskProvider.PathEquals(episodeFile.Path, newFile)) + { + _logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); + return null; + } + + if (!_diskProvider.FileExists(episodeFile.Path)) + { + _logger.Error("Episode file path does not exist, {0}", episodeFile.Path); + return null; + } + + _diskProvider.CreateDirectory(new FileInfo(newFile).DirectoryName); + + _logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile); + _diskProvider.MoveFile(episodeFile.Path, newFile); + + //Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important. + try + { + _diskProvider.InheritFolderPermissions(newFile); + } + catch (UnauthorizedAccessException ex) + { + _logger.Debug("Unable to apply folder permissions to: ", newFile); + _logger.TraceException(ex.Message, ex); + } + + episodeFile.Path = newFile; + _mediaFileService.Update(episodeFile); + + var parseResult = Parser.ParsePath(episodeFile.Path); + parseResult.Series = series; + parseResult.Quality = new QualityModel { Quality = episodeFile.Quality, Proper = episodeFile.Proper }; + parseResult.Episodes = episodes; + + + if (newDownload) + { + _eventAggregator.Publish(new EpisodeDownloadedEvent(parseResult)); + } + + return episodeFile; + } + + + } +} \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index e2dfdcb7f..26b4ef508 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -250,6 +250,7 @@ + diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index cd569600f..2304ea570 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -4,11 +4,7 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common; -using NzbDrone.Common.Eventing; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Organizer; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -22,24 +18,22 @@ namespace NzbDrone.Core.Providers private readonly IEpisodeService _episodeService; private readonly ICleanGhostFiles _ghostFileCleaner; private readonly IMediaFileService _mediaFileService; - private readonly IBuildFileNames _buildFileNames; private readonly RecycleBinProvider _recycleBinProvider; private readonly MediaInfoProvider _mediaInfoProvider; private readonly ISeriesRepository _seriesRepository; - private readonly IEventAggregator _eventAggregator; + private readonly IMoveEpisodeFiles _moveEpisodeFiles; - public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, ICleanGhostFiles ghostFileCleaner, IMediaFileService mediaFileService, IConfigService configService, IBuildFileNames buildFileNames, - RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository, IEventAggregator eventAggregator) + public DiskScanProvider(DiskProvider diskProvider, IEpisodeService episodeService, ICleanGhostFiles ghostFileCleaner, IMediaFileService mediaFileService, + RecycleBinProvider recycleBinProvider, MediaInfoProvider mediaInfoProvider, ISeriesRepository seriesRepository, IMoveEpisodeFiles moveEpisodeFiles) { _diskProvider = diskProvider; _episodeService = episodeService; _ghostFileCleaner = ghostFileCleaner; _mediaFileService = mediaFileService; - _buildFileNames = buildFileNames; _recycleBinProvider = recycleBinProvider; _mediaInfoProvider = mediaInfoProvider; _seriesRepository = seriesRepository; - _eventAggregator = eventAggregator; + _moveEpisodeFiles = moveEpisodeFiles; } public DiskScanProvider() @@ -180,63 +174,6 @@ namespace NzbDrone.Core.Providers return episodeFile; } - public virtual EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = false) - { - if (episodeFile == null) - throw new ArgumentNullException("episodeFile"); - - var series = _seriesRepository.Get(episodeFile.SeriesId); - var episodes = _episodeService.GetEpisodesByFileId(episodeFile.Id); - string newFileName = _buildFileNames.BuildFilename(episodes, series, episodeFile); - var newFile = _buildFileNames.BuildFilePath(series, episodes.First().SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); - - //Only rename if existing and new filenames don't match - if (DiskProvider.PathEquals(episodeFile.Path, newFile)) - { - Logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); - return null; - } - - if (!_diskProvider.FileExists(episodeFile.Path)) - { - Logger.Error("Episode file path does not exist, {0}", episodeFile.Path); - return null; - } - - _diskProvider.CreateDirectory(new FileInfo(newFile).DirectoryName); - - Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile); - _diskProvider.MoveFile(episodeFile.Path, newFile); - - //Wrapped in Try/Catch to prevent this from causing issues with remote NAS boxes, the move worked, which is more important. - try - { - _diskProvider.InheritFolderPermissions(newFile); - } - catch (UnauthorizedAccessException ex) - { - Logger.Debug("Unable to apply folder permissions to: ", newFile); - Logger.TraceException(ex.Message, ex); - } - - episodeFile.Path = newFile; - _mediaFileService.Update(episodeFile); - - var parseResult = Parser.ParsePath(episodeFile.Path); - parseResult.Series = series; - parseResult.Quality = new QualityModel { Quality = episodeFile.Quality, Proper = episodeFile.Proper }; - parseResult.Episodes = episodes; - - - if (newDownload) - { - _eventAggregator.Publish(new EpisodeDownloadedEvent(parseResult)); - } - - return episodeFile; - } - - public virtual void CleanUpDropFolder(string path) { @@ -254,7 +191,7 @@ namespace NzbDrone.Core.Providers { Logger.Trace("[{0}] was imported but not moved, moving it now", file); - MoveEpisodeFile(episodeFile, true); + _moveEpisodeFiles.MoveEpisodeFile(episodeFile, true); } } diff --git a/NzbDrone.Core/Providers/PostDownloadProvider.cs b/NzbDrone.Core/Providers/PostDownloadProvider.cs index 9adc0cddc..ae54e9989 100644 --- a/NzbDrone.Core/Providers/PostDownloadProvider.cs +++ b/NzbDrone.Core/Providers/PostDownloadProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; using NzbDrone.Core.Model; @@ -17,12 +18,14 @@ namespace NzbDrone.Core.Providers private readonly DiskProvider _diskProvider; private readonly DiskScanProvider _diskScanProvider; private readonly ISeriesRepository _seriesRepository; + private readonly IMoveEpisodeFiles _episodeFileMover; - public PostDownloadProvider(DiskProvider diskProvider, DiskScanProvider diskScanProvider, ISeriesRepository seriesRepository) + public PostDownloadProvider(DiskProvider diskProvider, DiskScanProvider diskScanProvider, ISeriesRepository seriesRepository, IMoveEpisodeFiles episodeFileMover) { _diskProvider = diskProvider; _diskScanProvider = diskScanProvider; _seriesRepository = seriesRepository; + _episodeFileMover = episodeFileMover; } public PostDownloadProvider() @@ -101,7 +104,7 @@ namespace NzbDrone.Core.Providers _diskScanProvider.CleanUpDropFolder(subfolderInfo.FullName); var importedFiles = _diskScanProvider.Scan(series, subfolderInfo.FullName); - importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file, true)); + importedFiles.ForEach(file => _episodeFileMover.MoveEpisodeFile(file, true)); //Delete the folder only if folder is small enough if (_diskProvider.GetDirectorySize(subfolderInfo.FullName) < Constants.IgnoreFileSize) @@ -166,7 +169,7 @@ namespace NzbDrone.Core.Providers var episodeFile = _diskScanProvider.ImportFile(series, videoFile); if (episodeFile != null) { - _diskScanProvider.MoveEpisodeFile(episodeFile, true); + _episodeFileMover.MoveEpisodeFile(episodeFile, true); } }