mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Merge pull request #106 from zone117x/develop
Fix SCC not saving and AlphaRatio
This commit is contained in:
@@ -48,6 +48,12 @@ namespace Jackett.Controllers
|
|||||||
return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key");
|
return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!indexer.IsConfigured)
|
||||||
|
{
|
||||||
|
logger.Warn(string.Format("Rejected a request to {0} which is unconfigured.", indexer.DisplayName));
|
||||||
|
return Request.CreateResponse(HttpStatusCode.Forbidden, "This indexer is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
var releases = await indexer.PerformQuery(torznabQuery);
|
var releases = await indexer.PerformQuery(torznabQuery);
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(torznabQuery.SanitizedSearchTerm))
|
if (string.IsNullOrWhiteSpace(torznabQuery.SanitizedSearchTerm))
|
||||||
|
@@ -31,6 +31,13 @@ namespace Jackett.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var indexer = indexerService.GetIndexer(indexerID);
|
var indexer = indexerService.GetIndexer(indexerID);
|
||||||
|
|
||||||
|
if (!indexer.IsConfigured)
|
||||||
|
{
|
||||||
|
logger.Warn(string.Format("Rejected a request to {0} which is unconfigured.", indexer.DisplayName));
|
||||||
|
return Request.CreateResponse(HttpStatusCode.Forbidden, "This indexer is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
var remoteFile = Encoding.UTF8.GetString(HttpServerUtility.UrlTokenDecode(path));
|
var remoteFile = Encoding.UTF8.GetString(HttpServerUtility.UrlTokenDecode(path));
|
||||||
var downloadBytes = await indexer.Download(new Uri(remoteFile));
|
var downloadBytes = await indexer.Download(new Uri(remoteFile));
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ using Jackett.Models;
|
|||||||
using Jackett.Utils;
|
using Jackett.Utils;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Jackett.Services;
|
using Jackett.Services;
|
||||||
|
using Jackett.Utils.Clients;
|
||||||
|
|
||||||
namespace Jackett.Indexers
|
namespace Jackett.Indexers
|
||||||
{
|
{
|
||||||
@@ -23,13 +24,10 @@ namespace Jackett.Indexers
|
|||||||
private readonly string DownloadUrl = "";
|
private readonly string DownloadUrl = "";
|
||||||
private readonly string GuidUrl = "";
|
private readonly string GuidUrl = "";
|
||||||
|
|
||||||
CookieContainer cookies;
|
private IWebClient webclient;
|
||||||
HttpClientHandler handler;
|
private string cookieHeader = "";
|
||||||
HttpClient client;
|
|
||||||
|
|
||||||
string cookieHeader;
|
public AlphaRatio(IIndexerManagerService i, IWebClient w, Logger l)
|
||||||
|
|
||||||
public AlphaRatio(IIndexerManagerService i, Logger l)
|
|
||||||
: base(name: "AlphaRatio",
|
: base(name: "AlphaRatio",
|
||||||
description: "Legendary",
|
description: "Legendary",
|
||||||
link: new Uri("https://alpharatio.cc"),
|
link: new Uri("https://alpharatio.cc"),
|
||||||
@@ -41,16 +39,7 @@ namespace Jackett.Indexers
|
|||||||
SearchUrl = SiteLink + "ajax.php?action=browse&searchstr=";
|
SearchUrl = SiteLink + "ajax.php?action=browse&searchstr=";
|
||||||
DownloadUrl = SiteLink + "torrents.php?action=download&id=";
|
DownloadUrl = SiteLink + "torrents.php?action=download&id=";
|
||||||
GuidUrl = SiteLink + "torrents.php?torrentid=";
|
GuidUrl = SiteLink + "torrents.php?torrentid=";
|
||||||
|
webclient = w;
|
||||||
cookies = new CookieContainer();
|
|
||||||
handler = new HttpClientHandler
|
|
||||||
{
|
|
||||||
CookieContainer = cookies,
|
|
||||||
AllowAutoRedirect = true,
|
|
||||||
UseCookies = true,
|
|
||||||
|
|
||||||
};
|
|
||||||
client = new HttpClient(handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||||
@@ -61,53 +50,48 @@ namespace Jackett.Indexers
|
|||||||
|
|
||||||
public async Task ApplyConfiguration(JToken configJson)
|
public async Task ApplyConfiguration(JToken configJson)
|
||||||
{
|
{
|
||||||
var configSaveData = new JObject();
|
var incomingConfig = new ConfigurationDataBasicLogin();
|
||||||
SaveConfig(configSaveData);
|
incomingConfig.LoadValuesFromJson(configJson);
|
||||||
|
|
||||||
var config = new ConfigurationDataBasicLogin();
|
|
||||||
config.LoadValuesFromJson(configJson);
|
|
||||||
|
|
||||||
var pairs = new Dictionary<string, string> {
|
var pairs = new Dictionary<string, string> {
|
||||||
{ "username", config.Username.Value },
|
{ "username", incomingConfig.Username.Value },
|
||||||
{ "password", @config.Password.Value },
|
{ "password", incomingConfig.Password.Value },
|
||||||
{ "login", "Login" },
|
{ "login", "Login" },
|
||||||
{ "keeplogged", "1" }
|
{ "keeplogged", "1" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var content = new FormUrlEncodedContent(pairs);
|
// Do the login
|
||||||
var message = CreateHttpRequest(new Uri(LoginUrl));
|
var response = await webclient.GetString(new Utils.Clients.WebRequest()
|
||||||
message.Content = content;
|
|
||||||
|
|
||||||
//message.Headers.Referrer = new Uri(LoginUrl);
|
|
||||||
string responseContent;
|
|
||||||
|
|
||||||
configSaveData = new JObject();
|
|
||||||
|
|
||||||
if (Engine.IsWindows)
|
|
||||||
{
|
{
|
||||||
// If Windows use .net http
|
PostData = pairs,
|
||||||
var response = await client.SendAsync(message);
|
Referer = LoginUrl,
|
||||||
responseContent = await response.Content.ReadAsStringAsync();
|
Type = RequestType.POST,
|
||||||
cookies.DumpToJson(SiteLink, configSaveData);
|
Url = LoginUrl
|
||||||
}
|
});
|
||||||
else
|
|
||||||
|
cookieHeader = response.Cookies;
|
||||||
|
|
||||||
|
if (response.Status == HttpStatusCode.Found || response.Status == HttpStatusCode.Redirect || response.Status == HttpStatusCode.RedirectMethod)
|
||||||
{
|
{
|
||||||
// If UNIX system use curl, probably broken due to missing chromeUseragent record for CURL...cannot test
|
response = await webclient.GetString(new Utils.Clients.WebRequest()
|
||||||
var response = await CurlHelper.PostAsync(LoginUrl, pairs);
|
{
|
||||||
responseContent = Encoding.UTF8.GetString(response.Content);
|
Url = SiteLink.ToString(),
|
||||||
cookieHeader = response.CookieHeader;
|
Referer = LoginUrl.ToString(),
|
||||||
configSaveData["cookie_header"] = cookieHeader;
|
Cookies = cookieHeader
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!responseContent.Contains("logout.php?"))
|
if (!response.Content.Contains("logout.php?"))
|
||||||
{
|
{
|
||||||
CQ dom = responseContent;
|
CQ dom = response.Content;
|
||||||
dom["#loginform > table"].Remove();
|
dom["#loginform > table"].Remove();
|
||||||
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
|
var errorMessage = dom["#loginform"].Text().Trim().Replace("\n\t", " ");
|
||||||
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)config);
|
throw new ExceptionWithConfigData(errorMessage, (ConfigurationData)incomingConfig);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var configSaveData = new JObject();
|
||||||
|
configSaveData["cookie_header"] = cookieHeader;
|
||||||
SaveConfig(configSaveData);
|
SaveConfig(configSaveData);
|
||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
@@ -124,10 +108,12 @@ namespace Jackett.Indexers
|
|||||||
|
|
||||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||||
{
|
{
|
||||||
cookies.FillFromJson(SiteLink, jsonConfig, logger);
|
cookieHeader = (string)jsonConfig["cookie_header"];
|
||||||
cookieHeader = cookies.GetCookieHeader(SiteLink);
|
if (!string.IsNullOrEmpty(cookieHeader))
|
||||||
|
{
|
||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)
|
void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)
|
||||||
{
|
{
|
||||||
@@ -146,23 +132,18 @@ namespace Jackett.Indexers
|
|||||||
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
|
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
|
||||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
||||||
|
|
||||||
string results;
|
var results = await webclient.GetString(new Utils.Clients.WebRequest()
|
||||||
if (Engine.IsWindows)
|
|
||||||
{
|
{
|
||||||
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
|
Cookies = cookieHeader,
|
||||||
request.Method = HttpMethod.Get;
|
Type = RequestType.GET,
|
||||||
var response = await client.SendAsync(request);
|
Url = episodeSearchUrl
|
||||||
results = await response.Content.ReadAsStringAsync();
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var response = await CurlHelper.GetAsync(episodeSearchUrl, cookieHeader);
|
|
||||||
results = Encoding.UTF8.GetString(response.Content);
|
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var json = JObject.Parse(results);
|
var json = JObject.Parse(results.Content);
|
||||||
foreach (JObject r in json["response"]["results"])
|
foreach (JObject r in json["response"]["results"])
|
||||||
{
|
{
|
||||||
DateTime pubDate = DateTime.MinValue;
|
DateTime pubDate = DateTime.MinValue;
|
||||||
@@ -198,7 +179,7 @@ namespace Jackett.Indexers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OnParseError(results, ex);
|
OnParseError(results.Content, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return releases.ToArray();
|
return releases.ToArray();
|
||||||
@@ -213,17 +194,14 @@ namespace Jackett.Indexers
|
|||||||
|
|
||||||
public async Task<byte[]> Download(Uri link)
|
public async Task<byte[]> Download(Uri link)
|
||||||
{
|
{
|
||||||
if (Engine.IsWindows)
|
var response = await webclient.GetBytes(new Utils.Clients.WebRequest()
|
||||||
{
|
{
|
||||||
return await client.GetByteArrayAsync(link);
|
Url = link.ToString(),
|
||||||
}
|
Cookies = cookieHeader
|
||||||
else
|
});
|
||||||
{
|
|
||||||
var response = await CurlHelper.GetAsync(link.ToString(), cookieHeader);
|
|
||||||
return response.Content;
|
return response.Content;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -86,6 +86,7 @@ namespace Jackett.Indexers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var configSaveData = new JObject();
|
var configSaveData = new JObject();
|
||||||
|
configSaveData["cookie_header"] = cookieHeader;
|
||||||
SaveConfig(configSaveData);
|
SaveConfig(configSaveData);
|
||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
|
@@ -24,17 +24,14 @@ namespace Jackett
|
|||||||
if (Startup.CurlSafe)
|
if (Startup.CurlSafe)
|
||||||
{
|
{
|
||||||
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
|
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
|
||||||
Console.WriteLine("Using UnixSafeCurlWebClient");
|
|
||||||
}
|
}
|
||||||
else if(System.Environment.OSVersion.Platform == PlatformID.Unix)
|
else if(System.Environment.OSVersion.Platform == PlatformID.Unix)
|
||||||
{
|
{
|
||||||
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
|
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
|
||||||
Console.WriteLine("Using UnixLibCurlWebClient");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.RegisterType<WindowsWebClient>().As<IWebClient>();
|
builder.RegisterType<WindowsWebClient>().As<IWebClient>();
|
||||||
Console.WriteLine("Using WindowsWebClient");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register indexers
|
// Register indexers
|
||||||
|
Reference in New Issue
Block a user