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.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
using Jackett.Common.Models;
@@ -17,8 +17,6 @@ namespace Jackett.Common.Indexers
{
public class SpeedCD : BaseWebIndexer
{
private string LoginUrl1 => SiteLink + "checkpoint/API";
private string LoginUrl2 => SiteLink + "checkpoint/";
private string SearchUrl => SiteLink + "browse.php";
public override string[] AlternativeSiteLinks { get; protected set; } = {
@@ -26,23 +24,23 @@ namespace Jackett.Common.Indexers
"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)
: base("Speed.cd",
description: "Your home now!",
link: "https://speed.cd/",
caps: new TorznabCapabilities
{
SupportsImdbMovieSearch = true
// SupportsImdbTVSearch = true (supported by the site but disabled due to #8107)
},
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLogin(
@"Speed.Cd have increased their security. If you are having problems please check the security tab
description: "Your home now!",
link: "https://speed.cd/",
caps: new TorznabCapabilities
{
SupportsImdbMovieSearch = true
// SupportsImdbTVSearch = true (supported by the site but disabled due to #8107)
},
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataCookie(
@"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
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)
{
LoadValuesFromJson(configJson);
await DoLogin();
return IndexerConfigurationStatus.RequiresTesting;
}
private async Task DoLogin()
{
// first request with username
var pairs = new Dictionary<string, string> {
{ "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, () =>
CookieHeader = configData.Cookie.Value;
try
{
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);
});
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)
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
@@ -140,11 +120,9 @@ namespace Jackett.Common.Indexers
var searchUrl = SearchUrl + "?" + qc.GetQueryString();
var response = await RequestStringWithCookiesAndRetry(searchUrl);
if (!response.Content.Contains("/logout.php")) // re-login
{
await DoLogin();
response = await RequestStringWithCookiesAndRetry(searchUrl);
}
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 " +
"made a mistake when copying it. Please check the settings.");
try
{