2011-09-10 11:42:05 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
2011-10-29 07:54:33 +03:00
|
|
|
using NzbDrone.Common;
|
2013-02-19 09:01:03 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2011-09-10 11:42:05 +03:00
|
|
|
using NzbDrone.Core.Model.Notification;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-09-10 11:42:05 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
2011-12-02 04:33:17 +03:00
|
|
|
namespace NzbDrone.Core.Jobs
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
|
|
|
public class BannerDownloadJob : IJob
|
|
|
|
{
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2012-03-07 05:53:49 +03:00
|
|
|
private readonly BannerProvider _bannerProvider;
|
2011-09-10 11:42:05 +03:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/";
|
2011-09-10 11:42:05 +03:00
|
|
|
|
2012-03-07 05:53:49 +03:00
|
|
|
public BannerDownloadJob(SeriesProvider seriesProvider, BannerProvider bannerProvider)
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
|
|
|
_seriesProvider = seriesProvider;
|
2012-03-07 05:53:49 +03:00
|
|
|
_bannerProvider = bannerProvider;
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public BannerDownloadJob()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
{
|
|
|
|
get { return "Banner Download"; }
|
|
|
|
}
|
|
|
|
|
2012-01-15 05:47:23 +03:00
|
|
|
public TimeSpan DefaultInterval
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2012-01-15 05:47:23 +03:00
|
|
|
get { return TimeSpan.FromDays(30); }
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
2012-09-10 22:04:17 +03:00
|
|
|
public virtual void Start(ProgressNotification notification, dynamic options)
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
|
|
|
Logger.Debug("Starting banner download job");
|
|
|
|
|
2012-09-10 22:04:17 +03:00
|
|
|
if (options != null)
|
2011-09-10 11:42:05 +03:00
|
|
|
{
|
2013-02-19 09:56:02 +03:00
|
|
|
Series series = _seriesProvider.Get(options.SeriesId);
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
if (series != null && !String.IsNullOrEmpty(series.BannerUrl))
|
2012-03-07 23:37:36 +03:00
|
|
|
{
|
|
|
|
DownloadBanner(notification, series);
|
|
|
|
}
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-19 09:56:02 +03:00
|
|
|
var seriesInDb = _seriesProvider.All();
|
2011-09-10 11:42:05 +03:00
|
|
|
|
|
|
|
foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl)))
|
|
|
|
{
|
2012-03-07 23:37:36 +03:00
|
|
|
DownloadBanner(notification, series);
|
2011-09-10 11:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Logger.Debug("Finished banner download job");
|
|
|
|
}
|
2012-03-07 23:37:36 +03: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 11:42:05 +03:00
|
|
|
}
|
|
|
|
}
|