Cardigann: make download method configurable

This commit is contained in:
kaso17
2017-01-03 13:19:23 +01:00
parent 20b9b692f0
commit 03ab411d68
2 changed files with 19 additions and 7 deletions

View File

@@ -334,13 +334,18 @@ namespace Jackett.Indexers
}
public async virtual Task<byte[]> Download(Uri link)
{
return await Download(link, RequestType.GET);
}
public async virtual Task<byte[]> 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<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null)
protected async Task<WebClientByteResult> 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<WebClientByteResult> RequestBytesWithCookies(string url, string cookieOverride = null)
protected async Task<WebClientByteResult> 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
};

View File

@@ -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<byte[]> 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);
}
}
}