parent
d898f55660
commit
8876c9194d
@ -0,0 +1,16 @@
|
||||
|
||||
function formatPreferredWordScore(input) {
|
||||
const score = Number(input);
|
||||
|
||||
if (score > 0) {
|
||||
return `+${score}`;
|
||||
}
|
||||
|
||||
if (score < 0) {
|
||||
return score;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
export default formatPreferredWordScore;
|
@ -0,0 +1,199 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.EpisodeImport;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetSceneNameFixture : CoreTest
|
||||
{
|
||||
private LocalEpisode _localEpisode;
|
||||
private string _seasonName = "series.title.s02.dvdrip.x264-ingot";
|
||||
private string _episodeName = "series.title.s02e23.dvdrip.x264-ingot";
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(e => e.QualityProfile = new QualityProfile { Items = Qualities.QualityFixture.GetDefaultQualities() })
|
||||
.With(l => l.LanguageProfile = new LanguageProfile
|
||||
{
|
||||
Cutoff = Language.Spanish,
|
||||
Languages = Languages.LanguageFixture.GetDefaultLanguages()
|
||||
})
|
||||
.With(s => s.Path = @"C:\Test\TV\Series Title".AsOsAgnostic())
|
||||
.Build();
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.Build();
|
||||
|
||||
_localEpisode = new LocalEpisode
|
||||
{
|
||||
Series = series,
|
||||
Episodes = new List<Episode> {episode},
|
||||
Path = Path.Combine(series.Path, "Series Title - S02E23 - Episode Title.mkv"),
|
||||
Quality = new QualityModel(Quality.Bluray720p),
|
||||
ReleaseGroup = "DRONE"
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenExistingFileOnDisk()
|
||||
{
|
||||
Mocker.GetMock<IMediaFileService>()
|
||||
.Setup(s => s.GetFilesWithRelativePath(It.IsAny<int>(), It.IsAny<string>()))
|
||||
.Returns(new List<EpisodeFile>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_download_client_item_title_as_scene_name()
|
||||
{
|
||||
_localEpisode.DownloadClientEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _episodeName
|
||||
};
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.Be(_episodeName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_use_download_client_item_title_as_scene_name_if_full_season()
|
||||
{
|
||||
_localEpisode.DownloadClientEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _seasonName,
|
||||
FullSeason = true
|
||||
};
|
||||
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _seasonName, _episodeName)
|
||||
.AsOsAgnostic();
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_use_download_client_item_title_as_scene_name_if_there_are_other_video_files()
|
||||
{
|
||||
_localEpisode.OtherVideoFiles = true;
|
||||
_localEpisode.DownloadClientEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _seasonName,
|
||||
FullSeason = false
|
||||
};
|
||||
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _seasonName, _episodeName)
|
||||
.AsOsAgnostic();
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_file_name_as_scenename_only_if_it_looks_like_scenename()
|
||||
{
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _seasonName, _episodeName + ".mkv")
|
||||
.AsOsAgnostic();
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.Be(_episodeName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_use_file_name_as_scenename_if_it_doesnt_look_like_scenename()
|
||||
{
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _episodeName, "aaaaa.mkv")
|
||||
.AsOsAgnostic();
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_folder_name_as_scenename_only_if_it_looks_like_scenename()
|
||||
{
|
||||
_localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _episodeName
|
||||
};
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.Be(_episodeName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_use_folder_name_as_scenename_if_it_doesnt_look_like_scenename()
|
||||
{
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _episodeName, "aaaaa.mkv")
|
||||
.AsOsAgnostic();
|
||||
|
||||
_localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = "aaaaa"
|
||||
};
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_use_folder_name_as_scenename_if_it_is_for_a_full_season()
|
||||
{
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _episodeName, "aaaaa.mkv")
|
||||
.AsOsAgnostic();
|
||||
|
||||
_localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _seasonName,
|
||||
FullSeason = true
|
||||
};
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_use_folder_name_as_scenename_if_there_are_other_video_files()
|
||||
{
|
||||
_localEpisode.OtherVideoFiles = true;
|
||||
_localEpisode.Path = Path.Combine(@"C:\Test\Unsorted TV", _episodeName, "aaaaa.mkv")
|
||||
.AsOsAgnostic();
|
||||
|
||||
_localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _seasonName,
|
||||
FullSeason = false
|
||||
};
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.BeNull();
|
||||
}
|
||||
|
||||
[TestCase(".mkv")]
|
||||
[TestCase(".par2")]
|
||||
[TestCase(".nzb")]
|
||||
public void should_remove_extension_from_nzb_title_for_scene_name(string extension)
|
||||
{
|
||||
_localEpisode.DownloadClientEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
ReleaseTitle = _episodeName + extension
|
||||
};
|
||||
|
||||
SceneNameCalculator.GetSceneName(_localEpisode).Should()
|
||||
.Be(_episodeName);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Releases;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators
|
||||
{
|
||||
public class AggregatePreferredWordScore : IAggregateLocalEpisode
|
||||
{
|
||||
private readonly IPreferredWordService _preferredWordService;
|
||||
|
||||
public AggregatePreferredWordScore(IPreferredWordService preferredWordService)
|
||||
{
|
||||
_preferredWordService = preferredWordService;
|
||||
}
|
||||
|
||||
public LocalEpisode Aggregate(LocalEpisode localEpisode, DownloadClientItem downloadClientItem, bool otherFiles)
|
||||
{
|
||||
var series = localEpisode.Series;
|
||||
var scores = new List<int>();
|
||||
|
||||
if (localEpisode.FileEpisodeInfo != null)
|
||||
{
|
||||
scores.Add(_preferredWordService.Calculate(series, localEpisode.FileEpisodeInfo.ReleaseTitle, 0));
|
||||
}
|
||||
|
||||
if (localEpisode.SceneName != null)
|
||||
{
|
||||
scores.Add(_preferredWordService.Calculate(series, localEpisode.SceneName, 0));
|
||||
}
|
||||
|
||||
localEpisode.PreferredWordScore = scores.MaxOrDefault();
|
||||
|
||||
return localEpisode;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue