Patch/onedr0p (#716)

* Alter IMDb lists to what was requested: #697

* Update Pending Release

* Tests (these need to be updated further)

* Alter table migration, movieId already exists

* Update HouseKeeping for pending release

* Fix migratiom and pendingrelease housekeeping
Devin Buhl 8 years ago committed by GitHub
parent 93e55b7575
commit 1db3669afa

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
{ {
private Profile _profile; private Profile _profile;
private DelayProfile _delayProfile; private DelayProfile _delayProfile;
private RemoteEpisode _remoteEpisode; private RemoteMovie _remoteEpisode;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -38,12 +38,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
.With(d => d.PreferredProtocol = DownloadProtocol.Usenet) .With(d => d.PreferredProtocol = DownloadProtocol.Usenet)
.Build(); .Build();
var series = Builder<Series>.CreateNew() var series = Builder<Movie>.CreateNew()
.With(s => s.Profile = _profile) .With(s => s.Profile = _profile)
.Build(); .Build();
_remoteEpisode = Builder<RemoteEpisode>.CreateNew() _remoteEpisode = Builder<RemoteMovie>.CreateNew()
.With(r => r.Series = series) .With(r => r.Movie = series)
.Build(); .Build();
_profile.Items = new List<ProfileQualityItem>(); _profile.Items = new List<ProfileQualityItem>();
@ -53,30 +53,30 @@ namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
_profile.Cutoff = Quality.WEBDL720p; _profile.Cutoff = Quality.WEBDL720p;
_remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo(); _remoteEpisode.ParsedMovieInfo = new ParsedMovieInfo();
_remoteEpisode.Release = new ReleaseInfo(); _remoteEpisode.Release = new ReleaseInfo();
_remoteEpisode.Release.DownloadProtocol = DownloadProtocol.Usenet; _remoteEpisode.Release.DownloadProtocol = DownloadProtocol.Usenet;
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1).Build().ToList(); //_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1).Build().ToList();
_remoteEpisode.Episodes.First().EpisodeFileId = 0; //_remoteEpisode.Episodes.First().EpisodeFileId = 0;
Mocker.GetMock<IDelayProfileService>() //Mocker.GetMock<IDelayProfileService>()
.Setup(s => s.BestForTags(It.IsAny<HashSet<int>>())) // .Setup(s => s.BestForTags(It.IsAny<HashSet<int>>()))
.Returns(_delayProfile); // .Returns(_delayProfile);
Mocker.GetMock<IPendingReleaseService>() //Mocker.GetMock<IPendingReleaseService>()
.Setup(s => s.GetPendingRemoteEpisodes(It.IsAny<int>())) // .Setup(s => s.GetPendingRemoteEpisodes(It.IsAny<int>()))
.Returns(new List<RemoteEpisode>()); // .Returns(new List<RemoteEpisode>());
} }
private void GivenExistingFile(QualityModel quality) private void GivenExistingFile(QualityModel quality)
{ {
_remoteEpisode.Episodes.First().EpisodeFileId = 1; //_remoteEpisode.Episodes.First().EpisodeFileId = 1;
_remoteEpisode.Episodes.First().EpisodeFile = new LazyLoaded<EpisodeFile>(new EpisodeFile //_remoteEpisode.Episodes.First().EpisodeFile = new LazyLoaded<EpisodeFile>(new EpisodeFile
{ // {
Quality = quality // Quality = quality
}); // });
} }
private void GivenUpgradeForExistingFile() private void GivenUpgradeForExistingFile()

@ -20,20 +20,17 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
public class RemoveGrabbedFixture : CoreTest<PendingReleaseService> public class RemoveGrabbedFixture : CoreTest<PendingReleaseService>
{ {
private DownloadDecision _temporarilyRejected; private DownloadDecision _temporarilyRejected;
private Series _series; private Movie _series;
private Episode _episode; private Episode _episode;
private Profile _profile; private Profile _profile;
private ReleaseInfo _release; private ReleaseInfo _release;
private ParsedEpisodeInfo _parsedEpisodeInfo; private ParsedMovieInfo _parsedEpisodeInfo;
private RemoteEpisode _remoteEpisode; private RemoteMovie _remoteEpisode;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_series = Builder<Series>.CreateNew() _series = Builder<Movie>.CreateNew()
.Build();
_episode = Builder<Episode>.CreateNew()
.Build(); .Build();
_profile = new Profile _profile = new Profile
@ -52,13 +49,13 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
_release = Builder<ReleaseInfo>.CreateNew().Build(); _release = Builder<ReleaseInfo>.CreateNew().Build();
_parsedEpisodeInfo = Builder<ParsedEpisodeInfo>.CreateNew().Build(); _parsedEpisodeInfo = Builder<ParsedMovieInfo>.CreateNew().Build();
_parsedEpisodeInfo.Quality = new QualityModel(Quality.HDTV720p); _parsedEpisodeInfo.Quality = new QualityModel(Quality.HDTV720p);
_remoteEpisode = new RemoteEpisode(); _remoteEpisode = new RemoteMovie();
_remoteEpisode.Episodes = new List<Episode>{ _episode }; //_remoteEpisode.Episodes = new List<Episode>{ _episode };
_remoteEpisode.Series = _series; _remoteEpisode.Movie = _series;
_remoteEpisode.ParsedEpisodeInfo = _parsedEpisodeInfo; _remoteEpisode.ParsedMovieInfo = _parsedEpisodeInfo;
_remoteEpisode.Release = _release; _remoteEpisode.Release = _release;
_temporarilyRejected = new DownloadDecision(_remoteEpisode, new Rejection("Temp Rejected", RejectionType.Temporary)); _temporarilyRejected = new DownloadDecision(_remoteEpisode, new Rejection("Temp Rejected", RejectionType.Temporary));
@ -67,13 +64,13 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
.Setup(s => s.All()) .Setup(s => s.All())
.Returns(new List<PendingRelease>()); .Returns(new List<PendingRelease>());
Mocker.GetMock<ISeriesService>() Mocker.GetMock<IMovieService>()
.Setup(s => s.GetSeries(It.IsAny<int>())) .Setup(s => s.GetMovie(It.IsAny<int>()))
.Returns(_series); .Returns(_series);
Mocker.GetMock<IParsingService>() //Mocker.GetMock<IParsingService>()
.Setup(s => s.GetEpisodes(It.IsAny<ParsedEpisodeInfo>(), _series, true, null)) // .Setup(s => s.GetMovie(It.IsAny<ParsedMovieInfo>(), _series.Title))
.Returns(new List<Episode> {_episode}); // .Returns(_episode);
Mocker.GetMock<IPrioritizeDownloadDecision>() Mocker.GetMock<IPrioritizeDownloadDecision>()
.Setup(s => s.PrioritizeDecisions(It.IsAny<List<DownloadDecision>>())) .Setup(s => s.PrioritizeDecisions(It.IsAny<List<DownloadDecision>>()))
@ -89,7 +86,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
.All() .All()
.With(h => h.SeriesId = _series.Id) .With(h => h.SeriesId = _series.Id)
.With(h => h.Release = _release.JsonClone()) .With(h => h.Release = _release.JsonClone())
.With(h => h.ParsedEpisodeInfo = parsedEpisodeInfo) .With(h => h.ParsedMovieInfo = _parsedEpisodeInfo)
.Build(); .Build();
Mocker.GetMock<IPendingReleaseRepository>() Mocker.GetMock<IPendingReleaseRepository>()
@ -102,7 +99,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
{ {
GivenHeldRelease(_parsedEpisodeInfo.Quality); GivenHeldRelease(_parsedEpisodeInfo.Quality);
Subject.Handle(new EpisodeGrabbedEvent(_remoteEpisode)); Subject.Handle(new MovieGrabbedEvent(_remoteEpisode));
VerifyDelete(); VerifyDelete();
} }
@ -112,7 +109,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
{ {
GivenHeldRelease(new QualityModel(Quality.SDTV)); GivenHeldRelease(new QualityModel(Quality.SDTV));
Subject.Handle(new EpisodeGrabbedEvent(_remoteEpisode)); Subject.Handle(new MovieGrabbedEvent(_remoteEpisode));
VerifyDelete(); VerifyDelete();
} }
@ -122,7 +119,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
{ {
GivenHeldRelease(new QualityModel(Quality.Bluray720p)); GivenHeldRelease(new QualityModel(Quality.Bluray720p));
Subject.Handle(new EpisodeGrabbedEvent(_remoteEpisode)); Subject.Handle(new MovieGrabbedEvent(_remoteEpisode));
VerifyNoDelete(); VerifyNoDelete();
} }

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
using System.Data;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(129)]
public class add_parsed_movie_info_to_pending_release : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("PendingReleases").AddColumn("ParsedMovieInfo").AsString().Nullable();
}
}
}

@ -91,19 +91,19 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return Decision.Accept(); return Decision.Accept();
} }
/*
var oldest = _pendingReleaseService.OldestPendingRelease(subject.Series.Id, episodeIds); var oldest = _pendingReleaseService.OldestPendingRelease(subject.Movie.Id);
if (oldest != null && oldest.Release.AgeMinutes > delay) if (oldest != null && oldest.Release.AgeMinutes > delay)
{ {
return Decision.Accept(); return Decision.Accept();
}*/ }
if (subject.Release.AgeMinutes < delay) if (subject.Release.AgeMinutes < delay)
{ {
_logger.Debug("Waiting for better quality release, There is a {0} minute delay on {1}", delay, subject.Release.DownloadProtocol); _logger.Debug("Waiting for better quality release, There is a {0} minute delay on {1}", delay, subject.Release.DownloadProtocol);
return Decision.Reject("Waiting for better quality release"); return Decision.Reject("Waiting for better quality release");
} //TODO: Update for movies! }
return Decision.Accept(); return Decision.Accept();
} }
@ -158,14 +158,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return Decision.Accept(); return Decision.Accept();
} }
var episodeIds = subject.Episodes.Select(e => e.Id); // var episodeIds = subject.Episodes.Select(e => e.Id);
var oldest = _pendingReleaseService.OldestPendingRelease(subject.Series.Id, episodeIds); //var oldest = _pendingReleaseService.OldestPendingRelease(subject.Series.Id, episodeIds);
if (oldest != null && oldest.Release.AgeMinutes > delay) //if (oldest != null && oldest.Release.AgeMinutes > delay)
{ //{
return Decision.Accept(); // return Decision.Accept();
} //}
if (subject.Release.AgeMinutes < delay) if (subject.Release.AgeMinutes < delay)
{ {

@ -11,6 +11,7 @@ namespace NzbDrone.Core.Download.Pending
public string Title { get; set; } public string Title { get; set; }
public DateTime Added { get; set; } public DateTime Added { get; set; }
public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; } public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; }
public ParsedMovieInfo ParsedMovieInfo { get; set; }
public ReleaseInfo Release { get; set; } public ReleaseInfo Release { get; set; }
//Not persisted //Not persisted

@ -8,6 +8,8 @@ namespace NzbDrone.Core.Download.Pending
{ {
void DeleteBySeriesId(int seriesId); void DeleteBySeriesId(int seriesId);
List<PendingRelease> AllBySeriesId(int seriesId); List<PendingRelease> AllBySeriesId(int seriesId);
void DeleteByMovieId(int movieId);
List<PendingRelease> AllByMovieId(int movieId);
} }
public class PendingReleaseRepository : BasicRepository<PendingRelease>, IPendingReleaseRepository public class PendingReleaseRepository : BasicRepository<PendingRelease>, IPendingReleaseRepository
@ -26,5 +28,15 @@ namespace NzbDrone.Core.Download.Pending
{ {
return Query.Where(p => p.SeriesId == seriesId); return Query.Where(p => p.SeriesId == seriesId);
} }
public void DeleteByMovieId(int movieId)
{
Delete(r => r.MovieId == movieId);
}
public List<PendingRelease> AllByMovieId(int movieId)
{
return Query.Where(p => p.MovieId == movieId);
}
} }
} }

@ -23,22 +23,21 @@ namespace NzbDrone.Core.Download.Pending
void Add(DownloadDecision decision); void Add(DownloadDecision decision);
List<ReleaseInfo> GetPending(); List<ReleaseInfo> GetPending();
List<RemoteEpisode> GetPendingRemoteEpisodes(int seriesId); List<RemoteMovie> GetPendingRemoteMovies(int movieId);
List<Queue.Queue> GetPendingQueue(); List<Queue.Queue> GetPendingQueue();
Queue.Queue FindPendingQueueItem(int queueId); Queue.Queue FindPendingQueueItem(int queueId);
void RemovePendingQueueItems(int queueId); void RemovePendingQueueItems(int queueId);
RemoteEpisode OldestPendingRelease(int seriesId, IEnumerable<int> episodeIds); RemoteMovie OldestPendingRelease(int movieId);
} }
public class PendingReleaseService : IPendingReleaseService, public class PendingReleaseService : IPendingReleaseService,
IHandle<SeriesDeletedEvent>,
IHandle<EpisodeGrabbedEvent>,
IHandle<MovieGrabbedEvent>, IHandle<MovieGrabbedEvent>,
IHandle<MovieDeletedEvent>,
IHandle<RssSyncCompleteEvent> IHandle<RssSyncCompleteEvent>
{ {
private readonly IIndexerStatusService _indexerStatusService; private readonly IIndexerStatusService _indexerStatusService;
private readonly IPendingReleaseRepository _repository; private readonly IPendingReleaseRepository _repository;
private readonly ISeriesService _seriesService; private readonly IMovieService _movieService;
private readonly IParsingService _parsingService; private readonly IParsingService _parsingService;
private readonly IDelayProfileService _delayProfileService; private readonly IDelayProfileService _delayProfileService;
private readonly ITaskManager _taskManager; private readonly ITaskManager _taskManager;
@ -48,7 +47,7 @@ namespace NzbDrone.Core.Download.Pending
public PendingReleaseService(IIndexerStatusService indexerStatusService, public PendingReleaseService(IIndexerStatusService indexerStatusService,
IPendingReleaseRepository repository, IPendingReleaseRepository repository,
ISeriesService seriesService, IMovieService movieService,
IParsingService parsingService, IParsingService parsingService,
IDelayProfileService delayProfileService, IDelayProfileService delayProfileService,
ITaskManager taskManager, ITaskManager taskManager,
@ -58,7 +57,7 @@ namespace NzbDrone.Core.Download.Pending
{ {
_indexerStatusService = indexerStatusService; _indexerStatusService = indexerStatusService;
_repository = repository; _repository = repository;
_seriesService = seriesService; _movieService = movieService;
_parsingService = parsingService; _parsingService = parsingService;
_delayProfileService = delayProfileService; _delayProfileService = delayProfileService;
_taskManager = taskManager; _taskManager = taskManager;
@ -72,13 +71,11 @@ namespace NzbDrone.Core.Download.Pending
{ {
var alreadyPending = GetPendingReleases(); var alreadyPending = GetPendingReleases();
var episodeIds = decision.RemoteEpisode.Episodes.Select(e => e.Id); var movieId = decision.RemoteMovie.Movie.Id;
var existingReports = alreadyPending.Where(r => r.RemoteEpisode.Episodes.Select(e => e.Id) var existingReports = alreadyPending.Where(r => r.RemoteMovie.Movie.Id == movieId);
.Intersect(episodeIds)
.Any());
if (existingReports.Any(MatchingReleasePredicate(decision.RemoteEpisode.Release))) if (existingReports.Any(MatchingReleasePredicate(decision.RemoteMovie.Release)))
{ {
_logger.Debug("This release is already pending, not adding again"); _logger.Debug("This release is already pending, not adding again");
return; return;
@ -107,9 +104,9 @@ namespace NzbDrone.Core.Download.Pending
return releases.Where(release => !blockedIndexers.Contains(release.IndexerId)).ToList(); return releases.Where(release => !blockedIndexers.Contains(release.IndexerId)).ToList();
} }
public List<RemoteEpisode> GetPendingRemoteEpisodes(int seriesId) public List<RemoteMovie> GetPendingRemoteMovies(int movieId)
{ {
return _repository.AllBySeriesId(seriesId).Select(GetRemoteEpisode).ToList(); return _repository.AllByMovieId(movieId).Select(GetRemoteMovie).ToList();
} }
public List<Queue.Queue> GetPendingQueue() public List<Queue.Queue> GetPendingQueue()
@ -120,9 +117,9 @@ namespace NzbDrone.Core.Download.Pending
foreach (var pendingRelease in GetPendingReleases()) foreach (var pendingRelease in GetPendingReleases())
{ {
foreach (var episode in pendingRelease.RemoteEpisode.Episodes) //foreach (var episode in pendingRelease.RemoteEpisode.Episodes)
{ //{
var ect = pendingRelease.Release.PublishDate.AddMinutes(GetDelay(pendingRelease.RemoteEpisode)); var ect = pendingRelease.Release.PublishDate.AddMinutes(GetDelay(pendingRelease.RemoteMovie));
if (ect < nextRssSync.Value) if (ect < nextRssSync.Value)
{ {
@ -135,21 +132,22 @@ namespace NzbDrone.Core.Download.Pending
var queue = new Queue.Queue var queue = new Queue.Queue
{ {
Id = GetQueueId(pendingRelease, episode), Id = GetQueueId(pendingRelease, pendingRelease.RemoteMovie.Movie),
Series = pendingRelease.RemoteEpisode.Series, Series = null,
Episode = episode, Episode = null,
Quality = pendingRelease.RemoteEpisode.ParsedEpisodeInfo.Quality, Movie = pendingRelease.RemoteMovie.Movie,
Quality = pendingRelease.RemoteMovie.ParsedMovieInfo.Quality,
Title = pendingRelease.Title, Title = pendingRelease.Title,
Size = pendingRelease.RemoteEpisode.Release.Size, Size = pendingRelease.RemoteMovie.Release.Size,
Sizeleft = pendingRelease.RemoteEpisode.Release.Size, Sizeleft = pendingRelease.RemoteMovie.Release.Size,
RemoteEpisode = pendingRelease.RemoteEpisode, RemoteMovie = pendingRelease.RemoteMovie,
Timeleft = ect.Subtract(DateTime.UtcNow), Timeleft = ect.Subtract(DateTime.UtcNow),
EstimatedCompletionTime = ect, EstimatedCompletionTime = ect,
Status = "Pending", Status = "Pending",
Protocol = pendingRelease.RemoteEpisode.Release.DownloadProtocol Protocol = pendingRelease.RemoteMovie.Release.DownloadProtocol
}; };
queued.Add(queue); queued.Add(queue);
} //}
} }
//Return best quality release for each episode //Return best quality release for each episode
@ -158,7 +156,7 @@ namespace NzbDrone.Core.Download.Pending
var series = g.First().Series; var series = g.First().Series;
return g.OrderByDescending(e => e.Quality, new QualityModelComparer(series.Profile)) return g.OrderByDescending(e => e.Quality, new QualityModelComparer(series.Profile))
.ThenBy(q => PrioritizeDownloadProtocol(q.Series, q.Protocol)) .ThenBy(q => PrioritizeDownloadProtocol(q.Movie, q.Protocol))
.First(); .First();
}); });
@ -173,20 +171,16 @@ namespace NzbDrone.Core.Download.Pending
public void RemovePendingQueueItems(int queueId) public void RemovePendingQueueItems(int queueId)
{ {
var targetItem = FindPendingRelease(queueId); var targetItem = FindPendingRelease(queueId);
var seriesReleases = _repository.AllBySeriesId(targetItem.SeriesId); var movieReleases = _repository.AllByMovieId(targetItem.MovieId);
var releasesToRemove = seriesReleases.Where( var releasesToRemove = movieReleases.Where(c => c.ParsedMovieInfo.MovieTitle == targetItem.ParsedMovieInfo.MovieTitle);
c => c.ParsedEpisodeInfo.SeasonNumber == targetItem.ParsedEpisodeInfo.SeasonNumber &&
c.ParsedEpisodeInfo.EpisodeNumbers.SequenceEqual(targetItem.ParsedEpisodeInfo.EpisodeNumbers));
_repository.DeleteMany(releasesToRemove.Select(c => c.Id)); _repository.DeleteMany(releasesToRemove.Select(c => c.Id));
} }
public RemoteEpisode OldestPendingRelease(int seriesId, IEnumerable<int> episodeIds) public RemoteMovie OldestPendingRelease(int movieId)
{ {
return GetPendingRemoteEpisodes(seriesId).Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any()) return GetPendingRemoteMovies(movieId).OrderByDescending(p => p.Release.AgeHours).FirstOrDefault();
.OrderByDescending(p => p.Release.AgeHours)
.FirstOrDefault();
} }
private List<PendingRelease> GetPendingReleases() private List<PendingRelease> GetPendingReleases()
@ -195,11 +189,11 @@ namespace NzbDrone.Core.Download.Pending
foreach (var release in _repository.All()) foreach (var release in _repository.All())
{ {
var remoteEpisode = GetRemoteEpisode(release); var remoteMovie = GetRemoteMovie(release);
if (remoteEpisode == null) continue; if (remoteMovie == null) continue;
release.RemoteEpisode = remoteEpisode; release.RemoteMovie = remoteMovie;
result.Add(release); result.Add(release);
} }
@ -207,20 +201,19 @@ namespace NzbDrone.Core.Download.Pending
return result; return result;
} }
private RemoteEpisode GetRemoteEpisode(PendingRelease release) private RemoteMovie GetRemoteMovie(PendingRelease release)
{ {
var series = _seriesService.GetSeries(release.SeriesId); var movie = _movieService.GetMovie(release.MovieId);
//Just in case the series was removed, but wasn't cleaned up yet (housekeeper will clean it up) //Just in case the series was removed, but wasn't cleaned up yet (housekeeper will clean it up)
if (series == null) return null; if (movie == null) return null;
var episodes = _parsingService.GetEpisodes(release.ParsedEpisodeInfo, series, true); // var episodes = _parsingService.GetMovie(release.ParsedMovieInfo.MovieTitle);
return new RemoteEpisode return new RemoteMovie
{ {
Series = series, Movie = movie,
Episodes = episodes, ParsedMovieInfo = release.ParsedMovieInfo,
ParsedEpisodeInfo = release.ParsedEpisodeInfo,
Release = release.Release Release = release.Release
}; };
} }
@ -229,10 +222,10 @@ namespace NzbDrone.Core.Download.Pending
{ {
_repository.Insert(new PendingRelease _repository.Insert(new PendingRelease
{ {
SeriesId = decision.RemoteEpisode.Series.Id, MovieId = decision.RemoteMovie.Movie.Id,
ParsedEpisodeInfo = decision.RemoteEpisode.ParsedEpisodeInfo, ParsedMovieInfo = decision.RemoteMovie.ParsedMovieInfo,
Release = decision.RemoteEpisode.Release, Release = decision.RemoteMovie.Release,
Title = decision.RemoteEpisode.Release.Title, Title = decision.RemoteMovie.Release.Title,
Added = DateTime.UtcNow Added = DateTime.UtcNow
}); });
@ -252,46 +245,46 @@ namespace NzbDrone.Core.Download.Pending
p.Release.Indexer == release.Indexer; p.Release.Indexer == release.Indexer;
} }
private int GetDelay(RemoteEpisode remoteEpisode) private int GetDelay(RemoteMovie remoteMovie)
{ {
var delayProfile = _delayProfileService.AllForTags(remoteEpisode.Series.Tags).OrderBy(d => d.Order).First(); var delayProfile = _delayProfileService.AllForTags(remoteMovie.Movie.Tags).OrderBy(d => d.Order).First();
var delay = delayProfile.GetProtocolDelay(remoteEpisode.Release.DownloadProtocol); var delay = delayProfile.GetProtocolDelay(remoteMovie.Release.DownloadProtocol);
var minimumAge = _configService.MinimumAge; var minimumAge = _configService.MinimumAge;
return new[] { delay, minimumAge }.Max(); return new[] { delay, minimumAge }.Max();
} }
private void RemoveGrabbed(RemoteEpisode remoteEpisode) //private void RemoveGrabbed(RemoteEpisode remoteEpisode)
{ //{
var pendingReleases = GetPendingReleases(); // var pendingReleases = GetPendingReleases();
var episodeIds = remoteEpisode.Episodes.Select(e => e.Id); // var episodeIds = remoteEpisode.Episodes.Select(e => e.Id);
var existingReports = pendingReleases.Where(r => r.RemoteEpisode.Episodes.Select(e => e.Id) // var existingReports = pendingReleases.Where(r => r.RemoteEpisode.Episodes.Select(e => e.Id)
.Intersect(episodeIds) // .Intersect(episodeIds)
.Any()) // .Any())
.ToList(); // .ToList();
if (existingReports.Empty()) // if (existingReports.Empty())
{ // {
return; // return;
} // }
var profile = remoteEpisode.Series.Profile.Value; // var profile = remoteEpisode.Series.Profile.Value;
foreach (var existingReport in existingReports) // foreach (var existingReport in existingReports)
{ // {
var compare = new QualityModelComparer(profile).Compare(remoteEpisode.ParsedEpisodeInfo.Quality, // var compare = new QualityModelComparer(profile).Compare(remoteEpisode.ParsedEpisodeInfo.Quality,
existingReport.RemoteEpisode.ParsedEpisodeInfo.Quality); // existingReport.RemoteEpisode.ParsedEpisodeInfo.Quality);
//Only remove lower/equal quality pending releases // //Only remove lower/equal quality pending releases
//It is safer to retry these releases on the next round than remove it and try to re-add it (if its still in the feed) // //It is safer to retry these releases on the next round than remove it and try to re-add it (if its still in the feed)
if (compare >= 0) // if (compare >= 0)
{ // {
_logger.Debug("Removing previously pending release, as it was grabbed."); // _logger.Debug("Removing previously pending release, as it was grabbed.");
Delete(existingReport); // Delete(existingReport);
} // }
} // }
} //}
private void RemoveRejected(List<DownloadDecision> rejected) private void RemoveRejected(List<DownloadDecision> rejected)
{ {
@ -300,7 +293,7 @@ namespace NzbDrone.Core.Download.Pending
foreach (var rejectedRelease in rejected) foreach (var rejectedRelease in rejected)
{ {
var matching = pending.Where(MatchingReleasePredicate(rejectedRelease.RemoteEpisode.Release)); var matching = pending.Where(MatchingReleasePredicate(rejectedRelease.RemoteMovie.Release));
foreach (var pendingRelease in matching) foreach (var pendingRelease in matching)
{ {
@ -312,17 +305,17 @@ namespace NzbDrone.Core.Download.Pending
private PendingRelease FindPendingRelease(int queueId) private PendingRelease FindPendingRelease(int queueId)
{ {
return GetPendingReleases().First(p => p.RemoteEpisode.Episodes.Any(e => queueId == GetQueueId(p, e))); return GetPendingReleases().First(p => queueId == GetQueueId(p, p.RemoteMovie.Movie));
} }
private int GetQueueId(PendingRelease pendingRelease, Episode episode) private int GetQueueId(PendingRelease pendingRelease, Movie movie)
{ {
return HashConverter.GetHashInt31(string.Format("pending-{0}-ep{1}", pendingRelease.Id, episode.Id)); return HashConverter.GetHashInt31(string.Format("pending-{0}-movie{1}", pendingRelease.Id, movie.Id));
} }
private int PrioritizeDownloadProtocol(Series series, DownloadProtocol downloadProtocol) private int PrioritizeDownloadProtocol(Movie movie, DownloadProtocol downloadProtocol)
{ {
var delayProfile = _delayProfileService.BestForTags(series.Tags); var delayProfile = _delayProfileService.BestForTags(movie.Tags);
if (downloadProtocol == delayProfile.PreferredProtocol) if (downloadProtocol == delayProfile.PreferredProtocol)
{ {
@ -332,14 +325,9 @@ namespace NzbDrone.Core.Download.Pending
return 1; return 1;
} }
public void Handle(SeriesDeletedEvent message) public void Handle(MovieDeletedEvent message)
{
_repository.DeleteBySeriesId(message.Series.Id);
}
public void Handle(EpisodeGrabbedEvent message)
{ {
RemoveGrabbed(message.Episode); _repository.DeleteByMovieId(message.Movie.Id);
} }
public void Handle(MovieGrabbedEvent message) public void Handle(MovieGrabbedEvent message)

@ -18,9 +18,9 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
mapper.ExecuteNonQuery(@"DELETE FROM PendingReleases mapper.ExecuteNonQuery(@"DELETE FROM PendingReleases
WHERE Id IN ( WHERE Id IN (
SELECT PendingReleases.Id FROM PendingReleases SELECT PendingReleases.Id FROM PendingReleases
LEFT OUTER JOIN Series LEFT OUTER JOIN Movies
ON PendingReleases.SeriesId = Series.Id ON PendingReleases.MovieId = Movies.Id
WHERE Series.Id IS NULL)"); WHERE Movies.Id IS NULL)");
} }
} }
} }

@ -33,13 +33,22 @@ namespace NzbDrone.Core.NetImport.RSSImport
} }
yield return new NetImportDefinition yield return new NetImportDefinition
{ {
Name = "IMDb Watchlist", Name = "IMDb List",
Enabled = Enabled, Enabled = Enabled,
EnableAuto = true, EnableAuto = true,
ProfileId = 1, ProfileId = 1,
Implementation = GetType().Name, Implementation = GetType().Name,
Settings = new RSSImportSettings { Link = "http://rss.imdb.com/list/YOURLISTID" }, Settings = new RSSImportSettings { Link = "http://rss.imdb.com/list/YOURLISTID" },
}; };
yield return new NetImportDefinition
{
Name = "IMDb Watchlist",
Enabled = Enabled,
EnableAuto = true,
ProfileId = 1,
Implementation = GetType().Name,
Settings = new RSSImportSettings { Link = "http://rss.imdb.com/user/IMDBUSERID/watchlist" },
};
} }
} }

@ -124,6 +124,7 @@
<Compile Include="Authentication\UserRepository.cs" /> <Compile Include="Authentication\UserRepository.cs" />
<Compile Include="Authentication\UserService.cs" /> <Compile Include="Authentication\UserService.cs" />
<Compile Include="Datastore\Migration\123_create_netimport_table.cs" /> <Compile Include="Datastore\Migration\123_create_netimport_table.cs" />
<Compile Include="Datastore\Migration\129_add_parsed_movie_info_to_pending_release.cs" />
<Compile Include="Datastore\Migration\128_remove_kickass.cs" /> <Compile Include="Datastore\Migration\128_remove_kickass.cs" />
<Compile Include="NetImport\Trakt\TraktAPI.cs" /> <Compile Include="NetImport\Trakt\TraktAPI.cs" />
<Compile Include="NetImport\Trakt\TraktImport.cs" /> <Compile Include="NetImport\Trakt\TraktImport.cs" />

Loading…
Cancel
Save