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
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 21:04:17 +02:00
|
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-09-10 10:42:05 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Starting banner download job");
|
|
|
|
|
|
2012-09-10 21:04:17 +02:00
|
|
|
|
if (options != null)
|
2011-09-10 10:42:05 +02:00
|
|
|
|
{
|
2012-10-22 09:05:27 +02:00
|
|
|
|
Series series = _seriesProvider.GetSeries(options.SeriesId);
|
2011-09-10 10:42:05 +02:00
|
|
|
|
|
|
|
|
|
if (series != null && !String.IsNullOrEmpty(series.BannerUrl))
|
2012-03-07 21:37:36 +01:00
|
|
|
|
{
|
|
|
|
|
DownloadBanner(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 21:37:36 +01:00
|
|
|
|
DownloadBanner(notification, series);
|
2011-09-10 10:42:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Debug("Finished banner download job");
|
|
|
|
|
}
|
2012-03-07 21:37:36 +01:00
|
|
|
|
|
|
|
|
|
public virtual void DownloadBanner(ProgressNotification notification, Series series)
|
|
|
|
|
{
|
|
|
|
|
notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title);
|
|
|
|
|
|
|
|
|
|
if (_bannerProvider.Download(series))
|
|
|
|
|
notification.CurrentMessage = string.Format("Successfully download banner for '{0}'", series.Title);
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title);
|
|
|
|
|
}
|
2011-09-10 10:42:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|