New: Update anime episodes by season/episode number instead of absolute episode number

Closes #6547
This commit is contained in:
Mark McDowall 2024-02-25 16:32:32 -08:00 committed by Mark McDowall
parent 6dc0a88004
commit 4c170d0452
2 changed files with 13 additions and 116 deletions

View File

@ -40,7 +40,6 @@ namespace NzbDrone.Core.Test.TvTests
private Series GetSeries()
{
var series = _gameOfThrones.Item1.JsonClone();
series.Seasons = new List<Season>();
return series;
}
@ -49,7 +48,6 @@ namespace NzbDrone.Core.Test.TvTests
{
var series = Builder<Series>.CreateNew().Build();
series.SeriesType = SeriesTypes.Anime;
series.Seasons = new List<Season>();
return series;
}
@ -178,34 +176,6 @@ namespace NzbDrone.Core.Test.TvTests
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_set_monitored_status_for_old_episodes_to_false_if_no_episodes_existed()
{
var series = GetSeries();
series.Seasons = new List<Season>();
var episodes = GetEpisodes().OrderBy(v => v.SeasonNumber).ThenBy(v => v.EpisodeNumber).Take(4).ToList();
episodes[1].AirDateUtc = DateTime.UtcNow.AddDays(-15);
episodes[2].AirDateUtc = DateTime.UtcNow.AddDays(-10);
episodes[3].AirDateUtc = DateTime.UtcNow.AddDays(1);
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(series, episodes);
_insertedEpisodes = _insertedEpisodes.OrderBy(v => v.EpisodeNumber).ToList();
_insertedEpisodes.Should().HaveSameCount(episodes);
_insertedEpisodes[0].Monitored.Should().Be(false);
_insertedEpisodes[1].Monitored.Should().Be(false);
_insertedEpisodes[2].Monitored.Should().Be(false);
_insertedEpisodes[3].Monitored.Should().Be(true);
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_remove_duplicate_remote_episodes_before_processing()
{
@ -259,65 +229,6 @@ namespace NzbDrone.Core.Test.TvTests
_deletedEpisodes.Should().BeEmpty();
}
[Test]
public void should_get_new_season_and_episode_numbers_when_absolute_episode_number_match_found()
{
const int expectedSeasonNumber = 10;
const int expectedEpisodeNumber = 5;
const int expectedAbsoluteNumber = 3;
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeasonNumber = expectedSeasonNumber)
.With(e => e.EpisodeNumber = expectedEpisodeNumber)
.With(e => e.AbsoluteEpisodeNumber = expectedAbsoluteNumber)
.Build();
var existingEpisode = episode.JsonClone();
existingEpisode.SeasonNumber = 1;
existingEpisode.EpisodeNumber = 1;
existingEpisode.AbsoluteEpisodeNumber = expectedAbsoluteNumber;
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode> { existingEpisode });
Subject.RefreshEpisodeInfo(GetAnimeSeries(), new List<Episode> { episode });
_insertedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty();
_updatedEpisodes.First().SeasonNumber.Should().Be(expectedSeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(expectedEpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(expectedAbsoluteNumber);
}
[Test]
public void should_prefer_absolute_match_over_season_and_epsiode_match()
{
var episodes = Builder<Episode>.CreateListOfSize(2)
.Build()
.ToList();
episodes[0].AbsoluteEpisodeNumber = null;
episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber);
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
var existingEpisode = new Episode
{
SeasonNumber = episodes[0].SeasonNumber,
EpisodeNumber = episodes[0].EpisodeNumber,
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
};
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode> { existingEpisode });
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
}
[Test]
public void should_ignore_episodes_with_no_absolute_episode_in_distinct_by_absolute()
{
@ -427,14 +338,14 @@ namespace NzbDrone.Core.Test.TvTests
}
[Test]
public void should_prefer_regular_season_when_absolute_numbers_conflict()
public void should_match_anime_episodes_by_season_and_episode_numbers()
{
var episodes = Builder<Episode>.CreateListOfSize(2)
.Build()
.ToList();
.Build()
.ToList();
episodes[0].AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber;
episodes[0].SeasonNumber = 0;
episodes[0].AbsoluteEpisodeNumber = null;
episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber);
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
var existingEpisode = new Episode
@ -449,9 +360,13 @@ namespace NzbDrone.Core.Test.TvTests
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[0].SeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[0].EpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[0].AbsoluteEpisodeNumber);
_insertedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
_insertedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
_insertedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
}
[Test]

View File

@ -53,7 +53,7 @@ namespace NzbDrone.Core.Tv
{
try
{
var episodeToUpdate = GetEpisodeToUpdate(series, episode, existingEpisodes);
var episodeToUpdate = existingEpisodes.FirstOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber);
if (episodeToUpdate != null)
{
@ -235,24 +235,6 @@ namespace NzbDrone.Core.Tv
.ToList();
}
private Episode GetEpisodeToUpdate(Series series, Episode episode, List<Episode> existingEpisodes)
{
if (series.SeriesType == SeriesTypes.Anime)
{
if (episode.AbsoluteEpisodeNumber.HasValue)
{
var matchingEpisode = existingEpisodes.FirstOrDefault(e => e.AbsoluteEpisodeNumber == episode.AbsoluteEpisodeNumber);
if (matchingEpisode != null)
{
return matchingEpisode;
}
}
}
return existingEpisodes.FirstOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber);
}
private IEnumerable<Episode> OrderEpisodes(Series series, List<Episode> episodes)
{
if (series.SeriesType == SeriesTypes.Anime)