mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-09 12:32:31 +01:00
Added SeasonSearchCommand
This commit is contained in:
parent
7ebcd2b75e
commit
8ee0789c62
@ -19,7 +19,11 @@ public class ReleaseModule : NzbDroneRestModule<ReleaseResource>
|
|||||||
private readonly IDownloadService _downloadService;
|
private readonly IDownloadService _downloadService;
|
||||||
private readonly IParsingService _parsingService;
|
private readonly IParsingService _parsingService;
|
||||||
|
|
||||||
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser, ISearchForNzb nzbSearchService, IMakeDownloadDecision downloadDecisionMaker, IDownloadService downloadService, IParsingService parsingService)
|
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
|
||||||
|
ISearchForNzb nzbSearchService,
|
||||||
|
IMakeDownloadDecision downloadDecisionMaker,
|
||||||
|
IDownloadService downloadService,
|
||||||
|
IParsingService parsingService)
|
||||||
{
|
{
|
||||||
_rssFetcherAndParser = rssFetcherAndParser;
|
_rssFetcherAndParser = rssFetcherAndParser;
|
||||||
_nzbSearchService = nzbSearchService;
|
_nzbSearchService = nzbSearchService;
|
||||||
@ -40,7 +44,6 @@ private ReleaseResource DownloadRelease(ReleaseResource release)
|
|||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<ReleaseResource> GetReleases()
|
private List<ReleaseResource> GetReleases()
|
||||||
{
|
{
|
||||||
if (Request.Query.episodeId != null)
|
if (Request.Query.episodeId != null)
|
||||||
|
59
NzbDrone.Core/Download/DownloadApprovedReportsService.cs
Normal file
59
NzbDrone.Core/Download/DownloadApprovedReportsService.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Core.DecisionEngine;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Download
|
||||||
|
{
|
||||||
|
public interface IDownloadApprovedReportsService
|
||||||
|
{
|
||||||
|
List<DownloadDecision> DownloadApproved(List<DownloadDecision> decisions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DownloadApprovedReportsService : IDownloadApprovedReportsService
|
||||||
|
{
|
||||||
|
private readonly IDownloadService _downloadService;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public DownloadApprovedReportsService(IDownloadService downloadService, Logger logger)
|
||||||
|
{
|
||||||
|
_downloadService = downloadService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DownloadDecision> DownloadApproved(List<DownloadDecision> decisions)
|
||||||
|
{
|
||||||
|
var qualifiedReports = decisions
|
||||||
|
.Where(c => c.Approved)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var remoteEpisodes = qualifiedReports
|
||||||
|
.Select(c => c.RemoteEpisode)
|
||||||
|
.OrderByDescending(c => c.ParsedEpisodeInfo.Quality)
|
||||||
|
.ThenBy(c => c.Episodes.Select(e => e.EpisodeNumber).MinOrDefault())
|
||||||
|
.ThenBy(c => c.Report.Age)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var downloadedReports = new List<int>();
|
||||||
|
|
||||||
|
foreach (var episodeParseResult in remoteEpisodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (downloadedReports.Intersect(episodeParseResult.Episodes.Select(e => e.Id)).Any()) continue;
|
||||||
|
|
||||||
|
_downloadService.DownloadReport(episodeParseResult);
|
||||||
|
downloadedReports.AddRange(episodeParseResult.Episodes.Select(e => e.Id));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.WarnException("Couldn't add report to download queue. " + episodeParseResult, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return qualifiedReports;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,13 @@ public class NzbSearchService : ISearchForNzb
|
|||||||
private readonly IMakeDownloadDecision _makeDownloadDecision;
|
private readonly IMakeDownloadDecision _makeDownloadDecision;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public NzbSearchService(IIndexerService indexerService, IFetchFeedFromIndexers feedFetcher, ISceneMappingService sceneMapping, ISeriesService seriesService, IEpisodeService episodeService, IMakeDownloadDecision makeDownloadDecision, Logger logger)
|
public NzbSearchService(IIndexerService indexerService,
|
||||||
|
IFetchFeedFromIndexers feedFetcher,
|
||||||
|
ISceneMappingService sceneMapping,
|
||||||
|
ISeriesService seriesService,
|
||||||
|
IEpisodeService episodeService,
|
||||||
|
IMakeDownloadDecision makeDownloadDecision,
|
||||||
|
Logger logger)
|
||||||
{
|
{
|
||||||
_indexerService = indexerService;
|
_indexerService = indexerService;
|
||||||
_feedFetcher = feedFetcher;
|
_feedFetcher = feedFetcher;
|
||||||
@ -39,8 +45,6 @@ public NzbSearchService(IIndexerService indexerService, IFetchFeedFromIndexers f
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<DownloadDecision> EpisodeSearch(int episodeId)
|
public List<DownloadDecision> EpisodeSearch(int episodeId)
|
||||||
{
|
{
|
||||||
var episode = _episodeService.GetEpisode(episodeId);
|
var episode = _episodeService.GetEpisode(episodeId);
|
||||||
@ -54,7 +58,6 @@ public List<DownloadDecision> EpisodeSearch(int episodeId)
|
|||||||
return SearchSingle(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
|
return SearchSingle(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<DownloadDecision> SearchSingle(int seriesId, int seasonNumber, int episodeNumber)
|
private List<DownloadDecision> SearchSingle(int seriesId, int seasonNumber, int episodeNumber)
|
||||||
{
|
{
|
||||||
var searchSpec = Get<SingleEpisodeSearchCriteria>(seriesId, seasonNumber);
|
var searchSpec = Get<SingleEpisodeSearchCriteria>(seriesId, seasonNumber);
|
||||||
|
10
NzbDrone.Core/IndexerSearch/SeasonSearchCommand.cs
Normal file
10
NzbDrone.Core/IndexerSearch/SeasonSearchCommand.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.IndexerSearch
|
||||||
|
{
|
||||||
|
public class SeasonSearchCommand : ICommand
|
||||||
|
{
|
||||||
|
public int SeriesId { get; set; }
|
||||||
|
public int SeasonNumber { get; set; }
|
||||||
|
}
|
||||||
|
}
|
27
NzbDrone.Core/IndexerSearch/SeasonSearchService.cs
Normal file
27
NzbDrone.Core/IndexerSearch/SeasonSearchService.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
using NzbDrone.Core.Download;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.IndexerSearch
|
||||||
|
{
|
||||||
|
public class SeasonSearchService : IExecute<SeasonSearchCommand>
|
||||||
|
{
|
||||||
|
private readonly ISearchForNzb _nzbSearchService;
|
||||||
|
private readonly IDownloadApprovedReportsService _downloadApprovedReportsService;
|
||||||
|
|
||||||
|
public SeasonSearchService(ISearchForNzb nzbSearchService, IDownloadApprovedReportsService downloadApprovedReportsService)
|
||||||
|
{
|
||||||
|
_nzbSearchService = nzbSearchService;
|
||||||
|
_downloadApprovedReportsService = downloadApprovedReportsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(SeasonSearchCommand message)
|
||||||
|
{
|
||||||
|
var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, message.SeasonNumber);
|
||||||
|
var qualified = _downloadApprovedReportsService.DownloadApproved(decisions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,14 +17,17 @@ public class RssSyncService : IRssSyncService, IExecute<RssSyncCommand>
|
|||||||
{
|
{
|
||||||
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
||||||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||||
private readonly IDownloadService _downloadService;
|
private readonly IDownloadApprovedReportsService _downloadApprovedReportsService;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public RssSyncService(IFetchAndParseRss rssFetcherAndParser, IMakeDownloadDecision downloadDecisionMaker, IDownloadService downloadService, Logger logger)
|
public RssSyncService(IFetchAndParseRss rssFetcherAndParser,
|
||||||
|
IMakeDownloadDecision downloadDecisionMaker,
|
||||||
|
IDownloadApprovedReportsService downloadApprovedReportsService,
|
||||||
|
Logger logger)
|
||||||
{
|
{
|
||||||
_rssFetcherAndParser = rssFetcherAndParser;
|
_rssFetcherAndParser = rssFetcherAndParser;
|
||||||
_downloadDecisionMaker = downloadDecisionMaker;
|
_downloadDecisionMaker = downloadDecisionMaker;
|
||||||
_downloadService = downloadService;
|
_downloadApprovedReportsService = downloadApprovedReportsService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,30 +38,7 @@ public void Sync()
|
|||||||
|
|
||||||
var reports = _rssFetcherAndParser.Fetch();
|
var reports = _rssFetcherAndParser.Fetch();
|
||||||
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
|
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
|
||||||
|
var qualifiedReports = _downloadApprovedReportsService.DownloadApproved(decisions);
|
||||||
var qualifiedReports = decisions
|
|
||||||
.Where(c => c.Approved)
|
|
||||||
.Select(c => c.RemoteEpisode)
|
|
||||||
.OrderByDescending(c => c.ParsedEpisodeInfo.Quality)
|
|
||||||
.ThenBy(c => c.Episodes.Select(e => e.EpisodeNumber).MinOrDefault())
|
|
||||||
.ThenBy(c => c.Report.Age);
|
|
||||||
|
|
||||||
var downloadedReports = new List<int>();
|
|
||||||
|
|
||||||
foreach (var episodeParseResult in qualifiedReports)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (downloadedReports.Intersect(episodeParseResult.Episodes.Select(e => e.Id)).Any()) continue;
|
|
||||||
|
|
||||||
_downloadService.DownloadReport(episodeParseResult);
|
|
||||||
downloadedReports.AddRange(episodeParseResult.Episodes.Select(e => e.Id));
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.WarnException("Couldn't add report to download queue. " + episodeParseResult, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("RSS Sync Completed. Reports found: {0}, Fetches attempted: {1}", reports.Count, qualifiedReports.Count());
|
_logger.Info("RSS Sync Completed. Reports found: {0}, Fetches attempted: {1}", reports.Count, qualifiedReports.Count());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user