TorrentLeech: add recaptcha handling

This commit is contained in:
kaso17
2018-04-17 13:55:18 +02:00
parent 9ceeb71448
commit 535f71c18c

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -20,9 +21,9 @@ namespace Jackett.Common.Indexers
private string LoginUrl { get { return SiteLink + "user/account/login/"; } } private string LoginUrl { get { return SiteLink + "user/account/login/"; } }
private string SearchUrl { get { return SiteLink + "torrents/browse/list/"; } } private string SearchUrl { get { return SiteLink + "torrents/browse/list/"; } }
private new ConfigurationDataBasicLogin configData private new ConfigurationDataRecaptchaLogin configData
{ {
get { return (ConfigurationDataBasicLogin)base.configData; } get { return (ConfigurationDataRecaptchaLogin)base.configData; }
set { base.configData = value; } set { base.configData = value; }
} }
@@ -36,7 +37,7 @@ namespace Jackett.Common.Indexers
logger: l, logger: l,
p: ps, p: ps,
downloadBase: "https://www.torrentleech.org/download/", downloadBase: "https://www.torrentleech.org/download/",
configData: new ConfigurationDataBasicLogin("For best results, change the 'Default Number of Torrents per Page' setting to the maximum in your profile on the TorrentLeech webpage.")) configData: new ConfigurationDataRecaptchaLogin("For best results, change the 'Default Number of Torrents per Page' setting to the maximum in your profile on the TorrentLeech webpage."))
{ {
Encoding = Encoding.GetEncoding("iso-8859-1"); Encoding = Encoding.GetEncoding("iso-8859-1");
Language = "en-us"; Language = "en-us";
@@ -92,9 +93,62 @@ namespace Jackett.Common.Indexers
AddCategoryMapping(38, TorznabCatType.Other, "Education"); AddCategoryMapping(38, TorznabCatType.Other, "Education");
} }
public override async Task<ConfigurationData> GetConfigurationForSetup()
{
var loginPage = await RequestStringWithCookies(LoginUrl, string.Empty);
CQ cq = loginPage.Content;
var captcha = cq.Find(".g-recaptcha");
if (captcha.Any())
{
var result = this.configData;
result.CookieHeader.Value = loginPage.Cookies;
result.Captcha.SiteKey = captcha.Attr("data-sitekey");
result.Captcha.Version = "2";
return result;
}
else
{
var result = new ConfigurationDataBasicLogin();
result.SiteLink.Value = configData.SiteLink.Value;
result.Instructions.Value = configData.Instructions.Value;
result.Username.Value = configData.Username.Value;
result.Password.Value = configData.Password.Value;
result.CookieHeader.Value = loginPage.Cookies;
return result;
}
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{ {
LoadValuesFromJson(configJson); LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string> {
{ "username", configData.Username.Value },
{ "password", configData.Password.Value },
{ "g-recaptcha-response", configData.Captcha.Value }
};
if (!string.IsNullOrWhiteSpace(configData.Captcha.Cookie))
{
CookieHeader = configData.Captcha.Cookie;
try
{
var results = await PerformQuery(new TorznabQuery());
if (results.Count() == 0)
{
throw new Exception("Your cookie did not work");
}
IsConfigured = true;
SaveConfig();
return IndexerConfigurationStatus.Completed;
}
catch (Exception e)
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
}
await DoLogin(); await DoLogin();
return IndexerConfigurationStatus.RequiresTesting; return IndexerConfigurationStatus.RequiresTesting;
} }