parent
cd2761d07d
commit
6e88f55a54
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class DropFolderImportServiceFixture : CoreTest<DropFolderImportService>
|
||||
{
|
||||
private EpisodeFile _fakeEpisodeFile;
|
||||
|
||||
|
||||
private string[] _subFolders = new[] { "c:\\root\\foldername" };
|
||||
private string[] _videoFiles = new[] { "c:\\root\\foldername\\video.ext" };
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_fakeEpisodeFile = Builder<EpisodeFile>.CreateNew().Build();
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(_videoFiles);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.GetDirectories(It.IsAny<string>()))
|
||||
.Returns(_subFolders);
|
||||
}
|
||||
|
||||
private void WithOldWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.Now.AddDays(-5));
|
||||
}
|
||||
|
||||
private void WithRecentFolderWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetLastFolderWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_file()
|
||||
{
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
|
||||
VerifyImport();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_folder_is_too_fresh()
|
||||
{
|
||||
WithRecentFolderWrite();
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
|
||||
VerifyNoImport();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_folder_name()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
|
||||
Mocker.GetMock<ISeriesService>().Verify(c => c.FindByTitle("foldername"), Times.Once());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_file_name()
|
||||
{
|
||||
/*WithOldWrite();
|
||||
WithValidSeries();
|
||||
WithImportableFiles();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
||||
Subject.ProcessDownload(droppedFolder);
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Verify(c => c.Scan(_fakeSeries, It.IsAny<string>()));*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void all_imported_files_should_be_moved()
|
||||
{
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns(_fakeEpisodeFile);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(_fakeEpisodeFile, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_attempt_move_if_nothing_is_imported()
|
||||
{
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns<EpisodeFile>(null);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<bool>()), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_folder_is_in_use_by_another_process()
|
||||
{
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
|
||||
.Returns(true);
|
||||
|
||||
Subject.ProcessDropFolder("c:\\drop\\");
|
||||
VerifyNoImport();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void VerifyNoImport()
|
||||
{
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()),
|
||||
Times.Never());
|
||||
}
|
||||
|
||||
|
||||
private void VerifyImport()
|
||||
{
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()),
|
||||
Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,469 +0,0 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using Marr.Data;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessDownloadFixture : CoreTest
|
||||
{
|
||||
Series fakeSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.RootFolder = new LazyLoaded<RootFolder>(new RootFolder { Path = @"C:\Test\TV" }))
|
||||
.With(s => s.FolderName = "30 Rock")
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void WithOldWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetLastDirectoryWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.Now.AddDays(-5));
|
||||
}
|
||||
|
||||
private void WithRecentWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetLastDirectoryWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
}
|
||||
|
||||
private void WithValidSeries()
|
||||
{
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle(It.IsAny<string>()))
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.FolderExists(fakeSeries.Path))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void WithImportableFiles()
|
||||
{
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Setup(c => c.Scan(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns(Builder<EpisodeFile>.CreateListOfSize(1).Build().ToList());
|
||||
}
|
||||
|
||||
private void WithLotsOfFreeDiskSpace()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
|
||||
}
|
||||
|
||||
private void WithImportedFiles(string droppedFolder)
|
||||
{
|
||||
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(f => f.SeriesId = fakeSeries.Id)
|
||||
.Build().ToList();
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder)).Returns(fakeEpisodeFiles);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_folder_is_tagged_and_too_fresh()
|
||||
{
|
||||
WithStrictMocker();
|
||||
WithRecentWrite();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
||||
droppedFolder.Create();
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_continue_processing_if_folder_is_tagged_and_not_fresh()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(TempFolder + "\\_test\\");
|
||||
droppedFolder.Create();
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null).Verifiable();
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_title_without_status()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\_unpack_The Office - S01E01 - Episode Title");
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns<Series>(null).Verifiable();
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_folder_name()
|
||||
{
|
||||
WithOldWrite();
|
||||
WithValidSeries();
|
||||
WithImportableFiles();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Verify(c=>c.Scan(fakeSeries, It.IsAny<string>()));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_for_series_using_file_name()
|
||||
{
|
||||
WithOldWrite();
|
||||
WithValidSeries();
|
||||
WithImportableFiles();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Verify(c => c.Scan(fakeSeries, It.IsAny<string>()));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Disabled tagging")]
|
||||
public void when_series_isnt_found_folder_should_be_tagged_as_unknown_series()
|
||||
{
|
||||
|
||||
WithStrictMocker();
|
||||
WithOldWrite();
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
||||
|
||||
var taggedFolder = @"C:\Test\Unsorted TV\_UnknownSeries_The Office - S01E01 - Episode Title";
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns<Series>(null);
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Disabled tagging")]
|
||||
public void when_no_files_are_imported_folder_should_be_tagged_with_parse_error()
|
||||
{
|
||||
|
||||
WithStrictMocker();
|
||||
WithOldWrite();
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - S01E01 - Episode Title");
|
||||
|
||||
var taggedFolder = @"C:\Test\Unsorted TV\_ParseError_The Office - S01E01 - Episode Title";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.Title = "The Office")
|
||||
.Build();
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(new List<EpisodeFile>());
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Ignore("Disabled tagging")]
|
||||
public void when_no_file_are_imported_and_folder_size_isnt_small_enought_folder_should_be_tagged_unknown()
|
||||
{
|
||||
|
||||
WithStrictMocker();
|
||||
WithOldWrite();
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
||||
|
||||
var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown);
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.Title = "The Office")
|
||||
.Build();
|
||||
|
||||
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(f => f.SeriesId = fakeSeries.Id)
|
||||
.Build().ToList();
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.MoveDirectory(droppedFolder.FullName, taggedFolder));
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize + 10.Megabytes());
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[TestCase(@"\_UnknownSeries_The Office - S01E01 - Episode Title")]
|
||||
[TestCase(@"\_UnknownSeries_The Office - S01E01 - Episode Title\")]
|
||||
[TestCase("\\Test\\_UnknownSeries_The Office - S01E01 - Episode Title\\")]
|
||||
[TestCase("\\Test\\_UnknownSeries_The Office - S01E01 - Episode Title")]
|
||||
public void folder_shouldnt_be_tagged_with_same_tag_again(string path)
|
||||
{
|
||||
|
||||
|
||||
var droppedFolder = new DirectoryInfo(TempFolder + path);
|
||||
droppedFolder.Create();
|
||||
WithOldWrite();
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null);
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void folder_should_not_be_tagged_if_existing_tag_is_diffrent()
|
||||
{
|
||||
|
||||
WithOldWrite();
|
||||
var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title");
|
||||
droppedFolder.Create();
|
||||
droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1);
|
||||
|
||||
var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title";
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.MoveDirectory(droppedFolder.FullName, taggedFolder), Times.Never());
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void when_files_are_imported_and_folder_is_small_enough_dir_should_be_deleted()
|
||||
{
|
||||
|
||||
WithStrictMocker();
|
||||
WithLotsOfFreeDiskSpace();
|
||||
|
||||
var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01");
|
||||
|
||||
WithImportedFiles(droppedFolder.FullName);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.CleanUpDropFolder(droppedFolder.FullName));
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true));
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true);
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.IsFolderLocked(droppedFolder.FullName)).Returns(false);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void all_imported_files_should_be_moved()
|
||||
{
|
||||
var droppedFolder = new DirectoryInfo(TempFolder);
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.Build();
|
||||
|
||||
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
|
||||
.Build().ToList();
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<string>())).Returns(fakeSeries);
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true);
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(droppedFolder);
|
||||
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true),
|
||||
Times.Exactly(fakeEpisodeFiles.Count));
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_logError_and_return_if_size_exceeds_free_space()
|
||||
{
|
||||
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.Title = "30 Rock")
|
||||
.With(s => s.RootFolder = new LazyLoaded<RootFolder>(new RootFolder { Path = @"C:\Test\TV" }))
|
||||
.With(s => s.FolderName = "30 Rock")
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle("rock"))
|
||||
.Returns(series);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetDirectorySize(downloadName.FullName))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FolderExists(series.Path))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(series.Path))
|
||||
.Returns(9);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(series, downloadName.FullName), Times.Never());
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_process_if_free_disk_space_exceeds_size()
|
||||
{
|
||||
WithLotsOfFreeDiskSpace();
|
||||
WithValidSeries();
|
||||
|
||||
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
||||
|
||||
WithImportedFiles(downloadName.FullName);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle("rock"))
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetDirectorySize(downloadName.FullName))
|
||||
.Returns(8);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(fakeSeries, downloadName.FullName), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_process_if_free_disk_space_equals_size()
|
||||
{
|
||||
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
||||
|
||||
WithImportedFiles(downloadName.FullName);
|
||||
WithValidSeries();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetDirectorySize(downloadName.FullName))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
|
||||
.Returns(10);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(fakeSeries, downloadName.FullName), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_create_series_directory_if_series_path_does_not_exist()
|
||||
{
|
||||
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
||||
|
||||
WithValidSeries();
|
||||
WithLotsOfFreeDiskSpace();
|
||||
WithImportedFiles(downloadName.FullName);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FolderExists(fakeSeries.Path))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle("office")).Returns(fakeSeries);
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.CleanUpDropFolder(downloadName.FullName));
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(downloadName.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(downloadName.FullName, true));
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.IsFolderLocked(downloadName.FullName)).Returns(false);
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.CreateDirectory(fakeSeries.Path), Times.Once());
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_folder_is_in_use_by_another_process()
|
||||
{
|
||||
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
|
||||
|
||||
WithValidSeries();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.IsFolderLocked(downloadName.FullName))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectorySize(It.IsAny<String>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using Marr.Data;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessDropDirectoryFixture : CoreTest
|
||||
{
|
||||
Series fakeSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.RootFolder = new LazyLoaded<RootFolder>(new RootFolder { Path = @"C:\Test\TV" }))
|
||||
.With(s => s.FolderName = "30 Rock")
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void WithLotsOfFreeDiskSpace()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessDropFolder_should_only_process_folders_that_arent_known_series_folders()
|
||||
{
|
||||
WithLotsOfFreeDiskSpace();
|
||||
|
||||
var subFolders = new[]
|
||||
{
|
||||
@"c:\drop\episode1",
|
||||
@"c:\drop\episode2",
|
||||
@"c:\drop\episode3",
|
||||
@"c:\drop\episode4"
|
||||
};
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Setup(c => c.GetVideoFiles(It.IsAny<String>(), false))
|
||||
.Returns(new List<String>());
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetDirectories(It.IsAny<String>()))
|
||||
.Returns(subFolders);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.SeriesPathExists(subFolders[1]))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle(It.IsAny<String>()))
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Setup(c => c.Scan(It.IsAny<Series>(), It.IsAny<String>()))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetDirectorySize(It.IsAny<String>()))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.FolderExists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDropFolder(@"C:\drop\");
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[0]), Times.Once());
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[1]), Times.Never());
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[2]), Times.Once());
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(It.IsAny<Series>(), subFolders[3]), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessDropFolder_should_process_individual_video_files_in_drop_folder()
|
||||
{
|
||||
WithLotsOfFreeDiskSpace();
|
||||
|
||||
var files = new List<String>
|
||||
{
|
||||
@"c:\drop\30 Rock - episode1.avi",
|
||||
@"c:\drop\30 Rock - episode2.mkv",
|
||||
@"c:\drop\30 Rock - episode3.mp4",
|
||||
@"c:\drop\30 Rock - episode4.wmv"
|
||||
};
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Setup(c => c.GetVideoFiles(It.IsAny<String>(), false))
|
||||
.Returns(files);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle(It.IsAny<String>()))
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Setup(c => c.Scan(It.IsAny<Series>(), It.IsAny<String>()))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetDirectorySize(It.IsAny<String>()))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.FolderExists(It.IsAny<String>()))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessDropFolder(@"C:\drop\");
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<String>()), Times.Exactly(4));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
using Marr.Data;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessVideoFileFixture : CoreTest
|
||||
{
|
||||
Series fakeSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(s => s.RootFolder = new LazyLoaded<RootFolder>(new RootFolder { Path = @"C:\Test\TV" }))
|
||||
.With(s => s.FolderName = "30 Rock")
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void WithOldWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetLastFileWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.Now.AddDays(-5));
|
||||
}
|
||||
|
||||
private void WithRecentWrite()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(c => c.GetLastFileWrite(It.IsAny<String>()))
|
||||
.Returns(DateTime.UtcNow);
|
||||
}
|
||||
|
||||
private void WithValidSeries()
|
||||
{
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle(It.IsAny<string>()))
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FolderExists(fakeSeries.Path))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
private void WithImportableFiles()
|
||||
{
|
||||
Mocker.GetMock<DiskScanProvider>()
|
||||
.Setup(c => c.Scan(It.IsAny<Series>(), It.IsAny<string>()))
|
||||
.Returns(Builder<EpisodeFile>.CreateListOfSize(1).Build().ToList());
|
||||
}
|
||||
|
||||
private void WithLotsOfFreeDiskSpace()
|
||||
{
|
||||
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
|
||||
}
|
||||
|
||||
private void WithImportedFile(string file)
|
||||
{
|
||||
var fakeEpisodeFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(f => f.SeriesId = fakeSeries.Id)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Setup(s => s.ImportFile(fakeSeries, file)).Returns(fakeEpisodeFile);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_and_too_fresh()
|
||||
{
|
||||
WithStrictMocker();
|
||||
WithRecentWrite();
|
||||
|
||||
var file = Path.Combine(TempFolder, "test.avi");
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(file);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_continue_processing_if_not_fresh()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
var file = Path.Combine(TempFolder, "test.avi");
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null).Verifiable();
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(file);
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Verify(s => s.GetByTitle(It.IsAny<String>()), Times.Once());
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_if_series_is_not_found()
|
||||
{
|
||||
WithOldWrite();
|
||||
|
||||
var file = Path.Combine(TempFolder, "test.avi");
|
||||
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Setup(s => s.GetByTitle(It.IsAny<String>())).Returns<Series>(null);
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(file);
|
||||
|
||||
|
||||
Mocker.GetMock<DiskProvider>().Verify(s => s.GetSize(It.IsAny<String>()), Times.Never());
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_move_file_if_imported()
|
||||
{
|
||||
WithLotsOfFreeDiskSpace();
|
||||
WithOldWrite();
|
||||
|
||||
var file = Path.Combine(TempFolder, "test.avi");
|
||||
|
||||
WithValidSeries();
|
||||
WithImportedFile(file);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(file);
|
||||
|
||||
|
||||
Mocker.GetMock<IMoveEpisodeFiles>().Verify(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true), Times.Once());
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_logError_and_return_if_size_exceeds_free_space()
|
||||
{
|
||||
var downloadName = @"C:\Test\Drop\30.Rock.S01E01.Pilot.mkv";
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.Title = "30 Rock")
|
||||
.With(s => s.RootFolder = new LazyLoaded<RootFolder>(new RootFolder { Path = @"C:\Test\TV" }))
|
||||
.With(s => s.FolderName = "30 Rock")
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle("rock"))
|
||||
.Returns(series);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetSize(downloadName))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(series.Path))
|
||||
.Returns(9);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FolderExists(series.Path))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(series, downloadName), Times.Never());
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_process_if_free_disk_space_exceeds_size()
|
||||
{
|
||||
WithLotsOfFreeDiskSpace();
|
||||
WithValidSeries();
|
||||
|
||||
var downloadName = @"C:\Test\Drop\30.Rock.S01E01.Pilot.mkv";
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(c => c.GetByTitle("rock"))
|
||||
.Returns(fakeSeries);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetSize(downloadName))
|
||||
.Returns(8);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(fakeSeries, downloadName), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_process_if_free_disk_space_equals_size()
|
||||
{
|
||||
var downloadName = @"C:\Test\Drop\30.Rock.S01E01.Pilot.mkv";
|
||||
|
||||
WithValidSeries();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetDirectorySize(downloadName))
|
||||
.Returns(10);
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
|
||||
.Returns(10);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(fakeSeries, downloadName), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_if_series_Path_doesnt_exist()
|
||||
{
|
||||
var downloadName = @"C:\Test\Drop\30.Rock.S01E01.Pilot.mkv";
|
||||
|
||||
WithValidSeries();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FolderExists(fakeSeries.Path))
|
||||
.Returns(false);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(downloadName);
|
||||
|
||||
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_if_file_is_in_use_by_another_process()
|
||||
{
|
||||
var downloadName = @"C:\Test\Drop\30.Rock.S01E01.Pilot.mkv";
|
||||
|
||||
WithValidSeries();
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.IsFileLocked(It.Is<FileInfo>(f => f.FullName == downloadName)))
|
||||
.Returns(true);
|
||||
|
||||
|
||||
Mocker.Resolve<PostDownloadProvider>().ProcessVideoFile(downloadName);
|
||||
|
||||
|
||||
|
||||
Mocker.GetMock<DiskScanProvider>().Verify(c => c.ImportFile(fakeSeries, downloadName), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Update;
|
||||
|
||||
namespace NzbDrone.Core.Test.UpdateTests
|
||||
{
|
||||
public class UpdatePackageProviderFixture : CoreTest<UpdatePackageProvider>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public interface IDecisionEngineSpecification : IRejectWithReason
|
||||
{
|
||||
bool IsSatisfiedBy(IndexerParseResult subject);
|
||||
bool IsSatisfiedBy(RemoteEpisode subject);
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
using NzbDrone.Core.IndexerSearch;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
|
||||
{
|
||||
public interface IDecisionEngineSearchSpecification : IRejectWithReason
|
||||
{
|
||||
bool IsSatisfiedBy(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase);
|
||||
bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinitionBase);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace NzbDrone.Core.Download.Clients
|
||||
namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
||||
{
|
||||
public class ConnectionInfoModel
|
||||
{
|
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Tv;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Parser.Model
|
||||
{
|
||||
public class LocalEpisode
|
||||
{
|
||||
//public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; }
|
||||
public List<Episode> Episodes { get; set; }
|
||||
|
||||
public QualityModel Quality { get; set; }
|
||||
public int SeasonNumber { get { return Episodes.Select(c => c.SeasonNumber).Distinct().Single(); } }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Parser.Model
|
||||
{
|
||||
public class ParsedEpisodeInfo
|
||||
{
|
||||
public string SeriesTitle { get; set; }
|
||||
public string OriginalString { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public List<int> EpisodeNumbers { get; set; }
|
||||
public DateTime? AirDate { get; set; }
|
||||
public Language Language { get; set; }
|
||||
|
||||
public bool FullSeason { get; set; }
|
||||
public bool SceneSource { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string episodeString = "[Unknown Episode]";
|
||||
|
||||
if (AirDate != null && EpisodeNumbers == null)
|
||||
{
|
||||
episodeString = string.Format("{0}", AirDate.Value.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
else if (FullSeason)
|
||||
{
|
||||
episodeString = string.Format("Season {0:00}", SeasonNumber);
|
||||
}
|
||||
else if (EpisodeNumbers != null && EpisodeNumbers.Any())
|
||||
{
|
||||
episodeString = string.Format("S{0:00}E{1}", SeasonNumber, String.Join("-", EpisodeNumbers.Select(c => c.ToString("00"))));
|
||||
}
|
||||
|
||||
return string.Format("{0} - {1} {2}", SeriesTitle, episodeString, Quality);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Parser.Model
|
||||
{
|
||||
public class RemoteEpisode
|
||||
{
|
||||
public ReportInfo Report { get; set; }
|
||||
|
||||
public bool FullSeason { get; set; }
|
||||
|
||||
public Series Series { get; set; }
|
||||
|
||||
public List<Episode> Episodes { get; set; }
|
||||
|
||||
public QualityModel Quality { get; set; }
|
||||
|
||||
public Language Language { get; set; }
|
||||
|
||||
public int SeasonNumber
|
||||
{
|
||||
get { return Episodes.Select(e => e.SeasonNumber).Distinct().SingleOrDefault(); }
|
||||
}
|
||||
|
||||
|
||||
public DateTime? AirDate
|
||||
{
|
||||
get
|
||||
{
|
||||
return Episodes.Single().AirDate;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<int> EpisodeNumbers
|
||||
{
|
||||
get
|
||||
{
|
||||
return Episodes.Select(c => c.EpisodeNumber).Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetDownloadTitle()
|
||||
{
|
||||
var seriesTitle = FileNameBuilder.CleanFilename(Series.Title);
|
||||
|
||||
//Handle Full Naming
|
||||
if (FullSeason)
|
||||
{
|
||||
var seasonResult = String.Format("{0} - Season {1} [{2}]", seriesTitle, SeasonNumber, Quality);
|
||||
|
||||
if (Quality.Proper)
|
||||
seasonResult += " [Proper]";
|
||||
|
||||
return seasonResult;
|
||||
}
|
||||
|
||||
if (Series.SeriesType == SeriesTypes.Daily)
|
||||
{
|
||||
var dailyResult = String.Format("{0} - {1:yyyy-MM-dd} - {2} [{3}]", seriesTitle,
|
||||
AirDate, Episodes.First().Title, Quality);
|
||||
|
||||
if (Quality.Proper)
|
||||
dailyResult += " [Proper]";
|
||||
|
||||
return dailyResult;
|
||||
}
|
||||
|
||||
//Show Name - 1x01-1x02 - Episode Name
|
||||
//Show Name - 1x01 - Episode Name
|
||||
var episodeString = new List<string>();
|
||||
var episodeNames = new List<string>();
|
||||
|
||||
foreach (var episode in Episodes)
|
||||
{
|
||||
episodeString.Add(String.Format("{0}x{1:00}", episode.SeasonNumber, episode.EpisodeNumber));
|
||||
episodeNames.Add(Core.Parser.Parser.CleanupEpisodeTitle(episode.Title));
|
||||
}
|
||||
|
||||
var epNumberString = String.Join("-", episodeString);
|
||||
string episodeName;
|
||||
|
||||
|
||||
if (episodeNames.Distinct().Count() == 1)
|
||||
episodeName = episodeNames.First();
|
||||
|
||||
else
|
||||
episodeName = String.Join(" + ", episodeNames.Distinct());
|
||||
|
||||
var result = String.Format("{0} - {1} - {2} [{3}]", seriesTitle, epNumberString, episodeName, Quality);
|
||||
|
||||
if (Quality.Proper)
|
||||
{
|
||||
result += " [Proper]";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue