mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Cardigann: make download method configurable
This commit is contained in:
@@ -334,13 +334,18 @@ namespace Jackett.Indexers
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async virtual Task<byte[]> Download(Uri link)
|
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
|
// do some extra escaping, needed for HD-Torrents
|
||||||
var requestLink = link.ToString()
|
var requestLink = link.ToString()
|
||||||
.Replace("(", "%28")
|
.Replace("(", "%28")
|
||||||
.Replace(")", "%29")
|
.Replace(")", "%29")
|
||||||
.Replace("'", "%27");
|
.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)
|
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);
|
logger.Error("Failed download cookies: " + this.CookieHeader);
|
||||||
@@ -352,14 +357,14 @@ namespace Jackett.Indexers
|
|||||||
return response.Content;
|
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;
|
Exception lastException = null;
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await RequestBytesWithCookies(url, cookieOverride);
|
return await RequestBytesWithCookies(url, cookieOverride, method);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -411,12 +416,12 @@ namespace Jackett.Indexers
|
|||||||
throw lastException;
|
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()
|
var request = new Utils.Clients.WebRequest()
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url,
|
||||||
Type = RequestType.GET,
|
Type = method,
|
||||||
Cookies = cookieOverride ?? CookieHeader,
|
Cookies = cookieOverride ?? CookieHeader,
|
||||||
Encoding = Encoding
|
Encoding = Encoding
|
||||||
};
|
};
|
||||||
|
@@ -136,6 +136,7 @@ namespace Jackett.Indexers
|
|||||||
public class downloadBlock
|
public class downloadBlock
|
||||||
{
|
{
|
||||||
public string Selector { get; set; }
|
public string Selector { get; set; }
|
||||||
|
public string Method { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly string[] OptionalFileds = new string[] { "imdb", "rageid", "tvdbid", "banner" };
|
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)
|
public override async Task<byte[]> Download(Uri link)
|
||||||
{
|
{
|
||||||
if(Definition.Download != null)
|
var method = RequestType.GET;
|
||||||
|
if (Definition.Download != null)
|
||||||
{
|
{
|
||||||
var Download = Definition.Download;
|
var Download = Definition.Download;
|
||||||
|
if (Download.Method != null)
|
||||||
|
{
|
||||||
|
if (Download.Method == "post")
|
||||||
|
method = RequestType.POST;
|
||||||
|
}
|
||||||
if (Download.Selector != null)
|
if (Download.Selector != null)
|
||||||
{
|
{
|
||||||
var response = await RequestStringWithCookies(link.ToString());
|
var response = await RequestStringWithCookies(link.ToString());
|
||||||
@@ -1138,7 +1145,7 @@ namespace Jackett.Indexers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await base.Download(link);
|
return await base.Download(link, method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user