2011-09-10 10:42:05 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Ninject;
|
|
|
|
|
using NLog;
|
2011-10-29 06:54:33 +02:00
|
|
|
|
using NzbDrone.Common;
|
2011-09-10 10:42:05 +02:00
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 02:33:17 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-09-10 10:42:05 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
|
2011-12-02 02:33:17 +01:00
|
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-09-10 10:42:05 +02:00
|
|
|
|
{
|
|
|
|
|
public class BannerDownloadJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2012-03-07 03:53:49 +01:00
|
|
|
|
private readonly BannerProvider _bannerProvider;
|
2011-09-10 10:42:05 +02:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2012-03-07 03:53:49 +01:00
|
|
|
|
private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/";
|
2011-09-10 10:42:05 +02:00
|
|
|
|
|
|
|
|
|
[Inject]
|
2012-03-07 03:53:49 +01:00
|
|
|
|
public BannerDownloadJob(SeriesProvider seriesProvider, BannerProvider bannerProvider)
|
2011-09-10 10:42:05 +02:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
2012-03-07 03:53:49 +01:00
|
|
|
|
_bannerProvider = bannerProvider;
|
2011-09-10 10:42:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BannerDownloadJob()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Banner Download"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 03:47:23 +01:00
|
|
|
|
public TimeSpan DefaultInterval
|
2011-09-10 10:42:05 +02:00
|
|
|
|
{
|
2012-01-15 03:47:23 +01:00
|
|
|
|
get { return TimeSpan.FromDays(30); }
|
2011-09-10 10:42:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Starting banner download job");
|
|
|
|
|
|
|
|
|
|
if (targetId > 0)
|
|
|
|
|
{
|
|
|
|
|
var series = _seriesProvider.GetSeries(targetId);
|
|
|
|
|
|
|
|
|
|
if (series != null && !String.IsNullOrEmpty(series.BannerUrl))
|
2012-03-07 03:53:49 +01:00
|
|
|
|
_bannerProvider.Download(notification, series);
|
2011-09-10 10:42:05 +02:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var seriesInDb = _seriesProvider.GetAllSeries();
|
|
|
|
|
|
|
|
|
|
foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl)))
|
|
|
|
|
{
|
2012-03-07 03:53:49 +01:00
|
|
|
|
_bannerProvider.Download(notification, series);
|
2011-09-10 10:42:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Debug("Finished banner download job");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|