1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-24 17:01:38 +00:00

More comprehensive check to see if we want this episode, will now compare episodeFile with the episode from the feed to see if it is wanted (Quality and Proper)

This commit is contained in:
markus101 2011-02-16 08:37:28 -08:00
parent 309e1ba249
commit 13ab28586f

View file

@ -18,16 +18,18 @@ public class EpisodeProvider : IEpisodeProvider
private readonly ISeasonProvider _seasons;
private readonly ITvDbProvider _tvDb;
private readonly IHistoryProvider _history;
private readonly IQualityProvider _quality;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public EpisodeProvider(IRepository sonicRepo, ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, ITvDbProvider tvDbProvider, IHistoryProvider history)
public EpisodeProvider(IRepository sonicRepo, ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, ITvDbProvider tvDbProvider, IHistoryProvider history, IQualityProvider quality)
{
_sonicRepo = sonicRepo;
_series = seriesProvider;
_tvDb = tvDbProvider;
_seasons = seasonProvider;
_history = history;
_quality = quality;
}
public Episode GetEpisode(long id)
@ -83,6 +85,13 @@ public bool IsNeeded(EpisodeModel episode)
//Check to see if there is an episode file for this episode
var dbEpisode = GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
if (dbEpisode == null)
{
//Todo: How do we want to handle this really? Episode could be released before information is on TheTvDB (Parks and Rec did this a lot in the first season from experience)
throw new NotImplementedException("Episode was not found in the database");
}
episode.EpisodeId = dbEpisode.EpisodeId;
var epWithFiles = _sonicRepo.Single<Episode>(c => c.EpisodeId == episode.EpisodeId && c.Files.Count > 0);
@ -93,8 +102,31 @@ public bool IsNeeded(EpisodeModel episode)
foreach (var file in epWithFiles.Files)
{
if (file.Quality == episode.Quality)
{
//If the episodeFile is a Proper we don't need to download again
if (file.Proper)
return false;
}
//There will never be a time when the episode quality is less than what we have and we want it... ever.... I think.
if (file.Quality > episode.Quality)
return false;
//Now we need to handle upgrades and actually pay attention to the Cutoff Value
if (file.Quality < episode.Quality)
{
var series = _series.GetSeries(episode.SeriesId);
var quality = _quality.Find(series.ProfileId);
if (quality.Cutoff <= file.Quality)
{
//If the episodeFile is a Proper we don't need to download again
if (file.Proper)
return false;
}
}
}
return true; //If we get to this point and the file has not yet been rejected then accept it
}
//IsInHistory? (NZBDrone)