2012-01-04 19:24:17 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-06-18 01:46:22 +00:00
|
|
|
|
using System.Linq;
|
2012-01-04 19:24:17 +00:00
|
|
|
|
using NLog;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-11-22 06:27:08 +00:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
|
2011-12-02 01:33:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
|
|
|
|
public class UpdateInfoJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2011-11-26 06:13:47 +00:00
|
|
|
|
private readonly ReferenceDataProvider _referenceDataProvider;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2013-02-19 06:56:02 +00:00
|
|
|
|
private readonly ISeriesRepository _seriesRepository;
|
2012-01-04 19:24:17 +00:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
2011-11-26 06:13:47 +00:00
|
|
|
|
public UpdateInfoJob(SeriesProvider seriesProvider, EpisodeProvider episodeProvider,
|
2013-02-19 06:56:02 +00:00
|
|
|
|
ReferenceDataProvider referenceDataProvider, ConfigProvider configProvider, ISeriesRepository seriesRepository)
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
2011-11-26 06:13:47 +00:00
|
|
|
|
_referenceDataProvider = referenceDataProvider;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
_configProvider = configProvider;
|
2013-02-19 06:56:02 +00:00
|
|
|
|
_seriesRepository = seriesRepository;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
public UpdateInfoJob()
|
|
|
|
|
{
|
2011-06-14 01:23:04 +00:00
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
2011-07-05 06:46:03 +00:00
|
|
|
|
get { return "Update Episode Info"; }
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 02:47:23 +00:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
2012-01-15 02:47:23 +00:00
|
|
|
|
get { return TimeSpan.FromHours(12); }
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
|
|
|
|
IList<Series> seriesToUpdate;
|
2012-09-10 19:04:17 +00:00
|
|
|
|
if (options == null || options.SeriesId == 0)
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
2012-12-21 05:36:48 +00:00
|
|
|
|
if (_configProvider.IgnoreArticlesWhenSortingSeries)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
seriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
2012-12-21 05:36:48 +00:00
|
|
|
|
|
|
|
|
|
else
|
2013-02-19 06:56:02 +00:00
|
|
|
|
seriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title).ToList();
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-02-19 06:56:02 +00:00
|
|
|
|
seriesToUpdate = new List<Series> { _seriesRepository.Get(options.SeriesId) };
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-26 06:13:47 +00:00
|
|
|
|
//Update any Daily Series in the DB with the IsDaily flag
|
|
|
|
|
_referenceDataProvider.UpdateDailySeries();
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
foreach (var series in seriesToUpdate)
|
|
|
|
|
{
|
2012-01-04 19:24:17 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
notification.CurrentMessage = "Updating " + series.Title;
|
|
|
|
|
_seriesProvider.UpdateSeriesInfo(series.SeriesId);
|
|
|
|
|
_episodeProvider.RefreshEpisodeInfo(series);
|
|
|
|
|
notification.CurrentMessage = "Update completed for " + series.Title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Failed to update episode info for series: " + series.Title, ex);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|