From 7c2b801ee93b7e9422ed88d8a31258ca1f8fa79b Mon Sep 17 00:00:00 2001 From: chibidev Date: Fri, 14 Jul 2017 07:39:52 +0200 Subject: [PATCH] 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 --- .../TestIIndexerManagerServiceHelper.cs | 12 +- src/Jackett/Indexers/BB.cs | 2 +- src/Jackett/Indexers/BeyondHD.cs | 2 +- src/Jackett/Indexers/BitHdtv.cs | 2 +- src/Jackett/Indexers/BitMeTV.cs | 2 +- src/Jackett/Indexers/DanishBits.cs | 14 +- src/Jackett/Indexers/Demonoid.cs | 2 +- src/Jackett/Indexers/DigitalHive.cs | 2 +- src/Jackett/Indexers/FunFile.cs | 2 +- src/Jackett/Indexers/Fuzer.cs | 2 +- src/Jackett/Indexers/GFTracker.cs | 2 +- src/Jackett/Indexers/HD4Free.cs | 2 +- src/Jackett/Indexers/HDTorrents.cs | 2 +- src/Jackett/Indexers/Hardbay.cs | 4 +- src/Jackett/Indexers/Hebits.cs | 2 +- src/Jackett/Indexers/Hounddawgs.cs | 174 +++++++++--------- src/Jackett/Indexers/HouseOfTorrents.cs | 2 +- src/Jackett/Indexers/PassThePopcorn.cs | 14 +- src/Jackett/Indexers/PirateTheNet.cs | 2 +- src/Jackett/Indexers/RevolutionTT.cs | 2 +- src/Jackett/Indexers/SceneTime.cs | 2 +- src/Jackett/Indexers/ShowRSS.cs | 2 +- src/Jackett/Indexers/SpeedCD.cs | 2 +- src/Jackett/Indexers/Superbits.cs | 2 +- src/Jackett/Indexers/T411.cs | 2 +- src/Jackett/Indexers/TehConnection.cs | 19 +- src/Jackett/Indexers/TorrentDay.cs | 2 +- src/Jackett/Indexers/TorrentLeech.cs | 2 +- src/Jackett/Indexers/TorrentSyndikat.cs | 2 +- src/Jackett/Indexers/TransmitheNet.cs | 2 +- src/Jackett/Indexers/x264.cs | 2 +- src/Jackett/JackettModule.cs | 11 -- src/Jackett/Services/IndexerManagerService.cs | 128 ++++++++----- src/Jackett/Services/ProtectionService.cs | 18 +- src/Jackett/Services/ServerService.cs | 12 +- 35 files changed, 231 insertions(+), 225 deletions(-) diff --git a/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs b/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs index 086547dd5..b0f2e3846 100644 --- a/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs +++ b/src/Jackett.Test/TestIIndexerManagerServiceHelper.cs @@ -33,7 +33,7 @@ namespace JackettTest throw new NotImplementedException(); } - public void InitIndexers() + public void InitIndexers(IEnumerable 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(); diff --git a/src/Jackett/Indexers/BB.cs b/src/Jackett/Indexers/BB.cs index 83dc68586..495aca3a2 100644 --- a/src/Jackett/Indexers/BB.cs +++ b/src/Jackett/Indexers/BB.cs @@ -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/", diff --git a/src/Jackett/Indexers/BeyondHD.cs b/src/Jackett/Indexers/BeyondHD.cs index 147a07a9e..0eb2a4d3c 100644 --- a/src/Jackett/Indexers/BeyondHD.cs +++ b/src/Jackett/Indexers/BeyondHD.cs @@ -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/", diff --git a/src/Jackett/Indexers/BitHdtv.cs b/src/Jackett/Indexers/BitHdtv.cs index 97176fb6b..b667cff31 100644 --- a/src/Jackett/Indexers/BitHdtv.cs +++ b/src/Jackett/Indexers/BitHdtv.cs @@ -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/", diff --git a/src/Jackett/Indexers/BitMeTV.cs b/src/Jackett/Indexers/BitMeTV.cs index 5f6a07751..d81cb8acb 100644 --- a/src/Jackett/Indexers/BitMeTV.cs +++ b/src/Jackett/Indexers/BitMeTV.cs @@ -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/", diff --git a/src/Jackett/Indexers/DanishBits.cs b/src/Jackett/Indexers/DanishBits.cs index 62ae2f217..94fbe8ccc 100644 --- a/src/Jackett/Indexers/DanishBits.cs +++ b/src/Jackett/Indexers/DanishBits.cs @@ -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/", @@ -160,7 +160,7 @@ namespace Jackett.Indexers var releasesPerPage = 100; var releases = new List(); - var page = (query.Offset/releasesPerPage) + 1; + var page = (query.Offset / releasesPerPage) + 1; string episodeSearchUrl; if (string.IsNullOrEmpty(query.GetQueryString())) @@ -212,13 +212,13 @@ namespace Jackett.Indexers var catUrl = catAnchor.GetAttribute("href"); var catStr = Regex.Match(catUrl, "filter_(?[0-9]+)=on").Groups["catNo"].Value; var catNo = int.Parse(catStr); - var moviesCatsDanish = new[] { 2,3,10,28,29,31 }; - var moviesCatsIntl = new[] { 8,9,11,22,24 }; + var moviesCatsDanish = new[] { 2, 3, 10, 28, 29, 31 }; + var moviesCatsIntl = new[] { 8, 9, 11, 22, 24 }; var moviesCats = configData.OnlyDanishCategories.Value ? moviesCatsDanish : moviesCatsDanish.Concat(moviesCatsIntl); - var seriesCatsDanish = new[] { 1,4,30 }; - var seriesCatsIntl = new[] { 20,21 }; + var seriesCatsDanish = new[] { 1, 4, 30 }; + var seriesCatsIntl = new[] { 20, 21 }; var seriesCats = configData.OnlyDanishCategories.Value ? seriesCatsDanish : seriesCatsDanish.Concat(seriesCatsIntl); @@ -248,7 +248,7 @@ namespace Jackett.Indexers var addedElement = qRow.Find("span.time").FirstElement(); var addedStr = addedElement.GetAttribute("title"); release.PublishDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.ParseExact(addedStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture), denmarkTz).ToLocalTime(); - + var columns = qRow.Children(); var seedersElement = columns.Reverse().Skip(1).First(); release.Seeders = int.Parse(seedersElement.InnerText); diff --git a/src/Jackett/Indexers/Demonoid.cs b/src/Jackett/Indexers/Demonoid.cs index 1eac98814..aa755f093 100644 --- a/src/Jackett/Indexers/Demonoid.cs +++ b/src/Jackett/Indexers/Demonoid.cs @@ -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/", diff --git a/src/Jackett/Indexers/DigitalHive.cs b/src/Jackett/Indexers/DigitalHive.cs index 8c76fa857..6bb91620d 100644 --- a/src/Jackett/Indexers/DigitalHive.cs +++ b/src/Jackett/Indexers/DigitalHive.cs @@ -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/", diff --git a/src/Jackett/Indexers/FunFile.cs b/src/Jackett/Indexers/FunFile.cs index 4dd7730b5..b77206ece 100644 --- a/src/Jackett/Indexers/FunFile.cs +++ b/src/Jackett/Indexers/FunFile.cs @@ -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/", diff --git a/src/Jackett/Indexers/Fuzer.cs b/src/Jackett/Indexers/Fuzer.cs index 3d7f2834b..a3049f9ad 100644 --- a/src/Jackett/Indexers/Fuzer.cs +++ b/src/Jackett/Indexers/Fuzer.cs @@ -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/", diff --git a/src/Jackett/Indexers/GFTracker.cs b/src/Jackett/Indexers/GFTracker.cs index 5f19effa4..833e5b81f 100644 --- a/src/Jackett/Indexers/GFTracker.cs +++ b/src/Jackett/Indexers/GFTracker.cs @@ -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/", diff --git a/src/Jackett/Indexers/HD4Free.cs b/src/Jackett/Indexers/HD4Free.cs index e23428a4f..8e10b808e 100644 --- a/src/Jackett/Indexers/HD4Free.cs +++ b/src/Jackett/Indexers/HD4Free.cs @@ -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/", diff --git a/src/Jackett/Indexers/HDTorrents.cs b/src/Jackett/Indexers/HDTorrents.cs index 1e479ff7b..47668760a 100644 --- a/src/Jackett/Indexers/HDTorrents.cs +++ b/src/Jackett/Indexers/HDTorrents.cs @@ -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 diff --git a/src/Jackett/Indexers/Hardbay.cs b/src/Jackett/Indexers/Hardbay.cs index e2f37a167..8851e2b6f 100644 --- a/src/Jackett/Indexers/Hardbay.cs +++ b/src/Jackett/Indexers/Hardbay.cs @@ -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/", diff --git a/src/Jackett/Indexers/Hebits.cs b/src/Jackett/Indexers/Hebits.cs index 92ab4b415..72532b313 100644 --- a/src/Jackett/Indexers/Hebits.cs +++ b/src/Jackett/Indexers/Hebits.cs @@ -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/", diff --git a/src/Jackett/Indexers/Hounddawgs.cs b/src/Jackett/Indexers/Hounddawgs.cs index c6fcc0808..d09c1fef6 100644 --- a/src/Jackett/Indexers/Hounddawgs.cs +++ b/src/Jackett/Indexers/Hounddawgs.cs @@ -23,28 +23,28 @@ using System.Text.RegularExpressions; namespace Jackett.Indexers { - public class Hounddawgs : BaseWebIndexer - { - private string LoginUrl { get { return SiteLink + "login.php"; } } - private string SearchUrl { get { return SiteLink + "torrents.php"; } } + public class Hounddawgs : BaseWebIndexer + { + private string LoginUrl { get { return SiteLink + "login.php"; } } + private string SearchUrl { get { return SiteLink + "torrents.php"; } } - new NxtGnConfigurationData configData - { - get { return (NxtGnConfigurationData)base.configData; } - set { base.configData = value; } - } + new NxtGnConfigurationData configData + { + get { return (NxtGnConfigurationData)base.configData; } + set { base.configData = value; } + } - public Hounddawgs(IIndexerConfigurationService configService, Logger l, IWebClient c, IProtectionService ps) - : base(name: "Hounddawgs", - description: "A danish closed torrent tracker", - link: "https://hounddawgs.org/", - caps: TorznabUtil.CreateDefaultTorznabTVCaps(), - configService: configService, - client: c, - logger: l, - p: ps, - configData: new NxtGnConfigurationData()) - { + public Hounddawgs(IIndexerConfigurationService configService, IWebClient c, Logger l, IProtectionService ps) + : base(name: "Hounddawgs", + description: "A danish closed torrent tracker", + link: "https://hounddawgs.org/", + caps: TorznabUtil.CreateDefaultTorznabTVCaps(), + configService: configService, + client: c, + logger: l, + p: ps, + configData: new NxtGnConfigurationData()) + { Encoding = Encoding.GetEncoding("UTF-8"); Language = "da-dk"; Type = "private"; @@ -84,32 +84,32 @@ namespace Jackett.Indexers AddCategoryMapping(67, TorznabCatType.XXX, "XXX"); } - public override async Task ApplyConfiguration(JToken configJson) - { - LoadValuesFromJson(configJson); - var pairs = new Dictionary { - { "username", configData.Username.Value }, - { "password", configData.Password.Value }, - { "keeplogged", "1" }, - { "login", "Login" } + public override async Task ApplyConfiguration(JToken configJson) + { + LoadValuesFromJson(configJson); + var pairs = new Dictionary { + { "username", configData.Username.Value }, + { "password", configData.Password.Value }, + { "keeplogged", "1" }, + { "login", "Login" } - }; - // Get inital cookies + }; + // Get inital cookies var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, "https://hounddawgs.org/"); - await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("Velkommen til"), () => - { - CQ dom = response.Content; - var messageEl = dom["inputs"]; - var errorMessage = messageEl.Text().Trim(); - throw new ExceptionWithConfigData(errorMessage, configData); - }); - return IndexerConfigurationStatus.RequiresTesting; - } + await ConfigureIfOK(response.Cookies, response.Content != null && response.Content.Contains("Velkommen til"), () => + { + CQ dom = response.Content; + var messageEl = dom["inputs"]; + var errorMessage = messageEl.Text().Trim(); + throw new ExceptionWithConfigData(errorMessage, configData); + }); + return IndexerConfigurationStatus.RequiresTesting; + } - protected override async Task> PerformQuery(TorznabQuery query) - { - var releases = new List(); + protected override async Task> PerformQuery(TorznabQuery query) + { + var releases = new List(); var searchString = query.GetQueryString(); var searchUrl = SearchUrl; var queryCollection = new NameValueCollection(); @@ -129,34 +129,34 @@ namespace Jackett.Indexers searchUrl += "?" + queryCollection.GetQueryString(); var results = await RequestStringWithCookiesAndRetry(searchUrl); - if (results.Content.Contains("Din søgning gav intet resultat.")) - { - return releases; - } - try - { - CQ dom = results.Content; + if (results.Content.Contains("Din søgning gav intet resultat.")) + { + return releases; + } + try + { + CQ dom = results.Content; - var rows = dom["#torrent_table > tbody > tr"].ToArray(); + var rows = dom["#torrent_table > tbody > tr"].ToArray(); - foreach (var row in rows.Skip(1)) - { + foreach (var row in rows.Skip(1)) + { var qRow = row.Cq(); var release = new ReleaseInfo(); - release.MinimumRatio = 1; - release.MinimumSeedTime = 172800; + release.MinimumRatio = 1; + release.MinimumSeedTime = 172800; - var qCat = row.ChildElements.ElementAt(0).ChildElements.ElementAt(0).Cq(); - var catUrl = qCat.Attr("href"); - var cat = catUrl.Substring(catUrl.LastIndexOf('[') + 1).Trim(']'); + var qCat = row.ChildElements.ElementAt(0).ChildElements.ElementAt(0).Cq(); + var catUrl = qCat.Attr("href"); + var cat = catUrl.Substring(catUrl.LastIndexOf('[') + 1).Trim(']'); release.Category = MapTrackerCatToNewznab(cat); var qAdded = row.ChildElements.ElementAt(4).ChildElements.ElementAt(0).Cq(); - var addedStr = qAdded.Attr("title"); - release.PublishDate = DateTime.ParseExact(addedStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture); + var addedStr = qAdded.Attr("title"); + release.PublishDate = DateTime.ParseExact(addedStr, "MMM dd yyyy, HH:mm", CultureInfo.InvariantCulture); var overlayScript = qRow.Find("script:contains(\"var overlay\")").Text(); - var overlayHtmlEscaped = overlayScript.Substring(overlayScript.IndexOf('=')+1).Trim().Trim('"'); + var overlayHtmlEscaped = overlayScript.Substring(overlayScript.IndexOf('=') + 1).Trim().Trim('"'); var overlayHtml = Regex.Unescape(overlayHtmlEscaped); CQ qOverlay = overlayHtml; var title = qOverlay.Find("td.overlay > strong"); @@ -177,46 +177,46 @@ namespace Jackett.Indexers var qLink = row.Cq().Find("a[href^=\"torrents.php?id=\"][onmouseover]"); release.Comments = new Uri(SiteLink + qLink.Attr("href")); - release.Guid = release.Comments; + release.Guid = release.Comments; - var qDownload = row.ChildElements.ElementAt(1).ChildElements.ElementAt(1).ChildElements.ElementAt(0).Cq(); - release.Link = new Uri(SiteLink + qDownload.Attr("href")); + var qDownload = row.ChildElements.ElementAt(1).ChildElements.ElementAt(1).ChildElements.ElementAt(0).Cq(); + release.Link = new Uri(SiteLink + qDownload.Attr("href")); - var sizeStr = row.ChildElements.ElementAt(5).Cq().Text(); - release.Size = ReleaseInfo.GetBytes(sizeStr); + var sizeStr = row.ChildElements.ElementAt(5).Cq().Text(); + release.Size = ReleaseInfo.GetBytes(sizeStr); - release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(6).Cq().Text()); - release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text()) + release.Seeders; + release.Seeders = ParseUtil.CoerceInt(row.ChildElements.ElementAt(6).Cq().Text()); + release.Peers = ParseUtil.CoerceInt(row.ChildElements.ElementAt(7).Cq().Text()) + release.Seeders; var files = row.Cq().Find("td:nth-child(4)").Text(); release.Files = ParseUtil.CoerceInt(files); if (row.Cq().Find("img[src=\"/static//common/browse/freeleech.png\"]").Any()) - release.DownloadVolumeFactor = 0; + release.DownloadVolumeFactor = 0; else release.DownloadVolumeFactor = 1; release.UploadVolumeFactor = 1; releases.Add(release); - } - } - catch (Exception ex) - { - OnParseError(results.Content, ex); - } + } + } + catch (Exception ex) + { + OnParseError(results.Content, ex); + } - return releases; - } - public class NxtGnConfigurationData : ConfigurationData - { - public NxtGnConfigurationData() - { - Username = new StringItem { Name = "Username" }; - Password = new StringItem { Name = "Password" }; - } - public StringItem Username { get; private set; } - public StringItem Password { get; private set; } - } - } + return releases; + } + public class NxtGnConfigurationData : ConfigurationData + { + public NxtGnConfigurationData() + { + Username = new StringItem { Name = "Username" }; + Password = new StringItem { Name = "Password" }; + } + public StringItem Username { get; private set; } + public StringItem Password { get; private set; } + } + } } diff --git a/src/Jackett/Indexers/HouseOfTorrents.cs b/src/Jackett/Indexers/HouseOfTorrents.cs index 861622e7c..4e76fd8fa 100644 --- a/src/Jackett/Indexers/HouseOfTorrents.cs +++ b/src/Jackett/Indexers/HouseOfTorrents.cs @@ -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/", diff --git a/src/Jackett/Indexers/PassThePopcorn.cs b/src/Jackett/Indexers/PassThePopcorn.cs index 4b7567927..a4152d28e 100644 --- a/src/Jackett/Indexers/PassThePopcorn.cs +++ b/src/Jackett/Indexers/PassThePopcorn.cs @@ -22,14 +22,14 @@ namespace Jackett.Indexers private string indexUrl { get { return "https://passthepopcorn.me/ajax.php?action=login"; } } private string SearchUrl { get { return "https://passthepopcorn.me/torrents.php"; } } private string DetailURL { get { return "https://passthepopcorn.me/torrents.php?torrentid="; } } - private string AuthKey { get; set; } + private string AuthKey { get; set; } new ConfigurationDataBasicLoginWithFilterAndPasskey configData { get { return (ConfigurationDataBasicLoginWithFilterAndPasskey)base.configData; } 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/", @@ -91,7 +91,7 @@ namespace Jackett.Indexers // Landing page wil have "Result":"Error" if log in fails string errorMessage = (string)js_response["Message"]; throw new ExceptionWithConfigData(errorMessage, configData); - }); + }); } protected override async Task> PerformQuery(TorznabQuery query) @@ -108,7 +108,7 @@ namespace Jackett.Indexers { movieListSearchUrl = string.Format("{0}?json=noredirect&searchstr={1}", SearchUrl, HttpUtility.UrlEncode(query.ImdbID)); } - else if(!string.IsNullOrEmpty(query.GetQueryString())) + else if (!string.IsNullOrEmpty(query.GetQueryString())) { movieListSearchUrl = string.Format("{0}?json=noredirect&searchstr={1}", SearchUrl, HttpUtility.UrlEncode(query.GetQueryString())); } @@ -132,7 +132,7 @@ namespace Jackett.Indexers if (!string.IsNullOrEmpty(coverStr)) coverUri = new Uri(coverStr); long? movie_imdbid = null; - if(!string.IsNullOrEmpty(movie_imdbid_str)) + if (!string.IsNullOrEmpty(movie_imdbid_str)) movie_imdbid = long.Parse(movie_imdbid_str); string movie_groupid = (string)movie["GroupId"]; foreach (var torrent in movie["Torrents"]) @@ -149,9 +149,9 @@ namespace Jackett.Indexers release.Grabs = long.Parse((string)torrent["Snatched"]); release.Seeders = int.Parse((string)torrent["Seeders"]); release.Peers = release.Seeders + int.Parse((string)torrent["Leechers"]); - release.PublishDate = DateTime.ParseExact((string)torrent["UploadTime"], "yyyy-MM-dd HH:mm:ss", + release.PublishDate = DateTime.ParseExact((string)torrent["UploadTime"], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); - release.Link = new Uri(string.Format("{0}?action=download&id={1}&authkey={2}&torrent_pass={3}", + release.Link = new Uri(string.Format("{0}?action=download&id={1}&authkey={2}&torrent_pass={3}", SearchUrl, HttpUtility.UrlEncode((string)torrent["Id"]), HttpUtility.UrlEncode(AuthKey), HttpUtility.UrlEncode(configData.Passkey.Value))); release.MinimumRatio = 1; release.MinimumSeedTime = 345600; diff --git a/src/Jackett/Indexers/PirateTheNet.cs b/src/Jackett/Indexers/PirateTheNet.cs index 5237d040a..7397d6ca1 100644 --- a/src/Jackett/Indexers/PirateTheNet.cs +++ b/src/Jackett/Indexers/PirateTheNet.cs @@ -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/", diff --git a/src/Jackett/Indexers/RevolutionTT.cs b/src/Jackett/Indexers/RevolutionTT.cs index 18de3a60e..440c6c7ad 100644 --- a/src/Jackett/Indexers/RevolutionTT.cs +++ b/src/Jackett/Indexers/RevolutionTT.cs @@ -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/", diff --git a/src/Jackett/Indexers/SceneTime.cs b/src/Jackett/Indexers/SceneTime.cs index f1584e369..5e156c8b9 100644 --- a/src/Jackett/Indexers/SceneTime.cs +++ b/src/Jackett/Indexers/SceneTime.cs @@ -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/", diff --git a/src/Jackett/Indexers/ShowRSS.cs b/src/Jackett/Indexers/ShowRSS.cs index 72928bc09..d7a1da162 100644 --- a/src/Jackett/Indexers/ShowRSS.cs +++ b/src/Jackett/Indexers/ShowRSS.cs @@ -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/", diff --git a/src/Jackett/Indexers/SpeedCD.cs b/src/Jackett/Indexers/SpeedCD.cs index ed69bddb2..d19798ec4 100644 --- a/src/Jackett/Indexers/SpeedCD.cs +++ b/src/Jackett/Indexers/SpeedCD.cs @@ -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/", diff --git a/src/Jackett/Indexers/Superbits.cs b/src/Jackett/Indexers/Superbits.cs index 72a4a6b51..595681736 100644 --- a/src/Jackett/Indexers/Superbits.cs +++ b/src/Jackett/Indexers/Superbits.cs @@ -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/", diff --git a/src/Jackett/Indexers/T411.cs b/src/Jackett/Indexers/T411.cs index e46c240b1..c2ed8bfc6 100644 --- a/src/Jackett/Indexers/T411.cs +++ b/src/Jackett/Indexers/T411.cs @@ -32,7 +32,7 @@ namespace Jackett.Indexers private Dictionary> _mediaCategoryMapping = new Dictionary>(); - 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/", diff --git a/src/Jackett/Indexers/TehConnection.cs b/src/Jackett/Indexers/TehConnection.cs index f6505eb2f..779f56cba 100644 --- a/src/Jackett/Indexers/TehConnection.cs +++ b/src/Jackett/Indexers/TehConnection.cs @@ -21,14 +21,14 @@ namespace Jackett.Indexers private string LoginUrl { get { return SiteLink + "login.php"; } } private string indexUrl { get { return SiteLink + "index.php"; } } private string SearchUrl { get { return SiteLink + "torrents.php"; } } - + new ConfigurationDataBasicLoginWithFilter configData { get { return (ConfigurationDataBasicLoginWithFilter)base.configData; } 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/", @@ -111,7 +111,7 @@ namespace Jackett.Indexers { movieListSearchUrl = string.Format("{0}?action=basic&searchstr={1}", SearchUrl, HttpUtility.UrlEncode(query.ImdbID)); } - else if(!string.IsNullOrEmpty(query.GetQueryString())) + else if (!string.IsNullOrEmpty(query.GetQueryString())) { movieListSearchUrl = string.Format("{0}?action=basic&searchstr={1}", SearchUrl, HttpUtility.UrlEncode(query.GetQueryString())); } @@ -155,7 +155,7 @@ namespace Jackett.Indexers { var release = new ReleaseInfo(); var qRow = row.Cq(); - + string title = qRow.Find("[id^=desc_] > h2 > strong").First().Text().Trim(); Uri link = new Uri(SiteLink.TrimEnd('/') + qRow.Find("a[title='Download']").First().Attr("href").Trim()); Uri guid = new Uri(SiteLink.TrimEnd('/') + qRow.Find("a[title='Permalink']").First().Attr("href").Trim()); @@ -170,7 +170,7 @@ namespace Jackett.Indexers Uri CoverUrl = new Uri(dom.Find("div[id='poster'] > a > img").First().Attr("src").Trim()); release.BannerUrl = CoverUrl; } - + bool freeleech = qRow.Find("span[class='freeleech']").Length == 1 ? true : false; bool qualityEncode = qRow.Find("img[class='approved']").Length == 1 ? true : false; string grabs = qRow.Find("img[title='Snatches']").First().Parent().Text().Trim(); @@ -181,11 +181,11 @@ namespace Jackett.Indexers { sizeStr = secondSizeStr.Replace("(", "").Replace(")", "").Trim(); } } - if(string.IsNullOrWhiteSpace(title)) + if (string.IsNullOrWhiteSpace(title)) { title = dom.Find("div.title_text").Text() + " - " + qRow.Find("div.details_title > a").Text(); } - + release.Title = title; release.Guid = guid; @@ -199,11 +199,12 @@ namespace Jackett.Indexers release.MinimumSeedTime = 345600; release.Category = new List { 2000 }; release.Comments = movieReleasesLink; - if (imdb_id > 0) { + if (imdb_id > 0) + { release.Imdb = imdb_id; } - var files = qRow.Find("div[id^=\"filelist\"] tr").Count()-1; + var files = qRow.Find("div[id^=\"filelist\"] tr").Count() - 1; release.Files = files; release.Grabs = ParseUtil.CoerceLong(grabs); diff --git a/src/Jackett/Indexers/TorrentDay.cs b/src/Jackett/Indexers/TorrentDay.cs index e819aeee8..c8801472a 100644 --- a/src/Jackett/Indexers/TorrentDay.cs +++ b/src/Jackett/Indexers/TorrentDay.cs @@ -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/", diff --git a/src/Jackett/Indexers/TorrentLeech.cs b/src/Jackett/Indexers/TorrentLeech.cs index db2341114..16014dabc 100644 --- a/src/Jackett/Indexers/TorrentLeech.cs +++ b/src/Jackett/Indexers/TorrentLeech.cs @@ -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/", diff --git a/src/Jackett/Indexers/TorrentSyndikat.cs b/src/Jackett/Indexers/TorrentSyndikat.cs index 902542255..2f4f04c91 100644 --- a/src/Jackett/Indexers/TorrentSyndikat.cs +++ b/src/Jackett/Indexers/TorrentSyndikat.cs @@ -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/", diff --git a/src/Jackett/Indexers/TransmitheNet.cs b/src/Jackett/Indexers/TransmitheNet.cs index fa25954d9..b7f4347d1 100644 --- a/src/Jackett/Indexers/TransmitheNet.cs +++ b/src/Jackett/Indexers/TransmitheNet.cs @@ -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/", diff --git a/src/Jackett/Indexers/x264.cs b/src/Jackett/Indexers/x264.cs index 8c8003755..3408ca829 100644 --- a/src/Jackett/Indexers/x264.cs +++ b/src/Jackett/Indexers/x264.cs @@ -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/", diff --git a/src/Jackett/JackettModule.cs b/src/Jackett/JackettModule.cs index 31d8cc9b0..5174f56ed 100644 --- a/src/Jackett/JackettModule.cs +++ b/src/Jackett/JackettModule.cs @@ -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(BaseIndexer.GetIndexerID(indexer)); - } - Mapper.CreateMap().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((be, str) => { str.Content = Encoding.UTF8.GetString(be.Content); diff --git a/src/Jackett/Services/IndexerManagerService.cs b/src/Jackett/Services/IndexerManagerService.cs index 7e39b72e6..21be9200e 100644 --- a/src/Jackett/Services/IndexerManagerService.cs +++ b/src/Jackett/Services/IndexerManagerService.cs @@ -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 GetAllIndexers(); - void InitIndexers(); - void InitCardigannIndexers(string path); + void InitIndexers(IEnumerable path); void InitAggregateIndexer(); - void SortIndexers(); } public class IndexerManagerService : IIndexerManagerService { - private IContainer container; - private Logger logger; - private Dictionary indexers = new Dictionary(); private ICacheService cacheService; private IIndexerConfigurationService configService; + private IProtectionService protectionService; + private IWebClient webClient; + + private Logger logger; + + private Dictionary indexers = new Dictionary(); 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 path) { - logger.Info("Using HTTP Client: " + container.Resolve().GetType().Name); + InitIndexers(); + InitCardigannIndexers(path); + InitAggregateIndexer(); + } - foreach (var idx in container.Resolve>().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 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() + 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(DefinitionString); - CardigannIndexer idx = new CardigannIndexer(configService, container.Resolve(), logger, container.Resolve(), definition); - if (indexers.ContainsKey(idx.ID)) + return definition; + }); + var cardigannIndexers = definitions.Select(definition => + { + 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) + { + if (indexers.ContainsKey(indexer.ID)) { - logger.Debug(string.Format("Ignoring definition ID={0}, file={1}: Indexer already exists", idx.ID, file.FullName)); - } - else - { - indexers.Add(idx.ID, idx); - configService.Load(idx); + 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().Config.OmdbApiKey; + var omdbApiKey = Engine.Server.Config.OmdbApiKey; IFallbackStrategyProvider fallbackStrategyProvider = null; IResultFilterProvider resultFilterProvider = null; if (omdbApiKey != null) { - var imdbResolver = new OmdbResolver(container.Resolve(), 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(), logger, container.Resolve()); + aggregateIndexer = new AggregateIndexer(fallbackStrategyProvider, resultFilterProvider, configService, webClient, logger, protectionService); aggregateIndexer.Indexers = indexers.Values; } @@ -147,7 +187,7 @@ namespace Jackett.Services public IEnumerable 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 newIndexers = new Dictionary(); - foreach (var indexer in indexers.OrderBy(_ => _.Value.DisplayName)) - newIndexers.Add(indexer.Key, indexer.Value); - indexers = newIndexers; - } } } diff --git a/src/Jackett/Services/ProtectionService.cs b/src/Jackett/Services/ProtectionService.cs index a97e08481..af5738892 100644 --- a/src/Jackett/Services/ProtectionService.cs +++ b/src/Jackett/Services/ProtectionService.cs @@ -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()) { @@ -155,12 +155,12 @@ namespace Jackett.Services { var type = obj.GetType(); - foreach(var property in type.GetProperties(BindingFlags.SetProperty |BindingFlags.GetProperty | BindingFlags.Public)) + foreach (var property in type.GetProperties(BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.Public)) { - if(property.GetCustomAttributes(typeof(JackettProtectedAttribute), false).Count() > 0) + if (property.GetCustomAttributes(typeof(JackettProtectedAttribute), false).Count() > 0) { var value = property.GetValue(obj); - if(value is string) + if (value is string) { var protectedString = Protect(value as string); property.SetValue(obj, protectedString); diff --git a/src/Jackett/Services/ServerService.cs b/src/Jackett/Services/ServerService.cs index 034db7f82..3a6837481 100644 --- a/src/Jackett/Services/ServerService.cs +++ b/src/Jackett/Services/ServerService.cs @@ -57,7 +57,7 @@ namespace Jackett.Services private IUpdateService updater; private List _notices = new List(); - 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(); }