From 2fc76a9ac5815886fa8bbd7d56ea5c974a701b09 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 30 Dec 2022 16:42:11 -0800 Subject: [PATCH] New: Use XEM season number for some releases when mapping episodes Closes #5195 --- .../ParsingServiceTests/MapFixture.cs | 40 +++++++++++++++++++ src/NzbDrone.Core/Parser/ParsingService.cs | 7 ++++ 2 files changed, 47 insertions(+) diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs index d8c6fbb8d..e0277d3e4 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/MapFixture.cs @@ -220,5 +220,45 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests Mocker.GetMock() .Verify(v => v.FindByTitle(It.IsAny()), Times.Never()); } + + [Test] + public void should_use_scene_season_number_from_xem_mapping_if_alias_matches_a_specific_season_number() + { + _parsedEpisodeInfo.SeasonNumber = 1; + + var sceneMapping = new SceneMapping + { + Type = "XemService", + SceneSeasonNumber = 2 + }; + + Mocker.GetMock() + .Setup(s => s.FindSceneMapping(_parsedEpisodeInfo.SeriesTitle, _parsedEpisodeInfo.ReleaseTitle, _parsedEpisodeInfo.SeasonNumber)) + .Returns(sceneMapping); + + var result = Subject.Map(_parsedEpisodeInfo, _series); + + result.MappedSeasonNumber.Should().Be(sceneMapping.SceneSeasonNumber); + } + + [Test] + public void should_not_use_scene_season_number_from_xem_mapping_if_alias_matches_a_specific_season_number_but_did_not_parse_season_1() + { + _parsedEpisodeInfo.SeasonNumber = 2; + + var sceneMapping = new SceneMapping + { + Type = "XemService", + SceneSeasonNumber = 2 + }; + + Mocker.GetMock() + .Setup(s => s.FindSceneMapping(_parsedEpisodeInfo.SeriesTitle, _parsedEpisodeInfo.ReleaseTitle, _parsedEpisodeInfo.SeasonNumber)) + .Returns(sceneMapping); + + var result = Subject.Map(_parsedEpisodeInfo, _series); + + result.MappedSeasonNumber.Should().Be(sceneMapping.SceneSeasonNumber); + } } } diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index afa8ef115..118fda239 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -163,6 +163,13 @@ namespace NzbDrone.Core.Parser { sceneSource = false; } + else if (sceneMapping.Type == "XemService" && + sceneMapping.SceneSeasonNumber.HasValue && + parsedEpisodeInfo.SeasonNumber == 1 && + sceneMapping.SceneSeasonNumber != parsedEpisodeInfo.SeasonNumber) + { + remoteEpisode.MappedSeasonNumber = sceneMapping.SceneSeasonNumber.Value; + } } if (series == null)