diff --git a/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs b/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs new file mode 100644 index 000000000..885dd8656 --- /dev/null +++ b/NzbDrone.Core/Jobs/PastWeekBacklogSearchJob.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NLog; +using NzbDrone.Core.Model; +using NzbDrone.Core.Model.Notification; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; + +namespace NzbDrone.Core.Jobs +{ + public class PastWeekBacklogSearchJob : IJob + { + private readonly EpisodeProvider _episodeProvider; + private readonly EpisodeSearchJob _episodeSearchJob; + private readonly ConfigProvider _configProvider; + + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + public PastWeekBacklogSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob, + ConfigProvider configProvider) + { + _episodeProvider = episodeProvider; + _episodeSearchJob = episodeSearchJob; + _configProvider = configProvider; + } + + public string Name + { + get { return "Past Week Backlog Search"; } + } + + public TimeSpan DefaultInterval + { + get { return TimeSpan.FromTicks(0); } + } + + public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + { + var missingEpisodes = GetMissingForEnabledSeries(); + + Logger.Debug("Processing missing episodes from the past week, count: {0}", missingEpisodes.Count); + foreach (var episode in missingEpisodes) + { + _episodeSearchJob.Start(notification, episode.EpisodeId, 0); + } + } + + public List GetMissingForEnabledSeries() + { + return _episodeProvider.EpisodesWithoutFiles(true).Where(e => + e.AirDate >= DateTime.Today.AddDays(-7) && + e.Series.Monitored + ).ToList(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index b51d80ed1..bf58918d0 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -248,6 +248,7 @@ + diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 959780f05..5521a7999 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -52,6 +52,12 @@ namespace NzbDrone.Web.Controllers return JsonNotificationResult.Queued("Recent backlog search"); } + public JsonResult PastWeekBacklogSearch() + { + _jobProvider.QueueJob(typeof(PastWeekBacklogSearchJob)); + return JsonNotificationResult.Queued("Past Week backlog search"); + } + public JsonResult ForceRefresh(int seriesId) { _jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId); diff --git a/NzbDrone.Web/Views/Missing/Index.cshtml b/NzbDrone.Web/Views/Missing/Index.cshtml index 646ce7b85..4af88a37e 100644 --- a/NzbDrone.Web/Views/Missing/Index.cshtml +++ b/NzbDrone.Web/Views/Missing/Index.cshtml @@ -9,6 +9,7 @@
  • @Ajax.ActionLink("Start RSS Sync", "RssSync", "Command", null, null, new { Title = "Check for newly released downloads" })
  • @Ajax.ActionLink("Start Backlog Search", "BacklogSearch", "Command",null, null, new { title = "Search and download all missing episodes"})
  • @Ajax.ActionLink("Start Recent Backlog Search", "RecentBacklogSearch", "Command", null, null, new { title = "Search and download missing episodes that aired in the last 30 days" })
  • +
  • @Ajax.ActionLink("Force Past Week Backlog Search", "PastWeekBacklogSearch", "Command", null, null, new { title = "Search and download missing episodes that aired in the last 7 days (Ignores backlog search settings)" })
  • }