mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 20:12:41 +02:00
New: Store OriginalFilePath for New Downloads
This commit is contained in:
parent
e954b01921
commit
63197d38ce
@ -5,6 +5,7 @@
|
||||
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 @@ public void Setup()
|
||||
_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 @@ public void Setup()
|
||||
.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 @@ public void should_move_new_downloads()
|
||||
}
|
||||
|
||||
[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 @@ public void should_not_move_existing_files()
|
||||
[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 @@ public void should_use_nzb_title_as_scene_name()
|
||||
[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 @@ public void should_remove_extension_from_nzb_title_for_scene_name(string extensi
|
||||
[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 @@ public void should_not_use_nzb_title_as_scene_name_if_full_season()
|
||||
[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 @@ public void should_use_file_name_as_scenename_only_if_it_looks_like_scenename()
|
||||
[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 @@ public void should_import_larger_files_first()
|
||||
[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 @@ public void should_copy_when_cannot_move_files_downloads()
|
||||
[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())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public class MovieFile : ModelBase
|
||||
public string Path { get; set; }
|
||||
public long Size { get; set; }
|
||||
public DateTime DateAdded { get; set; }
|
||||
public string OriginalFilePath { get; set; }
|
||||
public string SceneName { get; set; }
|
||||
public string ReleaseGroup { get; set; }
|
||||
public IndexerFlags IndexerFlags { get; set; }
|
||||
|
@ -118,6 +118,7 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
||||
|
||||
if (newDownload)
|
||||
{
|
||||
movieFile.OriginalFilePath = GetOriginalFilePath(downloadClientItem, localMovie);
|
||||
movieFile.SceneName = GetSceneName(downloadClientItem, localMovie);
|
||||
|
||||
var moveResult = _movieFileUpgrader.UpgradeMovieFile(movieFile, localMovie, copyOnly); //TODO: Check if this works
|
||||
@ -176,6 +177,37 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
||||
return importResults;
|
||||
}
|
||||
|
||||
private string GetOriginalFilePath(DownloadClientItem downloadClientItem, LocalMovie localMovie)
|
||||
{
|
||||
if (downloadClientItem != null)
|
||||
{
|
||||
return downloadClientItem.OutputPath.Directory.ToString().GetRelativePath(localMovie.Path);
|
||||
}
|
||||
|
||||
var path = localMovie.Path;
|
||||
var folderMovieInfo = localMovie.FolderMovieInfo;
|
||||
|
||||
if (folderMovieInfo != null)
|
||||
{
|
||||
var folderPath = path.GetAncestorPath(folderMovieInfo.SimpleReleaseTitle);
|
||||
|
||||
if (folderPath != null)
|
||||
{
|
||||
return folderPath.GetParentPath().GetRelativePath(path);
|
||||
}
|
||||
}
|
||||
|
||||
var parentPath = path.GetParentPath();
|
||||
var grandparentPath = parentPath.GetParentPath();
|
||||
|
||||
if (grandparentPath != null)
|
||||
{
|
||||
return grandparentPath.GetRelativePath(path);
|
||||
}
|
||||
|
||||
return Path.Combine(Path.GetFileName(parentPath), Path.GetFileName(path));
|
||||
}
|
||||
|
||||
private string GetSceneName(DownloadClientItem downloadClientItem, LocalMovie localMovie)
|
||||
{
|
||||
if (downloadClientItem != null)
|
||||
|
@ -23,6 +23,7 @@ public class MovieFileResource : RestResource
|
||||
public QualityModel Quality { get; set; }
|
||||
public List<CustomFormatResource> CustomFormats { get; set; }
|
||||
public MediaInfoResource MediaInfo { get; set; }
|
||||
public string OriginalFilePath { get; set; }
|
||||
public bool QualityCutoffNotMet { get; set; }
|
||||
public List<Language> Languages { get; set; }
|
||||
}
|
||||
@ -51,8 +52,7 @@ private static MovieFileResource ToResource(this MovieFile model)
|
||||
Quality = model.Quality,
|
||||
Languages = model.Languages,
|
||||
MediaInfo = model.MediaInfo.ToResource(model.SceneName),
|
||||
|
||||
//QualityCutoffNotMet
|
||||
OriginalFilePath = model.OriginalFilePath
|
||||
};
|
||||
}
|
||||
|
||||
@ -76,7 +76,8 @@ public static MovieFileResource ToResource(this MovieFile model, NzbDrone.Core.M
|
||||
IndexerFlags = model.IndexerFlags,
|
||||
Quality = model.Quality,
|
||||
Languages = model.Languages,
|
||||
MediaInfo = model.MediaInfo.ToResource(model.SceneName)
|
||||
MediaInfo = model.MediaInfo.ToResource(model.SceneName),
|
||||
OriginalFilePath = model.OriginalFilePath
|
||||
};
|
||||
}
|
||||
|
||||
@ -101,7 +102,8 @@ public static MovieFileResource ToResource(this MovieFile model, NzbDrone.Core.M
|
||||
Quality = model.Quality,
|
||||
Languages = model.Languages,
|
||||
MediaInfo = model.MediaInfo.ToResource(model.SceneName),
|
||||
QualityCutoffNotMet = upgradableSpecification.QualityCutoffNotMet(movie.Profile, model.Quality)
|
||||
QualityCutoffNotMet = upgradableSpecification.QualityCutoffNotMet(movie.Profile, model.Quality),
|
||||
OriginalFilePath = model.OriginalFilePath
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user