Jackett/src/Jackett/Indexers/BaseIndexer.cs

71 lines
2.3 KiB
C#
Raw Normal View History

2015-07-19 00:59:30 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Jackett.Models;
using Newtonsoft.Json.Linq;
using NLog;
2015-07-19 17:18:54 +00:00
using Jackett.Services;
2015-07-19 19:28:08 +00:00
using Jackett.Utils;
2015-07-19 00:59:30 +00:00
namespace Jackett.Indexers
{
2015-07-19 17:18:54 +00:00
public abstract class BaseIndexer
2015-07-19 00:59:30 +00:00
{
2015-07-19 13:22:50 +00:00
public string DisplayDescription { get; private set; }
public string DisplayName { get; private set; }
2015-07-19 19:38:41 +00:00
public string ID { get { return GetIndexerID(GetType()); } }
2015-07-19 00:59:30 +00:00
public bool IsConfigured { get; protected set; }
2015-07-19 13:22:50 +00:00
public Uri SiteLink { get; private set; }
public TorznabCapabilities TorznabCaps { get; private set; }
2015-07-19 00:59:30 +00:00
2015-07-19 17:18:54 +00:00
protected Logger logger;
protected IIndexerManagerService indexerService;
// protected IWebClient webClient;
2015-07-19 00:59:30 +00:00
2015-07-19 17:18:54 +00:00
protected static List<CachedResult> cache = new List<CachedResult>();
protected static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0);
2015-07-19 00:59:30 +00:00
2015-07-19 19:38:41 +00:00
public static string GetIndexerID(Type type)
{
return StringUtil.StripNonAlphaNumeric(type.Name.ToLowerInvariant());
}
2015-07-19 17:18:54 +00:00
public BaseIndexer(string name, string description, Uri link, TorznabCapabilities caps, IIndexerManagerService manager,Logger logger)
2015-07-19 00:59:30 +00:00
{
DisplayName = name;
DisplayDescription = description;
SiteLink = link;
TorznabCaps = caps;
2015-07-19 00:59:30 +00:00
this.logger = logger;
2015-07-19 17:18:54 +00:00
indexerService = manager;
// webClient = wc;
2015-07-19 17:18:54 +00:00
}
protected void SaveConfig(JToken config)
{
indexerService.SaveConfig(this as IIndexer, config);
2015-07-19 00:59:30 +00:00
}
2015-07-19 17:18:54 +00:00
protected void OnParseError(string results, Exception ex)
2015-07-19 00:59:30 +00:00
{
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);
2015-07-19 17:18:54 +00:00
throw ex;
}
protected void CleanCache()
{
foreach (var expired in cache.Where(i => i.Created - DateTime.Now > cacheTime).ToList())
{
cache.Remove(expired);
}
2015-07-19 00:59:30 +00:00
}
}
}