speedcd: fix login

Fixes #15164
This commit is contained in:
Bogdan
2024-03-28 01:20:46 +02:00
parent 78b181eb60
commit 5450be31d0

View File

@@ -37,8 +37,6 @@ namespace Jackett.Common.Indexers
public override TorznabCapabilities TorznabCaps => SetCapabilities(); public override TorznabCapabilities TorznabCaps => SetCapabilities();
private string LoginUrl1 => SiteLink + "login";
private string LoginUrl2 => SiteLink + "login/API";
private string SearchUrl => SiteLink + "browse/"; private string SearchUrl => SiteLink + "browse/";
private new ConfigurationDataSpeedCD configData => (ConfigurationDataSpeedCD)base.configData; private new ConfigurationDataSpeedCD configData => (ConfigurationDataSpeedCD)base.configData;
@@ -127,24 +125,38 @@ namespace Jackett.Common.Indexers
private async Task DoLogin() private async Task DoLogin()
{ {
// first request with username // first request with username
var pairs = new Dictionary<string, string> var result = await RequestLoginAndFollowRedirect(
{ $"{SiteLink.TrimEnd('/')}/checkpoint/API",
{ "username", configData.Username.Value } new Dictionary<string, string>
}; {
var result = await RequestLoginAndFollowRedirect(LoginUrl1, pairs, null, true, null, SiteLink); { "username", configData.Username.Value }
},
null,
true,
null,
SiteLink);
var tokenRegex = new Regex(@"name=\\""a\\"" value=\\""([^""]+)\\"""); var tokenRegex = new Regex(@"name=\\""a\\"" value=\\""([^""]+)\\""");
var matches = tokenRegex.Match(result.ContentString); var matches = tokenRegex.Match(result.ContentString);
if (!matches.Success) if (!matches.Success)
{
throw new Exception("Error parsing the login form"); throw new Exception("Error parsing the login form");
}
var token = matches.Groups[1].Value; var token = matches.Groups[1].Value;
// second request with token and password // second request with token and password
pairs = new Dictionary<string, string> result = await RequestLoginAndFollowRedirect(
{ $"{SiteLink.TrimEnd('/')}/checkpoint/",
{ "pwd", configData.Password.Value }, new Dictionary<string, string>
{ "a", token } {
}; { "pwd", configData.Password.Value },
result = await RequestLoginAndFollowRedirect(LoginUrl2, pairs, result.Cookies, true, null, SiteLink); { "a", token }
},
result.Cookies,
true,
null,
SiteLink);
await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("/browse.php") == true, () => await ConfigureIfOK(result.Cookies, result.ContentString?.Contains("/browse.php") == true, () =>
{ {
@@ -153,7 +165,9 @@ namespace Jackett.Common.Indexers
var errorMessage = dom.QuerySelector("h5")?.TextContent; var errorMessage = dom.QuerySelector("h5")?.TextContent;
if (result.ContentString.Contains("Wrong Captcha!")) if (result.ContentString.Contains("Wrong Captcha!"))
{
errorMessage = "Captcha required due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure Jackett."; errorMessage = "Captcha required due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure Jackett.";
}
throw new Exception(errorMessage ?? "Login failed."); throw new Exception(errorMessage ?? "Login failed.");
}); });
@@ -168,13 +182,19 @@ namespace Jackett.Common.Indexers
var catList = MapTorznabCapsToTrackers(query); var catList = MapTorznabCapsToTrackers(query);
foreach (var cat in catList) foreach (var cat in catList)
{
qc.Add(cat); qc.Add(cat);
}
if (configData.Freeleech.Value) if (configData.Freeleech.Value)
{
qc.Add("freeleech"); qc.Add("freeleech");
}
if (configData.ExcludeArchives.Value) if (configData.ExcludeArchives.Value)
{
qc.Add("norar"); qc.Add("norar");
}
if (query.IsImdbQuery) if (query.IsImdbQuery)
{ {
@@ -185,7 +205,9 @@ namespace Jackett.Common.Indexers
term += $" {query.GetEpisodeSearchString()}"; term += $" {query.GetEpisodeSearchString()}";
if (query.Season > 0 && string.IsNullOrEmpty(query.Episode)) if (query.Season > 0 && string.IsNullOrEmpty(query.Episode))
{
term += "*"; term += "*";
}
} }
qc.Add("deep"); qc.Add("deep");
@@ -197,7 +219,9 @@ namespace Jackett.Common.Indexers
var term = query.GetQueryString(); var term = query.GetQueryString();
if (!string.IsNullOrWhiteSpace(query.GetEpisodeSearchString()) && query.Season > 0 && string.IsNullOrEmpty(query.Episode)) if (!string.IsNullOrWhiteSpace(query.GetEpisodeSearchString()) && query.Season > 0 && string.IsNullOrEmpty(query.Episode))
{
term += "*"; term += "*";
}
qc.Add("q"); qc.Add("q");
qc.Add(WebUtilityHelpers.UrlEncode(term.Trim(), Encoding)); qc.Add(WebUtilityHelpers.UrlEncode(term.Trim(), Encoding));