|
|
|
@ -5,6 +5,7 @@ using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
|
using NzbDrone.Core.History;
|
|
|
|
@ -37,6 +38,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
_rejectedDecisions = new List<ImportDecision>();
|
|
|
|
|
_approvedDecisions = new List<ImportDecision>();
|
|
|
|
|
|
|
|
|
|
var outputPath = @"C:\Test\Unsorted\TV\30.Rock.S01E01".AsOsAgnostic();
|
|
|
|
|
|
|
|
|
|
var movie = Builder<Movie>.CreateNew()
|
|
|
|
|
.With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() })
|
|
|
|
|
.With(s => s.Path = @"C:\Test\TV\30 Rock".AsOsAgnostic())
|
|
|
|
@ -63,7 +66,14 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
.Setup(x => x.FindByDownloadId(It.IsAny<string>()))
|
|
|
|
|
.Returns(new List<History.History>());
|
|
|
|
|
|
|
|
|
|
_downloadClientItem = Builder<DownloadClientItem>.CreateNew().Build();
|
|
|
|
|
_downloadClientItem = Builder<DownloadClientItem>.CreateNew()
|
|
|
|
|
.With(d => d.OutputPath = new OsPath(outputPath))
|
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenNewDownload()
|
|
|
|
|
{
|
|
|
|
|
_approvedDecisions.ForEach(a => a.LocalMovie.Path = Path.Combine(_downloadClientItem.OutputPath.ToString(), Path.GetFileName(a.LocalMovie.Path)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -116,7 +126,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_publish_EpisodeImportedEvent_for_new_downloads()
|
|
|
|
|
public void should_publish_MovieImportedEvent_for_new_downloads()
|
|
|
|
|
{
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
|
|
|
|
|
|
|
|
@ -137,6 +147,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_nzb_title_as_scene_name()
|
|
|
|
|
{
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
_downloadClientItem.Title = "malcolm.in.the.middle.2015.dvdrip.xvid-ingot";
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
@ -149,6 +160,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[TestCase(".nzb")]
|
|
|
|
|
public void should_remove_extension_from_nzb_title_for_scene_name(string extension)
|
|
|
|
|
{
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
var title = "malcolm.in.the.middle.2015.dvdrip.xvid-ingot";
|
|
|
|
|
|
|
|
|
|
_downloadClientItem.Title = title + extension;
|
|
|
|
@ -162,7 +174,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Ignore("Series")]
|
|
|
|
|
public void should_not_use_nzb_title_as_scene_name_if_full_season()
|
|
|
|
|
{
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = "c:\\tv\\season1\\malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv".AsOsAgnostic();
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = Path.Combine(_downloadClientItem.OutputPath.ToString(), "malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv");
|
|
|
|
|
_downloadClientItem.Title = "malcolm.in.the.middle.s02.dvdrip.xvid-ingot";
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
@ -174,7 +187,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Ignore("Series")]
|
|
|
|
|
public void should_use_file_name_as_scenename_only_if_it_looks_like_scenename()
|
|
|
|
|
{
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = "c:\\tv\\malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv".AsOsAgnostic();
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = Path.Combine(_downloadClientItem.OutputPath.ToString(), "malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv");
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
|
|
|
|
|
|
|
|
@ -184,7 +198,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_file_name_as_scenename_if_it_doesnt_looks_like_scenename()
|
|
|
|
|
{
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = "c:\\tv\\aaaaa.mkv".AsOsAgnostic();
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = Path.Combine(_downloadClientItem.OutputPath.ToString(), "aaaaa.mkv");
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true);
|
|
|
|
|
|
|
|
|
@ -220,7 +235,11 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_copy_when_cannot_move_files_downloads()
|
|
|
|
|
{
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, new DownloadClientItem { Title = "30.Rock.S01E01", CanMoveFiles = false });
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
_downloadClientItem.Title = "30.Rock.S01E01";
|
|
|
|
|
_downloadClientItem.CanMoveFiles = false;
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IUpgradeMediaFiles>()
|
|
|
|
|
.Verify(v => v.UpgradeMovieFile(It.IsAny<MovieFile>(), _approvedDecisions.First().LocalMovie, true), Times.Once());
|
|
|
|
@ -229,10 +248,71 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_override_importmode()
|
|
|
|
|
{
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, new DownloadClientItem { Title = "30.Rock.S01E01", CanMoveFiles = false }, ImportMode.Move);
|
|
|
|
|
GivenNewDownload();
|
|
|
|
|
_downloadClientItem.Title = "30.Rock.S01E01";
|
|
|
|
|
_downloadClientItem.CanMoveFiles = false;
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem, ImportMode.Move);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IUpgradeMediaFiles>()
|
|
|
|
|
.Verify(v => v.UpgradeMovieFile(It.IsAny<MovieFile>(), _approvedDecisions.First().LocalMovie, false), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_file_name_only_for_download_client_item_without_a_job_folder()
|
|
|
|
|
{
|
|
|
|
|
var fileName = "Series.Title.S01E01.720p.HDTV.x264-Sonarr.mkv";
|
|
|
|
|
var path = Path.Combine(@"C:\Test\Unsorted\TV\".AsOsAgnostic(), fileName);
|
|
|
|
|
|
|
|
|
|
_downloadClientItem.OutputPath = new OsPath(path);
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = path;
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<MovieFile>(c => c.OriginalFilePath == fileName)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_folder_and_file_name_only_for_download_client_item_with_a_job_folder()
|
|
|
|
|
{
|
|
|
|
|
var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr";
|
|
|
|
|
var outputPath = Path.Combine(@"C:\Test\Unsorted\TV\".AsOsAgnostic(), name);
|
|
|
|
|
|
|
|
|
|
_downloadClientItem.OutputPath = new OsPath(outputPath);
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = Path.Combine(outputPath, name + ".mkv");
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<MovieFile>(c => c.OriginalFilePath == $"{name}\\{name}.mkv".AsOsAgnostic())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_include_intermediate_folders_for_download_client_item_with_a_job_folder()
|
|
|
|
|
{
|
|
|
|
|
var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr";
|
|
|
|
|
var outputPath = Path.Combine(@"C:\Test\Unsorted\TV\".AsOsAgnostic(), name);
|
|
|
|
|
|
|
|
|
|
_downloadClientItem.OutputPath = new OsPath(outputPath);
|
|
|
|
|
_approvedDecisions.First().LocalMovie.Path = Path.Combine(outputPath, "subfolder", name + ".mkv");
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, _downloadClientItem);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<MovieFile>(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_folder_info_release_title_to_find_relative_path()
|
|
|
|
|
{
|
|
|
|
|
var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr";
|
|
|
|
|
var outputPath = Path.Combine(@"C:\Test\Unsorted\TV\".AsOsAgnostic(), name);
|
|
|
|
|
var localEpisode = _approvedDecisions.First().LocalMovie;
|
|
|
|
|
|
|
|
|
|
localEpisode.FolderMovieInfo = new ParsedMovieInfo { SimpleReleaseTitle = name };
|
|
|
|
|
localEpisode.Path = Path.Combine(outputPath, "subfolder", name + ".mkv");
|
|
|
|
|
|
|
|
|
|
Subject.Import(new List<ImportDecision> { _approvedDecisions.First() }, true, null);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>().Verify(v => v.Add(It.Is<MovieFile>(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|