2011-04-20 07:44:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.Jobs
|
|
|
|
|
{
|
|
|
|
|
public class NewSeriesUpdate : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
|
|
|
|
private readonly MediaFileProvider _mediaFileProvider;
|
2011-05-18 04:21:13 +00:00
|
|
|
|
private readonly SeasonProvider _seasonProvider;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2011-05-18 04:21:13 +00:00
|
|
|
|
public NewSeriesUpdate(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider, SeasonProvider seasonProvider)
|
2011-04-20 07:44:13 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
|
|
|
|
_mediaFileProvider = mediaFileProvider;
|
2011-05-18 04:21:13 +00:00
|
|
|
|
_seasonProvider = seasonProvider;
|
2011-04-20 07:44:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "New Series Update"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return 1; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(ProgressNotification notification, int targetId)
|
|
|
|
|
{
|
|
|
|
|
ScanSeries(notification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ScanSeries(ProgressNotification notification)
|
|
|
|
|
{
|
|
|
|
|
var syncList = _seriesProvider.GetAllSeries().Where(s => s.LastInfoSync == null).ToList();
|
2011-05-17 07:04:49 +00:00
|
|
|
|
if (syncList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-04-20 07:44:13 +00:00
|
|
|
|
|
|
|
|
|
foreach (var currentSeries in syncList)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-05-18 04:21:13 +00:00
|
|
|
|
notification.CurrentMessage = String.Format("Searching for '{0}'",
|
|
|
|
|
new DirectoryInfo(currentSeries.Path).Name);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
var updatedSeries = _seriesProvider.UpdateSeriesInfo(currentSeries.SeriesId);
|
|
|
|
|
|
2011-05-17 07:04:49 +00:00
|
|
|
|
notification.CurrentMessage = String.Format("Downloading episode info for '{0}'",
|
2011-05-18 04:21:13 +00:00
|
|
|
|
updatedSeries.Title);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
_episodeProvider.RefreshEpisodeInfo(updatedSeries.SeriesId);
|
|
|
|
|
|
2011-05-17 07:04:49 +00:00
|
|
|
|
notification.CurrentMessage = String.Format("Scanning disk for '{0}' files", updatedSeries.Title);
|
2011-04-20 07:44:13 +00:00
|
|
|
|
_mediaFileProvider.Scan(_seriesProvider.GetSeries(updatedSeries.SeriesId));
|
|
|
|
|
|
2011-05-18 05:10:46 +00:00
|
|
|
|
if (_mediaFileProvider.GetSeriesFiles(currentSeries.SeriesId).Count() != 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Looking for seasons to ignore");
|
|
|
|
|
foreach (var season in updatedSeries.Seasons)
|
|
|
|
|
{
|
|
|
|
|
if (season.SeasonNumber != updatedSeries.Seasons.Max(s => s.SeasonNumber) && _mediaFileProvider.GetSeasonFiles(season.SeasonId).Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Season {0} of {1} doesn't have any files on disk. season will not be monitored.", season.SeasonNumber, updatedSeries.Title);
|
|
|
|
|
season.Monitored = false;
|
|
|
|
|
_seasonProvider.SaveSeason(season);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2011-04-20 07:44:13 +00:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException(e.Message, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Keep scanning until there no more shows left.
|
|
|
|
|
ScanSeries(notification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|