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