@ -32,53 +32,112 @@ namespace NzbDrone.Core.Download
public ProcessedDecisions ProcessDecisions ( List < DownloadDecision > decisions )
{
var qualifiedReports = GetQualifiedReports ( decisions ) ;
var prioritizedDecisions = _prioritizeDownloadDecision . PrioritizeDecisions ( qualifiedReport s) ;
//var qualifiedReports = GetQualifiedReports(decisions) ;
var prioritizedDecisions = _prioritizeDownloadDecision . PrioritizeDecisions ( decision s) ;
var grabbed = new List < DownloadDecision > ( ) ;
var pending = new List < DownloadDecision > ( ) ;
foreach ( var report in prioritizedDecisions )
{
var remoteEpisode = report . RemoteEpisode ;
var episodeIds = remoteEpisode . Episodes . Select ( e = > e . Id ) . ToList ( ) ;
//Skip if already grabbed
if ( grabbed . SelectMany ( r = > r . RemoteEpisode . Episodes )
. Select ( e = > e . Id )
. ToList ( )
. Intersect ( episodeIds )
. Any ( ) )
if ( report . IsForMovie )
{
continue ;
}
var remoteMovie = report . RemoteMovie ;
if ( report . TemporarilyRejected )
{
_pendingReleaseService . Add ( report ) ;
pending . Add ( report ) ;
continue ;
}
if ( report . TemporarilyRejected )
{
_pendingReleaseService . Add ( report ) ;
pending . Add ( report ) ;
continue ;
}
if ( pending . SelectMany ( r = > r . RemoteEpisode . Episodes )
. Select ( e = > e . Id )
. ToList ( )
. Intersect ( episodeIds )
. Any ( ) )
{
continue ;
}
if ( remoteMovie = = null | | remoteMovie . Movie = = null )
{
continue ;
}
try
{
_downloadService . DownloadReport ( remoteEpisode ) ;
grabbed . Add ( report ) ;
List < int > movieIds = new List < int > { remoteMovie . Movie . Id } ;
//Skip if already grabbed
if ( grabbed . Select ( r = > r . RemoteMovie . Movie )
. Select ( e = > e . Id )
. ToList ( )
. Intersect ( movieIds )
. Any ( ) )
{
continue ;
}
if ( pending . Select ( r = > r . RemoteMovie . Movie )
. Select ( e = > e . Id )
. ToList ( )
. Intersect ( movieIds )
. Any ( ) )
{
continue ;
}
try
{
_downloadService . DownloadReport ( remoteMovie ) ;
grabbed . Add ( report ) ;
}
catch ( Exception e )
{
//TODO: support for store & forward
//We'll need to differentiate between a download client error and an indexer error
_logger . Warn ( e , "Couldn't add report to download queue. " + remoteMovie ) ;
}
}
catch ( Exception e )
else
{
//TODO: support for store & forward
//We'll need to differentiate between a download client error and an indexer error
_logger . Warn ( e , "Couldn't add report to download queue. " + remoteEpisode ) ;
var remoteEpisode = report . RemoteEpisode ;
if ( remoteEpisode = = null | | remoteEpisode . Episodes = = null )
{
continue ;
}
var episodeIds = remoteEpisode . Episodes . Select ( e = > e . Id ) . ToList ( ) ;
//Skip if already grabbed
if ( grabbed . SelectMany ( r = > r . RemoteEpisode . Episodes )
. Select ( e = > e . Id )
. ToList ( )
. Intersect ( episodeIds )
. Any ( ) )
{
continue ;
}
if ( report . TemporarilyRejected )
{
_pendingReleaseService . Add ( report ) ;
pending . Add ( report ) ;
continue ;
}
if ( pending . SelectMany ( r = > r . RemoteEpisode . Episodes )
. Select ( e = > e . Id )
. ToList ( )
. Intersect ( episodeIds )
. Any ( ) )
{
continue ;
}
try
{
_downloadService . DownloadReport ( remoteEpisode ) ;
grabbed . Add ( report ) ;
}
catch ( Exception e )
{
//TODO: support for store & forward
//We'll need to differentiate between a download client error and an indexer error
_logger . Warn ( e , "Couldn't add report to download queue. " + remoteEpisode ) ;
}
}
}