2011-04-28 09:46:56 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2011-05-24 03:44:44 +03:00
|
|
|
using NLog;
|
2011-04-28 09:46:56 +03:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.Jobs
|
|
|
|
{
|
2011-05-21 03:23:49 +03:00
|
|
|
public class DiskScanJob : IJob
|
2011-04-28 09:46:56 +03:00
|
|
|
{
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
|
|
|
private readonly MediaFileProvider _mediaFileProvider;
|
2011-05-24 03:44:44 +03:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-28 09:46:56 +03:00
|
|
|
|
2011-05-21 03:23:49 +03:00
|
|
|
public DiskScanJob(SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider)
|
2011-04-28 09:46:56 +03:00
|
|
|
{
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
_mediaFileProvider = mediaFileProvider;
|
|
|
|
}
|
|
|
|
|
2011-05-21 03:23:49 +03:00
|
|
|
public DiskScanJob()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-28 09:46:56 +03:00
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "Media File Scan"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
{
|
|
|
|
get { return 60; }
|
|
|
|
}
|
|
|
|
|
2011-05-21 03:23:49 +03:00
|
|
|
public virtual void Start(ProgressNotification notification, int targetId)
|
2011-04-28 09:46:56 +03:00
|
|
|
{
|
|
|
|
IList<Series> seriesToScan;
|
|
|
|
if (targetId == 0)
|
|
|
|
{
|
|
|
|
seriesToScan = _seriesProvider.GetAllSeries().ToList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
seriesToScan = new List<Series>() { _seriesProvider.GetSeries(targetId) };
|
|
|
|
}
|
|
|
|
|
2011-05-21 03:23:49 +03:00
|
|
|
foreach (var series in seriesToScan.Where(c => c.Episodes.Count != 0))
|
2011-04-28 09:46:56 +03:00
|
|
|
{
|
2011-05-24 03:44:44 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title);
|
|
|
|
_mediaFileProvider.Scan(series);
|
|
|
|
notification.CurrentMessage = string.Format("Media File Scan completed for '{0}'", series.Title);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.ErrorException("An error has occured while scanning " + series.Title, e);
|
|
|
|
}
|
2011-04-28 09:46:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|