Add SceneTime captcha support (#529)

* Add optional instruction message to RecaptchaLogin

* Add recaptcha support for Scene Time

* Fix Scene Time captcha handling from a remote host
This commit is contained in:
kaso17 2016-09-29 21:09:20 +02:00 committed by JigSaw
parent 6cab5fbba8
commit 50a06f640f
2 changed files with 51 additions and 5 deletions

View File

@ -16,13 +16,14 @@ namespace Jackett.Indexers
{
public class SceneTime : BaseIndexer, IIndexer
{
private string StartPageUrl { get { return SiteLink + "login.php"; } }
private string LoginUrl { get { return SiteLink + "takelogin.php"; } }
private string SearchUrl { get { return SiteLink + "browse_API.php"; } }
private string DownloadUrl { get { return SiteLink + "download.php/{0}/download.torrent"; } }
new ConfigurationDataBasicLogin configData
new ConfigurationDataRecaptchaLogin configData
{
get { return (ConfigurationDataBasicLogin)base.configData; }
get { return (ConfigurationDataRecaptchaLogin)base.configData; }
set { base.configData = value; }
}
@ -35,7 +36,7 @@ namespace Jackett.Indexers
client: w,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLogin("For best results, change the 'Torrents per page' setting to the maximum in your profile on the SceneTime webpage."))
configData: new ConfigurationDataRecaptchaLogin("For best results, change the 'Torrents per page' setting to the maximum in your profile on the SceneTime webpage."))
{
AddCategoryMapping(1, TorznabCatType.MoviesSD);
AddCategoryMapping(3, TorznabCatType.MoviesDVD);
@ -78,14 +79,57 @@ namespace Jackett.Indexers
AddCategoryMapping(11, TorznabCatType.AudioVideo);
}
public override async Task<ConfigurationData> GetConfigurationForSetup()
{
var loginPage = await RequestStringWithCookies(StartPageUrl, string.Empty);
CQ cq = loginPage.Content;
var result = new ConfigurationDataRecaptchaLogin();
CQ recaptcha = cq.Find(".g-recaptcha").Attr("data-sitekey");
if (recaptcha.Length != 0)
{
result.CookieHeader.Value = loginPage.Cookies;
result.Captcha.SiteKey = cq.Find(".g-recaptcha").Attr("data-sitekey");
return result;
}
else
{
var stdResult = new ConfigurationDataBasicLogin();
stdResult.CookieHeader.Value = loginPage.Cookies;
return stdResult;
}
}
public async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{
configData.LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string> {
{ "username", configData.Username.Value },
{ "password", configData.Password.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");
}
SaveConfig();
IsConfigured = true;
return IndexerConfigurationStatus.Completed;
}
catch (Exception e)
{
IsConfigured = false;
throw new Exception("Your cookie did not work: " + e.Message);
}
}
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () =>
{

View File

@ -12,12 +12,14 @@ namespace Jackett.Models.IndexerConfig
public StringItem Username { get; private set; }
public StringItem Password { get; private set; }
public RecaptchaItem Captcha { get; private set; }
public DisplayItem Instructions { get; private set; }
public ConfigurationDataRecaptchaLogin()
public ConfigurationDataRecaptchaLogin(string instructionMessageOptional = null)
{
Username = new StringItem { Name = "Username" };
Password = new StringItem { Name = "Password" };
Captcha = new RecaptchaItem() { Name = "Recaptcha" };
Instructions = new DisplayItem(instructionMessageOptional) { Name = "" };
}