From 50a06f640fa791c6e262d0da7b56f88b91e0dd38 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Thu, 29 Sep 2016 21:09:20 +0200 Subject: [PATCH] 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 --- src/Jackett/Indexers/SceneTime.cs | 52 +++++++++++++++++-- .../ConfigurationDataRecaptchaLogin.cs | 4 +- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Jackett/Indexers/SceneTime.cs b/src/Jackett/Indexers/SceneTime.cs index 6f5ec65f1..95c635536 100644 --- a/src/Jackett/Indexers/SceneTime.cs +++ b/src/Jackett/Indexers/SceneTime.cs @@ -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 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 ApplyConfiguration(JToken configJson) { configData.LoadValuesFromJson(configJson); var pairs = new Dictionary { { "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"), () => { diff --git a/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs b/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs index 94991c02d..cdac1a64a 100644 --- a/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs +++ b/src/Jackett/Models/IndexerConfig/ConfigurationDataRecaptchaLogin.cs @@ -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 = "" }; }