|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
@ -6,17 +7,25 @@ using NzbDrone.Core.Download;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.Languages;
|
|
|
|
|
using NzbDrone.Core.Profiles.Releases;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|
|
|
|
{
|
|
|
|
|
public class UpgradeSpecification : IImportDecisionEngineSpecification
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
|
private readonly IPreferredWordService _preferredWordService;
|
|
|
|
|
private readonly IEpisodeFilePreferredWordCalculator _episodeFilePreferredWordCalculator;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public UpgradeSpecification(IConfigService configService, Logger logger)
|
|
|
|
|
public UpgradeSpecification(IConfigService configService,
|
|
|
|
|
IPreferredWordService preferredWordService,
|
|
|
|
|
IEpisodeFilePreferredWordCalculator episodeFilePreferredWordCalculator,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_configService = configService;
|
|
|
|
|
_preferredWordService = preferredWordService;
|
|
|
|
|
_episodeFilePreferredWordCalculator = episodeFilePreferredWordCalculator;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -25,6 +34,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|
|
|
|
var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
|
|
|
|
|
var qualityComparer = new QualityModelComparer(localEpisode.Series.QualityProfile);
|
|
|
|
|
var languageComparer = new LanguageComparer(localEpisode.Series.LanguageProfile);
|
|
|
|
|
var preferredWordScore = GetPreferredWordScore(localEpisode);
|
|
|
|
|
|
|
|
|
|
foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
|
|
|
|
|
{
|
|
|
|
@ -45,7 +55,6 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|
|
|
|
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Same quality, is not a language upgrade, propers/repacks are preferred and it is not a revision update
|
|
|
|
|
// This will allow language upgrades of a lower revision to be imported, which are allowed to be grabbed,
|
|
|
|
|
// they just don't import automatically.
|
|
|
|
@ -56,17 +65,48 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
|
|
|
|
localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("This file isn't a quality revision upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
|
|
|
|
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
|
|
|
|
return Decision.Reject("Not a quality revision upgrade for existing episode file(s)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (languageCompare < 0 && qualityCompare == 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("This file isn't a language upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
|
|
|
|
return Decision.Reject("Not an upgrade for existing episode file(s)");
|
|
|
|
|
return Decision.Reject("Not a language upgrade for existing episode file(s)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var episodeFilePreferredWordScore = _episodeFilePreferredWordCalculator.Calculate(localEpisode.Series, episodeFile);
|
|
|
|
|
|
|
|
|
|
if (qualityCompare == 0 && preferredWordScore < episodeFilePreferredWordScore)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("This file isn't a preferred word upgrade for all episodes. Skipping {0}", localEpisode.Path);
|
|
|
|
|
return Decision.Reject("Not a preferred word upgrade for existing episode file(s)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Decision.Accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetPreferredWordScore(LocalEpisode localEpisode)
|
|
|
|
|
{
|
|
|
|
|
var series = localEpisode.Series;
|
|
|
|
|
var scores = new List<int>();
|
|
|
|
|
|
|
|
|
|
if (localEpisode.FileEpisodeInfo != null)
|
|
|
|
|
{
|
|
|
|
|
scores.Add(_preferredWordService.Calculate(series, localEpisode.FileEpisodeInfo.ReleaseTitle, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (localEpisode.FolderEpisodeInfo != null)
|
|
|
|
|
{
|
|
|
|
|
scores.Add(_preferredWordService.Calculate(series, localEpisode.FolderEpisodeInfo.ReleaseTitle, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (localEpisode.DownloadClientEpisodeInfo != null)
|
|
|
|
|
{
|
|
|
|
|
scores.Add(_preferredWordService.Calculate(series, localEpisode.DownloadClientEpisodeInfo.ReleaseTitle, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return scores.MaxOrDefault();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|