2013-06-02 21:29:00 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-07-19 03:52:31 +02:00
|
|
|
|
using NzbDrone.Core.DataAugmentation.DailySeries;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
using NzbDrone.Core.MetadataSource;
|
2013-06-03 07:39:42 +02:00
|
|
|
|
using NzbDrone.Core.Tv.Commands;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
using NzbDrone.Core.Tv.Events;
|
2013-06-03 07:51:16 +02:00
|
|
|
|
using NzbDrone.Common;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Tv
|
|
|
|
|
{
|
|
|
|
|
public class RefreshSeriesService : IExecute<RefreshSeriesCommand>, IHandleAsync<SeriesAddedEvent>
|
|
|
|
|
{
|
|
|
|
|
private readonly IProvideSeriesInfo _seriesInfo;
|
|
|
|
|
private readonly ISeriesService _seriesService;
|
2013-08-01 04:02:36 +02:00
|
|
|
|
private readonly IRefreshEpisodeService _refreshEpisodeService;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
private readonly IMessageAggregator _messageAggregator;
|
2013-07-19 03:52:31 +02:00
|
|
|
|
private readonly IDailySeriesService _dailySeriesService;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-08-01 04:02:36 +02:00
|
|
|
|
public RefreshSeriesService(IProvideSeriesInfo seriesInfo, ISeriesService seriesService, IRefreshEpisodeService refreshEpisodeService, IMessageAggregator messageAggregator, IDailySeriesService dailySeriesService, Logger logger)
|
2013-06-02 21:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
_seriesInfo = seriesInfo;
|
|
|
|
|
_seriesService = seriesService;
|
2013-08-01 04:02:36 +02:00
|
|
|
|
_refreshEpisodeService = refreshEpisodeService;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
_messageAggregator = messageAggregator;
|
2013-07-19 03:52:31 +02:00
|
|
|
|
_dailySeriesService = dailySeriesService;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(RefreshSeriesCommand message)
|
|
|
|
|
{
|
|
|
|
|
if (message.SeriesId.HasValue)
|
|
|
|
|
{
|
2013-06-03 07:39:42 +02:00
|
|
|
|
var series = _seriesService.GetSeries(message.SeriesId.Value);
|
|
|
|
|
RefreshSeriesInfo(series);
|
2013-06-02 21:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-03 07:39:42 +02:00
|
|
|
|
var allSeries = _seriesService.GetAllSeries().OrderBy(c => c.LastInfoSync).ToList();
|
2013-06-02 21:29:00 +02:00
|
|
|
|
|
2013-06-03 07:39:42 +02:00
|
|
|
|
foreach (var series in allSeries)
|
2013-06-02 21:29:00 +02:00
|
|
|
|
{
|
2013-06-03 07:51:16 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RefreshSeriesInfo(series);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2013-07-05 07:17:25 +02:00
|
|
|
|
_logger.ErrorException("Couldn't refresh info for {0}".Inject(series), e);
|
2013-06-03 07:51:16 +02:00
|
|
|
|
}
|
2013-06-02 21:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HandleAsync(SeriesAddedEvent message)
|
|
|
|
|
{
|
2013-06-03 07:39:42 +02:00
|
|
|
|
RefreshSeriesInfo(message.Series);
|
2013-06-02 21:29:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 07:39:42 +02:00
|
|
|
|
private void RefreshSeriesInfo(Series series)
|
2013-06-02 21:29:00 +02:00
|
|
|
|
{
|
|
|
|
|
var tuple = _seriesInfo.GetSeriesInfo(series.TvdbId);
|
|
|
|
|
|
|
|
|
|
var seriesInfo = tuple.Item1;
|
|
|
|
|
|
|
|
|
|
series.Title = seriesInfo.Title;
|
|
|
|
|
series.AirTime = seriesInfo.AirTime;
|
|
|
|
|
series.Overview = seriesInfo.Overview;
|
|
|
|
|
series.Status = seriesInfo.Status;
|
2013-08-01 04:02:36 +02:00
|
|
|
|
series.CleanTitle = seriesInfo.CleanTitle;
|
2013-06-03 07:39:42 +02:00
|
|
|
|
series.LastInfoSync = DateTime.UtcNow;
|
2013-06-02 21:29:00 +02:00
|
|
|
|
series.Runtime = seriesInfo.Runtime;
|
|
|
|
|
series.Images = seriesInfo.Images;
|
|
|
|
|
series.Network = seriesInfo.Network;
|
|
|
|
|
series.FirstAired = seriesInfo.FirstAired;
|
2013-07-19 03:52:31 +02:00
|
|
|
|
|
|
|
|
|
if (_dailySeriesService.IsDailySeries(series.TvdbId))
|
|
|
|
|
{
|
|
|
|
|
series.SeriesType = SeriesTypes.Daily;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-02 21:29:00 +02:00
|
|
|
|
_seriesService.UpdateSeries(series);
|
|
|
|
|
|
2013-08-01 04:02:36 +02:00
|
|
|
|
_refreshEpisodeService.RefreshEpisodeInfo(series, tuple.Item2);
|
2013-06-02 21:29:00 +02:00
|
|
|
|
|
|
|
|
|
_messageAggregator.PublishEvent(new SeriesUpdatedEvent(series));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|