2011-11-24 02:09:09 +01:00
|
|
|
|
using System;
|
2012-01-24 07:29:32 +01:00
|
|
|
|
using System.Collections.Generic;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
2013-02-24 07:48:52 +01:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-03-05 06:20:47 +01:00
|
|
|
|
using NzbDrone.Core.Jobs.Framework;
|
2013-02-19 07:01:03 +01:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-01-24 07:29:32 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-01-24 07:29:32 +01:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
|
2011-12-02 02:33:17 +01:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
|
|
|
|
public class RecentBacklogSearchJob : IJob
|
|
|
|
|
{
|
2013-02-22 01:47:09 +01:00
|
|
|
|
private readonly IEpisodeService _episodeService;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
private readonly EpisodeSearchJob _episodeSearchJob;
|
2013-02-24 07:48:52 +01:00
|
|
|
|
private readonly IConfigService _configService;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2013-02-22 01:47:09 +01:00
|
|
|
|
public RecentBacklogSearchJob(IEpisodeService episodeService, EpisodeSearchJob episodeSearchJob,
|
2013-02-24 07:48:52 +01:00
|
|
|
|
IConfigService configService)
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
_episodeService = episodeService;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
_episodeSearchJob = episodeSearchJob;
|
2013-02-24 07:48:52 +01:00
|
|
|
|
_configService = configService;
|
2011-11-24 02:09:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Recent Backlog Search"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 03:47:23 +01:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
2012-01-15 03:47:23 +01:00
|
|
|
|
get { return TimeSpan.FromDays(1); }
|
2011-11-24 02:09:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 21:04:17 +02:00
|
|
|
|
public void Start(ProgressNotification notification, dynamic options)
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
2012-01-24 07:29:32 +01:00
|
|
|
|
var missingEpisodes = GetMissingForEnabledSeries();
|
|
|
|
|
|
|
|
|
|
Logger.Debug("Processing missing episodes from the last 30 days, count: {0}", missingEpisodes.Count);
|
|
|
|
|
foreach (var episode in missingEpisodes)
|
2012-01-15 01:01:51 +01:00
|
|
|
|
{
|
2013-02-26 04:58:57 +01:00
|
|
|
|
_episodeSearchJob.Start(notification, new { EpisodeId = episode.Id });
|
2012-01-15 01:01:51 +01:00
|
|
|
|
}
|
2012-01-24 07:29:32 +01:00
|
|
|
|
}
|
2012-01-15 01:01:51 +01:00
|
|
|
|
|
2012-01-24 07:29:32 +01:00
|
|
|
|
public List<Episode> GetMissingForEnabledSeries()
|
|
|
|
|
{
|
2013-02-24 07:48:52 +01:00
|
|
|
|
if (!_configService.EnableBacklogSearching)
|
2012-01-24 07:29:32 +01:00
|
|
|
|
{
|
|
|
|
|
Logger.Trace("Backlog searching is not enabled, only running for explicitly enabled series.");
|
2013-02-20 03:05:15 +01:00
|
|
|
|
return _episodeService.EpisodesWithoutFiles(true).Where(e =>
|
2012-01-24 07:29:32 +01:00
|
|
|
|
e.AirDate >= DateTime.Today.AddDays(-30) &&
|
2012-01-26 02:02:21 +01:00
|
|
|
|
e.Series.BacklogSetting == BacklogSettingType.Enable &&
|
2012-01-24 07:29:32 +01:00
|
|
|
|
e.Series.Monitored
|
|
|
|
|
).ToList();
|
|
|
|
|
}
|
2011-11-24 02:09:09 +01:00
|
|
|
|
|
2012-01-24 07:29:32 +01:00
|
|
|
|
else
|
2011-11-24 02:09:09 +01:00
|
|
|
|
{
|
2013-02-20 03:05:15 +01:00
|
|
|
|
Logger.Trace("Backlog searching is enabled, skipping explicitly disabled series.");
|
|
|
|
|
return _episodeService.EpisodesWithoutFiles(true).Where(e =>
|
2012-01-24 07:29:32 +01:00
|
|
|
|
e.AirDate >= DateTime.Today.AddDays(-30) &&
|
2012-01-26 02:02:21 +01:00
|
|
|
|
e.Series.BacklogSetting != BacklogSettingType.Disable &&
|
2012-01-24 07:29:32 +01:00
|
|
|
|
e.Series.Monitored
|
|
|
|
|
).ToList();
|
2011-11-24 02:09:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|