mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-22 22:14:44 -04:00
Fixed: Do not replace a file unless it contains the same episodes
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public class SameEpisodesSpecification
|
||||
{
|
||||
private readonly IEpisodeService _episodeService;
|
||||
|
||||
public SameEpisodesSpecification(IEpisodeService episodeService)
|
||||
{
|
||||
_episodeService = episodeService;
|
||||
}
|
||||
|
||||
public bool IsSatisfiedBy(List<Episode> episodes)
|
||||
{
|
||||
var episodeIds = episodes.SelectList(e => e.Id);
|
||||
var episodeFileIds = episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFileId).Distinct();
|
||||
|
||||
foreach (var episodeFileId in episodeFileIds)
|
||||
{
|
||||
var episodesInFile = _episodeService.GetEpisodesByFileId(episodeFileId);
|
||||
|
||||
if (episodesInFile.Select(e => e.Id).Except(episodeIds).Any())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user