mirror of
https://github.com/Jackett/Jackett
synced 2024-12-26 17:58:49 +00:00
parent
6949ddea92
commit
39740d1f4c
1 changed files with 16 additions and 69 deletions
|
@ -4,7 +4,6 @@ using System.Diagnostics.CodeAnalysis;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AngleSharp.Html.Parser;
|
||||
using Jackett.Common.Helpers;
|
||||
using Jackett.Common.Models;
|
||||
using Jackett.Common.Models.IndexerConfig;
|
||||
|
@ -20,8 +19,6 @@ namespace Jackett.Common.Indexers
|
|||
[ExcludeFromCodeCoverage]
|
||||
public class TorrentDay : BaseWebIndexer
|
||||
{
|
||||
private string StartPageUrl => SiteLink + "login.php";
|
||||
private string LoginUrl => SiteLink + "tak3login.php";
|
||||
private string SearchUrl => SiteLink + "t.json";
|
||||
|
||||
public override string[] AlternativeSiteLinks { get; protected set; } = {
|
||||
|
@ -47,7 +44,7 @@ namespace Jackett.Common.Indexers
|
|||
"https://www.td.af/"
|
||||
};
|
||||
|
||||
private new ConfigurationDataRecaptchaLogin configData => (ConfigurationDataRecaptchaLogin)base.configData;
|
||||
private new ConfigurationDataCookie configData => (ConfigurationDataCookie)base.configData;
|
||||
|
||||
public TorrentDay(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
||||
: base(id: "torrentday",
|
||||
|
@ -63,7 +60,7 @@ namespace Jackett.Common.Indexers
|
|||
client: wc,
|
||||
logger: l,
|
||||
p: ps,
|
||||
configData: new ConfigurationDataRecaptchaLogin(
|
||||
configData: new ConfigurationDataCookie(
|
||||
"Make sure you get the cookies from the same torrent day domain as configured above."))
|
||||
{
|
||||
Encoding = Encoding.UTF8;
|
||||
|
@ -121,76 +118,26 @@ namespace Jackett.Common.Indexers
|
|||
AddCategoryMapping(15, TorznabCatType.XXXPacks, "XXX/Packs");
|
||||
}
|
||||
|
||||
public override async Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var loginPage = await RequestStringWithCookies(StartPageUrl, string.Empty);
|
||||
if (loginPage.IsRedirect)
|
||||
loginPage = await RequestStringWithCookies(loginPage.RedirectingTo, string.Empty);
|
||||
if (loginPage.IsRedirect)
|
||||
loginPage = await RequestStringWithCookies(loginPage.RedirectingTo, string.Empty);
|
||||
|
||||
var parser = new HtmlParser();
|
||||
var dom = parser.ParseDocument(loginPage.Content);
|
||||
var result = configData;
|
||||
|
||||
//result.CookieHeader.Value = loginPage.Cookies;
|
||||
UpdateCookieHeader(loginPage.Cookies); // update cookies instead of replacing them, see #3717
|
||||
result.Captcha.SiteKey = dom.QuerySelector(".g-recaptcha")?.GetAttribute("data-sitekey");
|
||||
result.Captcha.Version = "2";
|
||||
return result;
|
||||
}
|
||||
|
||||
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken 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.Cookie.Value;
|
||||
try
|
||||
{
|
||||
// Cookie was manually supplied
|
||||
CookieHeader = configData.Captcha.Cookie;
|
||||
try
|
||||
{
|
||||
var results = await PerformQuery(new TorznabQuery());
|
||||
if (!results.Any())
|
||||
throw new Exception("Found 0 results in the tracker");
|
||||
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);
|
||||
}
|
||||
IsConfigured = true;
|
||||
SaveConfig();
|
||||
return IndexerConfigurationStatus.Completed;
|
||||
}
|
||||
|
||||
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, configData.CookieHeader.Value, true, null, LoginUrl);
|
||||
await ConfigureIfOK(result.Cookies, result.Content?.Contains("logout.php") == true, () =>
|
||||
catch (Exception e)
|
||||
{
|
||||
var errorMessage = result.Content;
|
||||
|
||||
var parser = new HtmlParser();
|
||||
var dom = parser.ParseDocument(result.Content);
|
||||
var messageEl = dom.QuerySelector("#login");
|
||||
if (messageEl != null)
|
||||
{
|
||||
foreach (var child in messageEl.QuerySelectorAll("form"))
|
||||
child.Remove();
|
||||
errorMessage = messageEl.TextContent.Trim();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(errorMessage) && result.IsRedirect)
|
||||
errorMessage = $"Got a redirect to {result.RedirectingTo}, please adjust your the alternative link";
|
||||
|
||||
throw new ExceptionWithConfigData(errorMessage, configData);
|
||||
});
|
||||
return IndexerConfigurationStatus.RequiresTesting;
|
||||
IsConfigured = false;
|
||||
throw new Exception("Your cookie did not work: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
||||
|
@ -213,9 +160,9 @@ namespace Jackett.Common.Indexers
|
|||
// Check for being logged out
|
||||
if (results.IsRedirect)
|
||||
if (results.RedirectingTo.Contains("login.php"))
|
||||
throw new ExceptionWithConfigData("Login failed, please reconfigure the tracker to update the cookies", configData);
|
||||
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.");
|
||||
else
|
||||
throw new ExceptionWithConfigData($"Got a redirect to {results.RedirectingTo}, please adjust your the alternative link", configData);
|
||||
throw new Exception($"Got a redirect to {results.RedirectingTo}, please adjust your the alternative link");
|
||||
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue