From 03ab411d688ce92a5a66dd7a119ef2ef5e2f23fa Mon Sep 17 00:00:00 2001 From: kaso17 Date: Tue, 3 Jan 2017 13:19:23 +0100 Subject: [PATCH] Cardigann: make download method configurable --- src/Jackett/Indexers/BaseIndexer.cs | 15 ++++++++++----- src/Jackett/Indexers/CardigannIndexer.cs | 11 +++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Jackett/Indexers/BaseIndexer.cs b/src/Jackett/Indexers/BaseIndexer.cs index 38091a091..094b9f328 100644 --- a/src/Jackett/Indexers/BaseIndexer.cs +++ b/src/Jackett/Indexers/BaseIndexer.cs @@ -334,13 +334,18 @@ namespace Jackett.Indexers } public async virtual Task Download(Uri link) + { + return await Download(link, RequestType.GET); + } + + public async virtual Task Download(Uri link, RequestType method = RequestType.GET) { // do some extra escaping, needed for HD-Torrents var requestLink = link.ToString() .Replace("(", "%28") .Replace(")", "%29") .Replace("'", "%27"); - var response = await RequestBytesWithCookiesAndRetry(requestLink); + var response = await RequestBytesWithCookiesAndRetry(requestLink, null, method); if (response.Status != System.Net.HttpStatusCode.OK && response.Status != System.Net.HttpStatusCode.Continue && response.Status != System.Net.HttpStatusCode.PartialContent) { logger.Error("Failed download cookies: " + this.CookieHeader); @@ -352,14 +357,14 @@ namespace Jackett.Indexers return response.Content; } - protected async Task RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null) + protected async Task RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET) { Exception lastException = null; for (int i = 0; i < 3; i++) { try { - return await RequestBytesWithCookies(url, cookieOverride); + return await RequestBytesWithCookies(url, cookieOverride, method); } catch (Exception e) { @@ -411,12 +416,12 @@ namespace Jackett.Indexers throw lastException; } - protected async Task RequestBytesWithCookies(string url, string cookieOverride = null) + protected async Task RequestBytesWithCookies(string url, string cookieOverride = null, RequestType method = RequestType.GET) { var request = new Utils.Clients.WebRequest() { Url = url, - Type = RequestType.GET, + Type = method, Cookies = cookieOverride ?? CookieHeader, Encoding = Encoding }; diff --git a/src/Jackett/Indexers/CardigannIndexer.cs b/src/Jackett/Indexers/CardigannIndexer.cs index d62cd6e49..afd98d306 100644 --- a/src/Jackett/Indexers/CardigannIndexer.cs +++ b/src/Jackett/Indexers/CardigannIndexer.cs @@ -136,6 +136,7 @@ namespace Jackett.Indexers public class downloadBlock { public string Selector { get; set; } + public string Method { get; set; } } protected readonly string[] OptionalFileds = new string[] { "imdb", "rageid", "tvdbid", "banner" }; @@ -1115,9 +1116,15 @@ namespace Jackett.Indexers public override async Task Download(Uri link) { - if(Definition.Download != null) + var method = RequestType.GET; + if (Definition.Download != null) { var Download = Definition.Download; + if (Download.Method != null) + { + if (Download.Method == "post") + method = RequestType.POST; + } if (Download.Selector != null) { var response = await RequestStringWithCookies(link.ToString()); @@ -1138,7 +1145,7 @@ namespace Jackett.Indexers } } } - return await base.Download(link); + return await base.Download(link, method); } } }