speedcd: cookie login. resolves #8366 (#8372)

They changed the login form again. Now it's more complex to solve because they have several steps, reCaptcha and Google cookie.
This commit is contained in:
Diego Heras
2020-04-26 20:09:11 +02:00
committed by GitHub
parent 0e007909e7
commit d9b19719e4

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using AngleSharp.Html.Parser; using AngleSharp.Html.Parser;
using Jackett.Common.Models; using Jackett.Common.Models;
@@ -17,8 +17,6 @@ namespace Jackett.Common.Indexers
{ {
public class SpeedCD : BaseWebIndexer public class SpeedCD : BaseWebIndexer
{ {
private string LoginUrl1 => SiteLink + "checkpoint/API";
private string LoginUrl2 => SiteLink + "checkpoint/";
private string SearchUrl => SiteLink + "browse.php"; private string SearchUrl => SiteLink + "browse.php";
public override string[] AlternativeSiteLinks { get; protected set; } = { public override string[] AlternativeSiteLinks { get; protected set; } = {
@@ -26,7 +24,7 @@ namespace Jackett.Common.Indexers
"https://speed.click/" "https://speed.click/"
}; };
private new ConfigurationDataBasicLogin configData => (ConfigurationDataBasicLogin)base.configData; private new ConfigurationDataCookie configData => (ConfigurationDataCookie)base.configData;
public SpeedCD(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps) public SpeedCD(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base("Speed.cd", : base("Speed.cd",
@@ -41,7 +39,7 @@ namespace Jackett.Common.Indexers
client: wc, client: wc,
logger: l, logger: l,
p: ps, p: ps,
configData: new ConfigurationDataBasicLogin( configData: new ConfigurationDataCookie(
@"Speed.Cd have increased their security. If you are having problems please check the security tab @"Speed.Cd have increased their security. If you are having problems please check the security tab
in your Speed.Cd profile. Eg. Geo Locking, your seedbox may be in a different country to the one where you login via your in your Speed.Cd profile. Eg. Geo Locking, your seedbox may be in a different country to the one where you login via your
web browser.<br><br>For best results, change the 'Torrents per page' setting to 100 in 'Profile Settings > Torrents'.")) web browser.<br><br>For best results, change the 'Torrents per page' setting to 100 in 'Profile Settings > Torrents'."))
@@ -86,39 +84,21 @@ namespace Jackett.Common.Indexers
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{ {
LoadValuesFromJson(configJson); LoadValuesFromJson(configJson);
await DoLogin(); CookieHeader = configData.Cookie.Value;
return IndexerConfigurationStatus.RequiresTesting; try
{
var results = await PerformQuery(new TorznabQuery());
if (!results.Any())
throw new Exception("Found 0 results in the tracker");
IsConfigured = true;
SaveConfig();
return IndexerConfigurationStatus.Completed;
} }
catch (Exception e)
private async Task DoLogin()
{ {
// first request with username IsConfigured = false;
var pairs = new Dictionary<string, string> { throw new Exception("Your cookie did not work: " + e.Message);
{ "username", configData.Username.Value } }
};
var result = await RequestLoginAndFollowRedirect(LoginUrl1, pairs, null, true, null, SiteLink);
var tokenRegex = new Regex(@"name=\\""a\\"" value=\\""([^""]+)\\""");
var matches = tokenRegex.Match(result.Content);
if (!matches.Success)
throw new ExceptionWithConfigData("Error parsing the login form", configData);
var token = matches.Groups[1].Value;
// second request with token and password
pairs = new Dictionary<string, string> {
{ "a", token },
{ "b", configData.Password.Value },
};
result = await RequestLoginAndFollowRedirect(LoginUrl2, pairs, result.Cookies, true, null, SiteLink);
await ConfigureIfOK(result.Cookies, result.Content?.Contains("/browse.php") == true, () =>
{
var parser = new HtmlParser();
var dom = parser.ParseDocument(result.Content);
var errorMessage = dom.QuerySelector("h5")?.TextContent;
if (result.Content.Contains("Wrong Captcha!"))
errorMessage = "Captcha required due to a failed login attempt. Login via a browser to whitelist your IP and then reconfigure Jackett.";
throw new ExceptionWithConfigData(errorMessage, configData);
});
} }
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
@@ -140,11 +120,9 @@ namespace Jackett.Common.Indexers
var searchUrl = SearchUrl + "?" + qc.GetQueryString(); var searchUrl = SearchUrl + "?" + qc.GetQueryString();
var response = await RequestStringWithCookiesAndRetry(searchUrl); var response = await RequestStringWithCookiesAndRetry(searchUrl);
if (!response.Content.Contains("/logout.php")) // re-login if (!response.Content.Contains("/logout.php"))
{ throw new Exception("The user is not logged in. It is possible that the cookie has expired or you " +
await DoLogin(); "made a mistake when copying it. Please check the settings.");
response = await RequestStringWithCookiesAndRetry(searchUrl);
}
try try
{ {