mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Feature/remove autofac from indexer manager (#1549)
* Line endings... * Remove Autofac and all its shenanigans from IndexerManager I'm starting my warpath against Autofac. For the next couple PRs I want to focus on refactoring things rather than creating new things. This includes introducing LINQ extensions wherever possible as well as removing Autofac/Automapper dependencies in classes (or any other dependency, there's a great chance that most of the classes that use Jackett.Services wouldn't need so many of them). All this is order to boost performance and eventually reach testability. Can't stop, won't stop. * Remove unnecessary extension * Modify test project * As per @kaso17, iterating through iterator types rather than allocating them manually * Cleaning up a little * Adjusting interface in tests
This commit is contained in:
@@ -33,7 +33,7 @@ namespace JackettTest
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void InitIndexers()
|
||||
public void InitIndexers(IEnumerable<string> path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -48,16 +48,6 @@ namespace JackettTest
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void InitCardigannIndexers(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SortIndexers()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void InitAggregateIndexer()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@@ -33,7 +33,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public BB(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public BB(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "bB",
|
||||
description: "bB",
|
||||
link: "https://baconbits.org/",
|
||||
|
@@ -26,7 +26,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public BeyondHD(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public BeyondHD(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "BeyondHD",
|
||||
description: "Without BeyondHD, your HDTV is just a TV",
|
||||
link: "https://beyond-hd.me/",
|
||||
|
@@ -32,7 +32,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public BitHdtv(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public BitHdtv(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "BIT-HDTV",
|
||||
description: "Home of high definition invites",
|
||||
link: "https://www.bit-hdtv.com/",
|
||||
|
@@ -33,7 +33,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public BitMeTV(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps)
|
||||
public BitMeTV(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps)
|
||||
: base(name: "BitMeTV",
|
||||
description: "TV Episode specialty tracker",
|
||||
link: "http://www.bitmetv.org/",
|
||||
|
@@ -29,7 +29,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public DanishBits(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps)
|
||||
public DanishBits(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps)
|
||||
: base(name: "DanishBits",
|
||||
description: "A danish closed torrent tracker",
|
||||
link: "https://danishbits.org/",
|
||||
|
@@ -27,7 +27,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public Demonoid(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public Demonoid(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "Demonoid",
|
||||
description: "Demonoid",
|
||||
link: "https://www.demonoid.pw/",
|
||||
|
@@ -29,7 +29,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public DigitalHive(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public DigitalHive(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "DigitalHive",
|
||||
description: "DigitalHive is one of the oldest general trackers",
|
||||
link: "https://www.digitalhive.org/",
|
||||
|
@@ -25,7 +25,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public FunFile(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public FunFile(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "FunFile",
|
||||
description: "A general tracker",
|
||||
link: "https://www.funfile.org/",
|
||||
|
@@ -32,7 +32,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public Fuzer(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public Fuzer(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "Fuzer",
|
||||
description: "Fuzer is a private torrent website with israeli torrents.",
|
||||
link: "https://fuzer.me/",
|
||||
|
@@ -34,7 +34,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public GFTracker(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public GFTracker(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "GFTracker",
|
||||
description: "Home of user happiness",
|
||||
link: "https://www.thegft.org/",
|
||||
|
@@ -28,7 +28,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public HD4Free(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public HD4Free(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "HD4Free",
|
||||
description: "A HD trackers",
|
||||
link: "https://hd4free.xyz/",
|
||||
|
@@ -32,7 +32,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public HDTorrents(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public HDTorrents(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "HD-Torrents",
|
||||
description: "HD-Torrents is a private torrent website with HD torrents and strict rules on their content.",
|
||||
link: "https://hdts.ru/",// Of the accessible domains the .ru seems the most reliable. https://hdts.ru | https://hd-torrents.org | https://hd-torrents.net | https://hd-torrents.me
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using Jackett.Models;
|
||||
using Jackett.Models;
|
||||
using Jackett.Services;
|
||||
using Jackett.Utils;
|
||||
using Jackett.Utils.Clients;
|
||||
@@ -26,7 +26,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public Hardbay(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public Hardbay(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "Hardbay",
|
||||
description: null,
|
||||
link: "https://hardbay.club/",
|
||||
|
@@ -28,7 +28,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public Hebits(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public Hebits(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "Hebits",
|
||||
description: "The Israeli Tracker",
|
||||
link: "https://hebits.net/",
|
||||
|
@@ -34,7 +34,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public Hounddawgs(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps)
|
||||
public Hounddawgs(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps)
|
||||
: base(name: "Hounddawgs",
|
||||
description: "A danish closed torrent tracker",
|
||||
link: "https://hounddawgs.org/",
|
||||
|
@@ -29,7 +29,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public HouseOfTorrents(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public HouseOfTorrents(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "House-of-Torrents",
|
||||
description: "A general tracker",
|
||||
link: "https://houseoftorrents.club/",
|
||||
|
@@ -29,7 +29,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public PassThePopcorn(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps)
|
||||
public PassThePopcorn(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps)
|
||||
: base(name: "PassThePopcorn",
|
||||
description: "PassThePopcorn",
|
||||
link: "https://passthepopcorn.me/",
|
||||
|
@@ -30,7 +30,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public PirateTheNet(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public PirateTheNet(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "PirateTheNet",
|
||||
description: "A movie tracker",
|
||||
link: "http://piratethenet.org/",
|
||||
|
@@ -36,7 +36,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public RevolutionTT(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public RevolutionTT(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "RevolutionTT",
|
||||
description: "The Revolution has begun",
|
||||
link: "https://revolutiontt.me/",
|
||||
|
@@ -28,7 +28,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public SceneTime(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public SceneTime(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "SceneTime",
|
||||
description: "Always on time",
|
||||
link: "https://www.scenetime.com/",
|
||||
|
@@ -25,7 +25,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public ShowRSS(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public ShowRSS(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "ShowRSS",
|
||||
description: "showRSS is a service that allows you to keep track of your favorite TV shows",
|
||||
link: "http://showrss.info/",
|
||||
|
@@ -27,7 +27,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public SpeedCD(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public SpeedCD(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "Speed.cd",
|
||||
description: "Your home now!",
|
||||
link: "https://speed.cd/",
|
||||
|
@@ -26,7 +26,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public Superbits(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public Superbits(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "Superbits",
|
||||
description: null,
|
||||
link: "https://superbits.org/",
|
||||
|
@@ -32,7 +32,7 @@ namespace Jackett.Indexers
|
||||
|
||||
private Dictionary<int, List<int>> _mediaCategoryMapping = new Dictionary<int, List<int>>();
|
||||
|
||||
public T411(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public T411(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "T411",
|
||||
description: "French Torrent Tracker",
|
||||
link: "https://t411.al/",
|
||||
|
@@ -28,7 +28,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public TehConnection(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps)
|
||||
public TehConnection(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps)
|
||||
: base(name: "TehConnection",
|
||||
description: "Working towards providing a well-seeded archive of all available digital forms of cinema and film in their highest possible quality",
|
||||
link: "https://tehconnection.eu/",
|
||||
@@ -199,7 +199,8 @@ namespace Jackett.Indexers
|
||||
release.MinimumSeedTime = 345600;
|
||||
release.Category = new List<int> { 2000 };
|
||||
release.Comments = movieReleasesLink;
|
||||
if (imdb_id > 0) {
|
||||
if (imdb_id > 0)
|
||||
{
|
||||
release.Imdb = imdb_id;
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public TorrentDay(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public TorrentDay(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "TorrentDay",
|
||||
description: "TorrentDay",
|
||||
link: "https://torrentday.it/",
|
||||
|
@@ -29,7 +29,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public TorrentLeech(IIndexerConfigurationService configService, Logger l, IWebClient wc, IProtectionService ps)
|
||||
public TorrentLeech(IIndexerConfigurationService configService, IWebClient wc, Logger l, IProtectionService ps)
|
||||
: base(name: "TorrentLeech",
|
||||
description: "This is what happens when you seed",
|
||||
link: "https://www.torrentleech.org/",
|
||||
|
@@ -30,7 +30,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public TorrentSyndikat(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public TorrentSyndikat(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "Torrent-Syndikat",
|
||||
description: "A German general tracker",
|
||||
link: "https://torrent-syndikat.org/",
|
||||
|
@@ -27,7 +27,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public TransmitheNet(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps)
|
||||
public TransmitheNet(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps)
|
||||
: base(name: "Nebulance",
|
||||
description: " At Nebulance we will change the way you think about TV",
|
||||
link: "https://nebulance.io/",
|
||||
|
@@ -27,7 +27,7 @@ namespace Jackett.Indexers
|
||||
set { base.configData = value; }
|
||||
}
|
||||
|
||||
public x264(IIndexerConfigurationService configService, Logger l, IWebClient w, IProtectionService ps)
|
||||
public x264(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
|
||||
: base(name: "x264",
|
||||
description: "A movie/TV tracker",
|
||||
link: "https://x264.me/",
|
||||
|
@@ -115,17 +115,6 @@ namespace Jackett
|
||||
break;
|
||||
}
|
||||
|
||||
// Register indexers
|
||||
var allTypes = thisAssembly.GetTypes();
|
||||
var allIndexerTypes = allTypes.Where(p => typeof(IIndexer).IsAssignableFrom(p));
|
||||
var allInstantiatableIndexerTypes = allIndexerTypes.Where(p => !p.IsInterface && !p.IsAbstract);
|
||||
var allNonMetaInstantiatableIndexerTypes = allInstantiatableIndexerTypes.Where(p => !typeof(BaseMetaIndexer).IsAssignableFrom(p));
|
||||
var indexerTypes = allNonMetaInstantiatableIndexerTypes.Where(p => p.Name != "CardigannIndexer");
|
||||
foreach (var indexer in indexerTypes)
|
||||
{
|
||||
builder.RegisterType(indexer).Named<IIndexer>(BaseIndexer.GetIndexerID(indexer));
|
||||
}
|
||||
|
||||
Mapper.CreateMap<WebClientByteResult, WebClientStringResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((be, str) =>
|
||||
{
|
||||
str.Content = Encoding.UTF8.GetString(be.Content);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using Autofac;
|
||||
using Jackett.Indexers;
|
||||
using Jackett.Indexers;
|
||||
using Jackett.Models;
|
||||
using Jackett.Utils;
|
||||
using Jackett.Utils.Clients;
|
||||
@@ -24,71 +23,112 @@ namespace Jackett.Services
|
||||
IWebIndexer GetWebIndexer(string name);
|
||||
IEnumerable<IIndexer> GetAllIndexers();
|
||||
|
||||
void InitIndexers();
|
||||
void InitCardigannIndexers(string path);
|
||||
void InitIndexers(IEnumerable<string> path);
|
||||
void InitAggregateIndexer();
|
||||
void SortIndexers();
|
||||
}
|
||||
|
||||
public class IndexerManagerService : IIndexerManagerService
|
||||
{
|
||||
private IContainer container;
|
||||
private Logger logger;
|
||||
private Dictionary<string, IIndexer> indexers = new Dictionary<string, IIndexer>();
|
||||
private ICacheService cacheService;
|
||||
private IIndexerConfigurationService configService;
|
||||
private IProtectionService protectionService;
|
||||
private IWebClient webClient;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
private Dictionary<string, IIndexer> indexers = new Dictionary<string, IIndexer>();
|
||||
private AggregateIndexer aggregateIndexer;
|
||||
|
||||
public IndexerManagerService(IContainer c, IIndexerConfigurationService config, Logger l, ICacheService cache)
|
||||
public IndexerManagerService(IIndexerConfigurationService config, IProtectionService protectionService, IWebClient webClient, Logger l, ICacheService cache)
|
||||
{
|
||||
container = c;
|
||||
configService = config;
|
||||
this.protectionService = protectionService;
|
||||
this.webClient = webClient;
|
||||
logger = l;
|
||||
cacheService = cache;
|
||||
}
|
||||
|
||||
public void InitIndexers()
|
||||
public void InitIndexers(IEnumerable<string> path)
|
||||
{
|
||||
logger.Info("Using HTTP Client: " + container.Resolve<IWebClient>().GetType().Name);
|
||||
InitIndexers();
|
||||
InitCardigannIndexers(path);
|
||||
InitAggregateIndexer();
|
||||
}
|
||||
|
||||
foreach (var idx in container.Resolve<IEnumerable<IIndexer>>().OrderBy(_ => _.DisplayName))
|
||||
private void InitIndexers()
|
||||
{
|
||||
logger.Info("Using HTTP Client: " + webClient.GetType().Name);
|
||||
|
||||
var allTypes = GetType().Assembly.GetTypes();
|
||||
var allIndexerTypes = allTypes.Where(p => typeof(IIndexer).IsAssignableFrom(p));
|
||||
var allInstantiatableIndexerTypes = allIndexerTypes.Where(p => !p.IsInterface && !p.IsAbstract);
|
||||
var allNonMetaInstantiatableIndexerTypes = allInstantiatableIndexerTypes.Where(p => !typeof(BaseMetaIndexer).IsAssignableFrom(p));
|
||||
var indexerTypes = allNonMetaInstantiatableIndexerTypes.Where(p => p.Name != "CardigannIndexer");
|
||||
var ixs = indexerTypes.Select(type =>
|
||||
{
|
||||
var constructorArgumentTypes = new Type[] { typeof(IIndexerConfigurationService), typeof(IWebClient), typeof(Logger), typeof(IProtectionService) };
|
||||
var constructor = type.GetConstructor(constructorArgumentTypes);
|
||||
if (constructor != null)
|
||||
{
|
||||
var arguments = new object[] { configService, webClient, logger, protectionService };
|
||||
var indexer = (IIndexer)constructor.Invoke(arguments);
|
||||
return indexer;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Cannot instantiate " + type.Name);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
foreach (var idx in ixs)
|
||||
{
|
||||
if (idx == null)
|
||||
continue;
|
||||
indexers.Add(idx.ID, idx);
|
||||
configService.Load(idx);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitCardigannIndexers(string path)
|
||||
private void InitCardigannIndexers(IEnumerable<string> path)
|
||||
{
|
||||
logger.Info("Loading Cardigann definitions from: " + path);
|
||||
logger.Info("Loading Cardigann definitions from: " + string.Join(", ", path));
|
||||
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
return;
|
||||
|
||||
DirectoryInfo d = new DirectoryInfo(path);
|
||||
|
||||
foreach (var file in d.GetFiles("*.yml"))
|
||||
{
|
||||
logger.Info("Loading Cardigann definition " + file.FullName);
|
||||
string DefinitionString = File.ReadAllText(file.FullName);
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(new CamelCaseNamingConvention())
|
||||
.IgnoreUnmatchedProperties()
|
||||
.Build();
|
||||
|
||||
try
|
||||
{
|
||||
var directoryInfos = path.Select(p => new DirectoryInfo(p));
|
||||
var existingDirectories = directoryInfos.Where(d => d.Exists);
|
||||
var files = existingDirectories.SelectMany(d => d.GetFiles("*.yml"));
|
||||
var definitions = files.Select(file =>
|
||||
{
|
||||
logger.Info("Loading Cardigann definition " + file.FullName);
|
||||
|
||||
string DefinitionString = File.ReadAllText(file.FullName);
|
||||
var definition = deserializer.Deserialize<IndexerDefinition>(DefinitionString);
|
||||
|
||||
CardigannIndexer idx = new CardigannIndexer(configService, container.Resolve<IWebClient>(), logger, container.Resolve<IProtectionService>(), definition);
|
||||
if (indexers.ContainsKey(idx.ID))
|
||||
return definition;
|
||||
});
|
||||
var cardigannIndexers = definitions.Select(definition =>
|
||||
{
|
||||
logger.Debug(string.Format("Ignoring definition ID={0}, file={1}: Indexer already exists", idx.ID, file.FullName));
|
||||
}
|
||||
else
|
||||
IIndexer indexer = new CardigannIndexer(configService, webClient, logger, protectionService, definition);
|
||||
configService.Load(indexer);
|
||||
return indexer;
|
||||
}).ToList(); // Explicit conversion to list to avoid repeated resource loading
|
||||
|
||||
foreach (var indexer in cardigannIndexers)
|
||||
{
|
||||
indexers.Add(idx.ID, idx);
|
||||
configService.Load(idx);
|
||||
if (indexers.ContainsKey(indexer.ID))
|
||||
{
|
||||
logger.Debug(string.Format("Ignoring definition ID={0}: Indexer already exists", indexer.ID));
|
||||
continue;
|
||||
}
|
||||
|
||||
indexers.Add(indexer.ID, indexer);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -99,12 +139,12 @@ namespace Jackett.Services
|
||||
|
||||
public void InitAggregateIndexer()
|
||||
{
|
||||
var omdbApiKey = container.Resolve<IServerService>().Config.OmdbApiKey;
|
||||
var omdbApiKey = Engine.Server.Config.OmdbApiKey;
|
||||
IFallbackStrategyProvider fallbackStrategyProvider = null;
|
||||
IResultFilterProvider resultFilterProvider = null;
|
||||
if (omdbApiKey != null)
|
||||
{
|
||||
var imdbResolver = new OmdbResolver(container.Resolve<IWebClient>(), omdbApiKey.ToNonNull());
|
||||
var imdbResolver = new OmdbResolver(webClient, omdbApiKey.ToNonNull());
|
||||
fallbackStrategyProvider = new ImdbFallbackStrategyProvider(imdbResolver);
|
||||
resultFilterProvider = new ImdbTitleResultFilterProvider(imdbResolver);
|
||||
}
|
||||
@@ -115,7 +155,7 @@ namespace Jackett.Services
|
||||
}
|
||||
|
||||
logger.Info("Adding aggregate indexer");
|
||||
aggregateIndexer = new AggregateIndexer(fallbackStrategyProvider, resultFilterProvider, configService, container.Resolve<IWebClient>(), logger, container.Resolve<IProtectionService>());
|
||||
aggregateIndexer = new AggregateIndexer(fallbackStrategyProvider, resultFilterProvider, configService, webClient, logger, protectionService);
|
||||
aggregateIndexer.Indexers = indexers.Values;
|
||||
}
|
||||
|
||||
@@ -147,7 +187,7 @@ namespace Jackett.Services
|
||||
|
||||
public IEnumerable<IIndexer> GetAllIndexers()
|
||||
{
|
||||
return indexers.Values;
|
||||
return indexers.Values.OrderBy(_ => _.DisplayName);
|
||||
}
|
||||
|
||||
public async Task TestIndexer(string name)
|
||||
@@ -168,15 +208,5 @@ namespace Jackett.Services
|
||||
configService.Delete(indexer);
|
||||
indexer.Unconfigure();
|
||||
}
|
||||
|
||||
public void SortIndexers()
|
||||
{
|
||||
// Apparently Dictionary are ordered but can't be sorted again
|
||||
// This will recreate the indexers Dictionary to workaround this limitation
|
||||
Dictionary<string, IIndexer> newIndexers = new Dictionary<string, IIndexer>();
|
||||
foreach (var indexer in indexers.OrderBy(_ => _.Value.DisplayName))
|
||||
newIndexers.Add(indexer.Key, indexer.Value);
|
||||
indexers = newIndexers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ namespace Jackett.Services
|
||||
{
|
||||
public interface IProtectionService
|
||||
{
|
||||
byte[] InstanceKey { get; set; }
|
||||
|
||||
string Protect(string plainText);
|
||||
string UnProtect(string plainText);
|
||||
}
|
||||
@@ -22,12 +24,10 @@ namespace Jackett.Services
|
||||
private const string JACKETT_KEY = "JACKETT_KEY";
|
||||
const string APPLICATION_KEY = "Dvz66r3n8vhTGip2/quiw5ISyM37f7L2iOdupzdKmzkvXGhAgQiWK+6F+4qpxjPVNks1qO7LdWuVqRlzgLzeW8mChC6JnBMUS1Fin4N2nS9lh4XPuCZ1che75xO92Nk2vyXUo9KSFG1hvEszAuLfG2Mcg1r0sVyVXd2gQDU/TbY=";
|
||||
|
||||
IServerService serverService;
|
||||
public byte[] InstanceKey { get; set; }
|
||||
|
||||
public ProtectionService(IServerService s)
|
||||
public ProtectionService()
|
||||
{
|
||||
serverService = s;
|
||||
|
||||
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
// We should not be running as root and will only have access to the local store.
|
||||
@@ -70,7 +70,7 @@ namespace Jackett.Services
|
||||
|
||||
var plainBytes = Encoding.UTF8.GetBytes(plainText);
|
||||
var appKey = Convert.FromBase64String(APPLICATION_KEY);
|
||||
var instanceKey = Encoding.UTF8.GetBytes(serverService.Config.InstanceId);
|
||||
var instanceKey = InstanceKey;
|
||||
var entropy = new byte[appKey.Length + instanceKey.Length];
|
||||
Buffer.BlockCopy(instanceKey, 0, entropy, 0, instanceKey.Length);
|
||||
Buffer.BlockCopy(appKey, 0, entropy, instanceKey.Length, appKey.Length);
|
||||
@@ -108,7 +108,7 @@ namespace Jackett.Services
|
||||
return string.Empty;
|
||||
|
||||
var protectedBytes = Convert.FromBase64String(plainText);
|
||||
var instanceKey = Encoding.UTF8.GetBytes(serverService.Config.InstanceId);
|
||||
var instanceKey = InstanceKey;
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
|
@@ -57,7 +57,7 @@ namespace Jackett.Services
|
||||
private IUpdateService updater;
|
||||
private List<string> _notices = new List<string>();
|
||||
|
||||
public ServerService(IIndexerManagerService i, IProcessService p, ISerializeService s, IConfigurationService c, Logger l, IWebClient w, IUpdateService u)
|
||||
public ServerService(IIndexerManagerService i, IProcessService p, ISerializeService s, IConfigurationService c, Logger l, IWebClient w, IUpdateService u, IProtectionService protectionService)
|
||||
{
|
||||
indexerService = i;
|
||||
processService = p;
|
||||
@@ -68,6 +68,8 @@ namespace Jackett.Services
|
||||
updater = u;
|
||||
|
||||
LoadConfig();
|
||||
// "TEMPORARY" HACK
|
||||
protectionService.InstanceKey = Encoding.UTF8.GetBytes(Config.InstanceId);
|
||||
}
|
||||
|
||||
public ServerConfig Config
|
||||
@@ -283,13 +285,7 @@ namespace Jackett.Services
|
||||
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
||||
// Load indexers
|
||||
indexerService.InitIndexers();
|
||||
foreach (string dir in configService.GetCardigannDefinitionsFolders())
|
||||
{
|
||||
indexerService.InitCardigannIndexers(dir);
|
||||
}
|
||||
indexerService.InitAggregateIndexer();
|
||||
indexerService.SortIndexers();
|
||||
indexerService.InitIndexers(configService.GetCardigannDefinitionsFolders());
|
||||
client.Init();
|
||||
updater.CleanupTempDir();
|
||||
}
|
||||
|
Reference in New Issue
Block a user