2014-01-22 05:22:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2014-01-27 00:09:44 +00:00
|
|
|
|
using NzbDrone.Common.Disk;
|
2014-01-22 05:22:09 +00:00
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2014-01-24 16:17:56 +00:00
|
|
|
|
using NzbDrone.Core.Metadata.Files;
|
2014-01-22 05:22:09 +00:00
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Metadata
|
|
|
|
|
{
|
2014-01-24 16:17:56 +00:00
|
|
|
|
public abstract class MetadataBase<TSettings> : IMetadata where TSettings : IProviderConfig, new()
|
2014-01-22 05:22:09 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
|
private readonly IHttpProvider _httpProvider;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2014-01-24 16:17:56 +00:00
|
|
|
|
protected MetadataBase(IDiskProvider diskProvider, IHttpProvider httpProvider, Logger logger)
|
2014-01-22 05:22:09 +00:00
|
|
|
|
{
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
_httpProvider = httpProvider;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type ConfigContract
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return typeof(TSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ProviderDefinition> DefaultDefinitions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new List<ProviderDefinition>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProviderDefinition Definition { get; set; }
|
|
|
|
|
|
2014-02-22 22:03:23 +00:00
|
|
|
|
public abstract void OnSeriesUpdated(Series series, List<MetadataFile> existingMetadataFiles, List<EpisodeFile> episodeFiles);
|
2014-01-22 05:22:09 +00:00
|
|
|
|
public abstract void OnEpisodeImport(Series series, EpisodeFile episodeFile, bool newDownload);
|
2014-02-22 22:03:23 +00:00
|
|
|
|
public abstract void AfterRename(Series series, List<MetadataFile> existingMetadataFiles, List<EpisodeFile> episodeFiles);
|
2014-01-24 16:17:56 +00:00
|
|
|
|
public abstract MetadataFile FindMetadataFile(Series series, string path);
|
2014-01-22 05:22:09 +00:00
|
|
|
|
|
|
|
|
|
protected TSettings Settings
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (TSettings)Definition.Settings;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void DownloadImage(Series series, string url, string path)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_diskProvider.FileExists(path))
|
|
|
|
|
{
|
|
|
|
|
_logger.Trace("Image already exists: {0}, will not download again.", path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_httpProvider.DownloadFile(url, path);
|
|
|
|
|
}
|
|
|
|
|
catch (WebException e)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn(string.Format("Couldn't download image {0} for {1}. {2}", url, series, e.Message));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Couldn't download image " + url + " for " + series, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return GetType().Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|