2011-04-28 06:46:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2011-05-24 00:44:44 +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-28 06:46:56 +00:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-01-16 04:12:47 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-28 06:46:56 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
|
2011-12-02 01:33:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
2011-05-21 00:23:49 +00:00
|
|
|
|
public class DiskScanJob : IJob
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-06-20 03:04:08 +00:00
|
|
|
|
private readonly DiskScanProvider _diskScanProvider;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
2011-05-24 00:44:44 +00:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-28 06:46:56 +00:00
|
|
|
|
|
2012-12-21 05:36:48 +00:00
|
|
|
|
public DiskScanJob(SeriesProvider seriesProvider, DiskScanProvider diskScanProvider,
|
|
|
|
|
ConfigProvider configProvider)
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-06-20 03:04:08 +00:00
|
|
|
|
_diskScanProvider = diskScanProvider;
|
2012-12-21 05:36:48 +00:00
|
|
|
|
_configProvider = configProvider;
|
2011-04-28 06:46:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 00:23:49 +00:00
|
|
|
|
public DiskScanJob()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-28 06:46:56 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Media File Scan"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 02:47:23 +00:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
2012-01-15 02:47:23 +00:00
|
|
|
|
get { return TimeSpan.FromHours(6); }
|
2011-04-28 06:46:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 19:04:17 +00:00
|
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
|
|
|
|
IList<Series> seriesToScan;
|
2012-09-10 19:04:17 +00:00
|
|
|
|
if (options == null || options.SeriesId == 0)
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
2012-12-21 05:36:48 +00:00
|
|
|
|
if (_configProvider.IgnoreArticlesWhenSortingSeries)
|
2013-02-19 06:56:02 +00:00
|
|
|
|
seriesToScan = _seriesProvider.All().OrderBy(o => o.Title.IgnoreArticles()).ToList();
|
2012-12-21 05:36:48 +00:00
|
|
|
|
|
|
|
|
|
else
|
2013-02-19 06:56:02 +00:00
|
|
|
|
seriesToScan = _seriesProvider.All().OrderBy(o => o.Title).ToList();
|
2011-04-28 06:46:56 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-02-19 06:56:02 +00:00
|
|
|
|
seriesToScan = new List<Series>() { _seriesProvider.Get(options.SeriesId) };
|
2011-04-28 06:46:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 04:08:17 +00:00
|
|
|
|
foreach (var series in seriesToScan)
|
2011-04-28 06:46:56 +00:00
|
|
|
|
{
|
2011-05-24 00:44:44 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title);
|
2011-06-20 03:04:08 +00:00
|
|
|
|
_diskScanProvider.Scan(series);
|
2011-07-06 06:17:21 +00:00
|
|
|
|
notification.CurrentMessage = string.Format("Disk Scan completed for '{0}'", series.Title);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2011-07-06 06:17:21 +00:00
|
|
|
|
Logger.ErrorException("An error has occurred while scanning " + series.Title, e);
|
2011-05-24 00:44:44 +00:00
|
|
|
|
}
|
2011-04-28 06:46:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|