parent
c08d8252ff
commit
0c6ca6971d
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.DecisionEngine.Specifications
|
||||||
|
{
|
||||||
|
public class SameEpisodesGrabSpecification : IDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly SameEpisodesSpecification _sameEpisodesSpecification;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public SameEpisodesGrabSpecification(SameEpisodesSpecification sameEpisodesSpecification, Logger logger)
|
||||||
|
{
|
||||||
|
_sameEpisodesSpecification = sameEpisodesSpecification;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RejectionType Type { get { return RejectionType.Permanent; } }
|
||||||
|
|
||||||
|
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
|
||||||
|
{
|
||||||
|
if (_sameEpisodesSpecification.IsSatisfiedBy(subject.Episodes))
|
||||||
|
{
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Episode file on disk contains more episodes than this release contains");
|
||||||
|
return Decision.Reject("Episode file on disk contains more episodes than this release contains");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.DecisionEngine;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||||
|
{
|
||||||
|
public class SameEpisodesImportSpecification : IImportDecisionEngineSpecification
|
||||||
|
{
|
||||||
|
private readonly SameEpisodesSpecification _sameEpisodesSpecification;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public SameEpisodesImportSpecification(SameEpisodesSpecification sameEpisodesSpecification, Logger logger)
|
||||||
|
{
|
||||||
|
_sameEpisodesSpecification = sameEpisodesSpecification;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RejectionType Type { get { return RejectionType.Permanent; } }
|
||||||
|
|
||||||
|
public Decision IsSatisfiedBy(LocalEpisode localEpisode)
|
||||||
|
{
|
||||||
|
if (_sameEpisodesSpecification.IsSatisfiedBy(localEpisode.Episodes))
|
||||||
|
{
|
||||||
|
return Decision.Accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Episode file on disk contains more episodes than this file contains");
|
||||||
|
return Decision.Reject("Episode file on disk contains more episodes than this file contains");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue