mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
pretome: refactor parsing and login error message (#13957)
This commit is contained in:
@@ -160,14 +160,20 @@ namespace Jackett.Common.Indexers
|
|||||||
// Send Post
|
// Send Post
|
||||||
var result = await RequestWithCookiesAsync(LoginUrl, loginPage.Cookies, RequestType.POST, data: pairs);
|
var result = await RequestWithCookiesAsync(LoginUrl, loginPage.Cookies, RequestType.POST, data: pairs);
|
||||||
if (result.RedirectingTo == null)
|
if (result.RedirectingTo == null)
|
||||||
throw new ExceptionWithConfigData("Login failed. Did you use the PIN number that pretome emailed you?", configData);
|
throw new ExceptionWithConfigData("Login failed. Did you use the PIN number that PreToMe emailed you?", configData);
|
||||||
|
|
||||||
// Get result from redirect
|
// Get result from redirect
|
||||||
var loginCookies = result.Cookies;
|
var loginCookies = result.Cookies;
|
||||||
await FollowIfRedirect(result, LoginUrl, null, loginCookies);
|
await FollowIfRedirect(result, LoginUrl, null, loginCookies);
|
||||||
|
|
||||||
await ConfigureIfOK(loginCookies, result.ContentString?.Contains("logout.php") == true,
|
await ConfigureIfOK(loginCookies, result.ContentString?.Contains("logout.php") == true, () =>
|
||||||
() => throw new ExceptionWithConfigData("Login failed", configData));
|
{
|
||||||
|
var loginResultParser = new HtmlParser();
|
||||||
|
var loginResultDocument = loginResultParser.ParseDocument(result.ContentString);
|
||||||
|
var errorMessage = loginResultDocument.QuerySelector("table.body_table font[color~=\"red\"]")?.TextContent.Trim();
|
||||||
|
|
||||||
|
throw new ExceptionWithConfigData(errorMessage ?? "Login failed", configData);
|
||||||
|
});
|
||||||
|
|
||||||
return IndexerConfigurationStatus.RequiresTesting;
|
return IndexerConfigurationStatus.RequiresTesting;
|
||||||
}
|
}
|
||||||
@@ -236,27 +242,26 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
var dom = parser.ParseDocument(response.ContentString);
|
var dom = parser.ParseDocument(response.ContentString);
|
||||||
|
|
||||||
var rows = dom.QuerySelectorAll("table > tbody > tr.browse");
|
var rows = dom.QuerySelectorAll("table > tbody > tr.browse");
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
var qLink = row.Children[1].QuerySelector("a");
|
var qDetails = row.QuerySelector("a[href^=\"details.php?id=\"]");
|
||||||
var title = qLink.GetAttribute("title");
|
var title = qDetails?.GetAttribute("title");
|
||||||
if (qLink.QuerySelectorAll("span").Length == 1 && title.StartsWith("NEW! |"))
|
|
||||||
title = title.Substring(6).Trim();
|
|
||||||
|
|
||||||
if (!query.MatchQueryStringAND(title))
|
if (!query.MatchQueryStringAND(title))
|
||||||
continue; // we have to skip bad titles due to tags + any word search
|
continue; // we have to skip bad titles due to tags + any word search
|
||||||
|
|
||||||
var details = new Uri(SiteLink + qLink.GetAttribute("href"));
|
var details = new Uri(SiteLink + qDetails.GetAttribute("href"));
|
||||||
var link = new Uri(SiteLink + row.Children[2].QuerySelector("a").GetAttribute("href"));
|
var link = new Uri(SiteLink + row.QuerySelector("a[href^=\"download.php\"]")?.GetAttribute("href"));
|
||||||
var dateStr = Regex.Replace(row.Children[5].InnerHtml, @"\<br[\s]{0,1}[\/]{0,1}\>", " ");
|
|
||||||
|
var dateStr = Regex.Replace(row.QuerySelector("td:nth-of-type(6)").InnerHtml, @"\<br[\s]{0,1}[\/]{0,1}\>", " ").Trim();
|
||||||
var publishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
var publishDate = DateTimeUtil.FromTimeAgo(dateStr);
|
||||||
var files = ParseUtil.CoerceInt(row.Children[3].TextContent);
|
|
||||||
var size = ReleaseInfo.GetBytes(row.Children[7].TextContent);
|
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)")?.TextContent);
|
||||||
var grabs = ParseUtil.CoerceInt(row.Children[8].TextContent);
|
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(11)")?.TextContent);
|
||||||
var seeders = ParseUtil.CoerceInt(row.Children[9].TextContent);
|
|
||||||
var leechers = ParseUtil.CoerceInt(row.Children[10].TextContent);
|
var cat = row.QuerySelector("td:nth-of-type(1) a[href^=\"browse.php\"]")?.GetAttribute("href")?.Split('?').Last();
|
||||||
var cat = row.FirstElementChild.FirstElementChild.GetAttribute("href").Replace("browse.php?", string.Empty);
|
|
||||||
|
|
||||||
var release = new ReleaseInfo
|
var release = new ReleaseInfo
|
||||||
{
|
{
|
||||||
@@ -265,10 +270,10 @@ namespace Jackett.Common.Indexers
|
|||||||
Guid = details,
|
Guid = details,
|
||||||
Link = link,
|
Link = link,
|
||||||
PublishDate = publishDate,
|
PublishDate = publishDate,
|
||||||
Size = size,
|
Size = ReleaseInfo.GetBytes(row.QuerySelector("td:nth-of-type(8)")?.TextContent),
|
||||||
Category = MapTrackerCatToNewznab(cat),
|
Category = MapTrackerCatToNewznab(cat),
|
||||||
Files = files,
|
Files = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(4)")?.TextContent),
|
||||||
Grabs = grabs,
|
Grabs = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)")?.TextContent),
|
||||||
Seeders = seeders,
|
Seeders = seeders,
|
||||||
Peers = leechers + seeders,
|
Peers = leechers + seeders,
|
||||||
MinimumRatio = 0.75,
|
MinimumRatio = 0.75,
|
||||||
|
Reference in New Issue
Block a user