2013-03-04 21:37:33 -08:00
|
|
|
using System;
|
2012-01-04 11:24:17 -08:00
|
|
|
using System.Collections.Generic;
|
2011-06-17 18:46:22 -07:00
|
|
|
using System.Linq;
|
2012-01-04 11:24:17 -08:00
|
|
|
using NLog;
|
2013-02-23 22:48:52 -08:00
|
|
|
using NzbDrone.Core.Configuration;
|
2011-11-21 22:27:08 -08:00
|
|
|
using NzbDrone.Core.Helpers;
|
2011-04-20 00:44:13 -07:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
2013-03-04 21:37:33 -08:00
|
|
|
using NzbDrone.Core.ReferenceData;
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-04-20 00:44:13 -07:00
|
|
|
|
2013-03-04 21:37:33 -08:00
|
|
|
namespace NzbDrone.Core.Jobs.Implementations
|
2011-04-20 00:44:13 -07:00
|
|
|
{
|
|
|
|
public class UpdateInfoJob : IJob
|
|
|
|
{
|
2013-02-19 18:05:15 -08:00
|
|
|
private readonly ISeriesService _seriesService;
|
2013-02-21 16:47:09 -08:00
|
|
|
private readonly IEpisodeService _episodeService;
|
2013-03-02 10:25:39 -08:00
|
|
|
private readonly DailySeriesService _dailySeriesService;
|
2013-02-23 22:48:52 -08:00
|
|
|
private readonly IConfigService _configService;
|
2013-02-18 22:56:02 -08:00
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2012-01-04 11:24:17 -08:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-20 00:44:13 -07:00
|
|
|
|
2013-02-21 16:47:09 -08:00
|
|
|
public UpdateInfoJob(ISeriesService seriesService, IEpisodeService episodeService,
|
2013-03-02 10:25:39 -08:00
|
|
|
DailySeriesService dailySeriesService, IConfigService configService, ISeriesRepository seriesRepository)
|
2011-04-20 00:44:13 -07:00
|
|
|
{
|
2013-02-19 18:05:15 -08:00
|
|
|
_seriesService = seriesService;
|
|
|
|
_episodeService = episodeService;
|
2013-03-02 10:25:39 -08:00
|
|
|
_dailySeriesService = dailySeriesService;
|
2013-02-23 22:48:52 -08:00
|
|
|
_configService = configService;
|
2013-02-18 22:56:02 -08:00
|
|
|
_seriesRepository = seriesRepository;
|
2011-04-20 00:44:13 -07:00
|
|
|
}
|
|
|
|
|
2011-05-20 17:23:49 -07:00
|
|
|
public UpdateInfoJob()
|
|
|
|
{
|
2011-06-13 18:23:04 -07:00
|
|
|
|
2011-05-20 17:23:49 -07:00
|
|
|
}
|
|
|
|
|
2011-04-20 00:44:13 -07:00
|
|
|
public string Name
|
|
|
|
{
|
2011-07-04 23:46:03 -07:00
|
|
|
get { return "Update Episode Info"; }
|
2011-04-20 00:44:13 -07:00
|
|
|
}
|
|
|
|
|
2012-01-14 18:47:23 -08:00
|
|
|
public TimeSpan DefaultInterval
|
2011-04-20 00:44:13 -07:00
|
|
|
{
|
2012-01-14 18:47:23 -08:00
|
|
|
get { return TimeSpan.FromHours(12); }
|
2011-04-20 00:44:13 -07:00
|
|
|
}
|
|
|
|
|
2012-09-10 12:04:17 -07:00
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-04-20 00:44:13 -07:00
|
|
|
{
|
2013-02-28 08:33:55 -08:00
|
|
|
IList<Series> ListOfSeriesToUpdate;
|
2012-09-10 12:04:17 -07:00
|
|
|
if (options == null || options.SeriesId == 0)
|
2011-04-20 00:44:13 -07:00
|
|
|
{
|
2013-02-23 22:48:52 -08:00
|
|
|
if (_configService.IgnoreArticlesWhenSortingSeries)
|
2013-02-28 08:33:55 -08:00
|
|
|
ListOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
2012-12-20 21:36:48 -08:00
|
|
|
|
|
|
|
else
|
2013-02-28 08:33:55 -08:00
|
|
|
ListOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
2011-04-20 00:44:13 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-28 08:33:55 -08:00
|
|
|
ListOfSeriesToUpdate = new List<Series>
|
2013-02-22 15:55:43 -08:00
|
|
|
{
|
|
|
|
_seriesRepository.Get((int)options.SeriesId)
|
|
|
|
};
|
2011-04-20 00:44:13 -07:00
|
|
|
}
|
|
|
|
|
2011-11-25 22:13:47 -08:00
|
|
|
//Update any Daily Series in the DB with the IsDaily flag
|
2013-03-02 10:25:39 -08:00
|
|
|
_dailySeriesService.UpdateDailySeries();
|
2011-11-25 22:13:47 -08:00
|
|
|
|
2013-02-28 08:33:55 -08:00
|
|
|
foreach (var seriesToUpdate in ListOfSeriesToUpdate)
|
2011-04-20 00:44:13 -07:00
|
|
|
{
|
2013-02-28 08:33:55 -08:00
|
|
|
var series = seriesToUpdate;
|
|
|
|
|
2012-01-04 11:24:17 -08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
notification.CurrentMessage = "Updating " + series.Title;
|
2013-02-28 08:33:55 -08:00
|
|
|
series = _seriesService.UpdateSeriesInfo(series.Id);
|
2013-02-19 18:05:15 -08:00
|
|
|
_episodeService.RefreshEpisodeInfo(series);
|
2012-01-04 11:24:17 -08:00
|
|
|
notification.CurrentMessage = "Update completed for " + series.Title;
|
|
|
|
}
|
|
|
|
|
2013-02-22 15:55:43 -08:00
|
|
|
catch (Exception ex)
|
2012-01-04 11:24:17 -08:00
|
|
|
{
|
|
|
|
Logger.ErrorException("Failed to update episode info for series: " + series.Title, ex);
|
|
|
|
}
|
2013-02-22 15:55:43 -08:00
|
|
|
|
2011-04-20 00:44:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|