mirror of
https://github.com/Radarr/Radarr
synced 2024-12-25 17:27:59 +00:00
TVDB numbering confusion fixed
Fixed: Issue when episode numbers changed on TheTVDB causing episode files were linked incorrectly
This commit is contained in:
parent
02cf23721a
commit
23f8f534fc
2 changed files with 112 additions and 1 deletions
|
@ -630,7 +630,16 @@ public void existing_episodes_keep_their_episodeId_file_id()
|
|||
var currentEpisodes = new List<Episode>();
|
||||
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
||||
{
|
||||
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries });
|
||||
currentEpisodes.Add(new Episode
|
||||
{
|
||||
TvDbEpisodeId = tvDbEpisode.Id,
|
||||
EpisodeId = 99,
|
||||
EpisodeFileId = 69,
|
||||
Ignored = true,
|
||||
Series = fakeSeries,
|
||||
EpisodeNumber = tvDbEpisode.EpisodeNumber,
|
||||
SeasonNumber = tvDbEpisode.SeasonNumber
|
||||
});
|
||||
}
|
||||
|
||||
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
||||
|
@ -657,6 +666,98 @@ public void existing_episodes_keep_their_episodeId_file_id()
|
|||
updatedEpisodes.Should().OnlyContain(c => c.Ignored == true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void existing_episodes_remote_their_episodeId_file_id_when_episode_number_doesnt_match_tvdbid()
|
||||
{
|
||||
const int seriesId = 71663;
|
||||
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
||||
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
||||
).With(c => c.Id = seriesId).Build();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
|
||||
|
||||
var currentEpisodes = new List<Episode>();
|
||||
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
||||
{
|
||||
currentEpisodes.Add(new Episode
|
||||
{
|
||||
TvDbEpisodeId = tvDbEpisode.Id,
|
||||
EpisodeId = 99,
|
||||
EpisodeFileId = 69,
|
||||
Ignored = true,
|
||||
Series = fakeSeries,
|
||||
EpisodeNumber = tvDbEpisode.EpisodeNumber + 1,
|
||||
SeasonNumber = tvDbEpisode.SeasonNumber
|
||||
});
|
||||
}
|
||||
|
||||
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
||||
.Setup(c => c.GetSeries(seriesId, true, false))
|
||||
.Returns(tvdbSeries);
|
||||
|
||||
var updatedEpisodes = new List<Episode>();
|
||||
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(currentEpisodes);
|
||||
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
|
||||
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
|
||||
|
||||
//Assert
|
||||
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void existing_episodes_remote_their_episodeId_file_id_when_season_number_doesnt_match_tvdbid()
|
||||
{
|
||||
const int seriesId = 71663;
|
||||
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
|
||||
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
|
||||
).With(c => c.Id = seriesId).Build();
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
|
||||
|
||||
var currentEpisodes = new List<Episode>();
|
||||
foreach (var tvDbEpisode in tvdbSeries.Episodes)
|
||||
{
|
||||
currentEpisodes.Add(new Episode
|
||||
{
|
||||
TvDbEpisodeId = tvDbEpisode.Id,
|
||||
EpisodeId = 99,
|
||||
EpisodeFileId = 69,
|
||||
Ignored = true,
|
||||
Series = fakeSeries,
|
||||
EpisodeNumber = tvDbEpisode.EpisodeNumber,
|
||||
SeasonNumber = tvDbEpisode.SeasonNumber + 1
|
||||
});
|
||||
}
|
||||
|
||||
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
|
||||
.Setup(c => c.GetSeries(seriesId, true, false))
|
||||
.Returns(tvdbSeries);
|
||||
|
||||
var updatedEpisodes = new List<Episode>();
|
||||
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
||||
.Returns(currentEpisodes);
|
||||
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
|
||||
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
|
||||
|
||||
//Assert
|
||||
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RefreshEpisodeInfo_should_ignore_new_episode_for_ignored_season()
|
||||
{
|
||||
|
|
|
@ -322,6 +322,16 @@ public virtual void RefreshEpisodeInfo(Series series)
|
|||
updateList.Add(episodeToUpdate);
|
||||
}
|
||||
|
||||
if ((episodeToUpdate.EpisodeNumber != episode.EpisodeNumber ||
|
||||
episodeToUpdate.SeasonNumber != episode.SeasonNumber) &&
|
||||
episodeToUpdate.EpisodeFileId > 0)
|
||||
{
|
||||
logger.Info("Unlinking episode file because TheTVDB changed the epsiode number...");
|
||||
|
||||
_database.Delete<EpisodeFile>(episodeToUpdate.EpisodeFileId);
|
||||
episodeToUpdate.EpisodeFileId = 0;
|
||||
}
|
||||
|
||||
episodeToUpdate.SeriesId = series.SeriesId;
|
||||
episodeToUpdate.TvDbEpisodeId = episode.Id;
|
||||
episodeToUpdate.EpisodeNumber = episode.EpisodeNumber;
|
||||
|
|
Loading…
Reference in a new issue