Change indexers to use new api

This commit is contained in:
KZ
2015-07-19 18:18:54 +01:00
parent 9b1c0eb0c0
commit 75f0cce064
37 changed files with 532 additions and 957 deletions

View File

@@ -6,10 +6,11 @@ using System.Threading.Tasks;
using Jackett.Models;
using Newtonsoft.Json.Linq;
using NLog;
using Jackett.Services;
namespace Jackett.Indexers
{
public abstract class BaseIndexer: IIndexer
public abstract class BaseIndexer
{
public string DisplayDescription { get; private set; }
public string DisplayName { get; private set; }
@@ -17,28 +18,43 @@ namespace Jackett.Indexers
public Uri SiteLink { get; private set; }
public bool RequiresRageIDLookupDisabled { get; private set; }
public abstract Task ApplyConfiguration(JToken configJson);
public abstract Task<byte[]> Download(Uri link);
public abstract Task<ConfigurationData> GetConfigurationForSetup();
public abstract void LoadFromSavedConfiguration(JToken jsonConfig);
public abstract Task<ReleaseInfo[]> PerformQuery(TorznabQuery query);
protected Logger logger;
protected IIndexerManagerService indexerService;
private Logger logger;
protected static List<CachedResult> cache = new List<CachedResult>();
protected static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0);
public BaseIndexer(string name, string description, Uri link, Logger logger)
public BaseIndexer(string name, string description, bool rageid, Uri link, IIndexerManagerService manager, Logger logger)
{
DisplayName = name;
DisplayDescription = description;
SiteLink = link;
this.logger = logger;
indexerService = manager;
RequiresRageIDLookupDisabled = rageid;
}
protected void LogParseError(string results, Exception ex)
protected void SaveConfig(JToken config)
{
indexerService.SaveConfig(this as IIndexer, config);
}
protected void OnParseError(string results, Exception ex)
{
var fileName = string.Format("Error on {0} for {1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), DisplayName);
var spacing = string.Join("", Enumerable.Repeat(Environment.NewLine, 5));
var fileContents = string.Format("{0}{1}{2}", ex, spacing, results);
logger.Error(fileName + fileContents);
throw ex;
}
protected void CleanCache()
{
foreach (var expired in cache.Where(i => i.Created - DateTime.Now > cacheTime).ToList())
{
cache.Remove(expired);
}
}
}
}