Convert GimmePeers to AngleSharp (#7371)

This commit is contained in:
Cory 2020-02-29 12:33:30 -06:00 committed by GitHub
parent 169fda4dbb
commit 544501d2a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 17 deletions

View File

@ -5,7 +5,8 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CsQuery; using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Jackett.Common.Models; using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig; using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Services.Interfaces; using Jackett.Common.Services.Interfaces;
@ -90,9 +91,10 @@ namespace Jackett.Common.Indexers
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, SiteLink, SiteLink); var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true, SiteLink, SiteLink);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () => await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () =>
{ {
CQ dom = result.Content; var parser = new HtmlParser();
var messageEl = dom["body > div"].First(); var dom = parser.ParseDocument(result.Content);
var errorMessage = messageEl.Text().Trim(); var messageEl = dom.QuerySelector("body > div");
var errorMessage = messageEl.TextContent.Trim();
throw new ExceptionWithConfigData(errorMessage, configData); throw new ExceptionWithConfigData(errorMessage, configData);
}); });
return IndexerConfigurationStatus.RequiresTesting; return IndexerConfigurationStatus.RequiresTesting;
@ -141,17 +143,18 @@ namespace Jackett.Common.Indexers
var results = response.Content; var results = response.Content;
try try
{ {
CQ dom = results; var parser = new HtmlParser();
var dom = parser.ParseDocument(results);
var rows = dom[".browsetable:last tr"]; //the class for the table changed var rows = dom.QuerySelectorAll(".browsetable:last tr"); //the class for the table changed
foreach (var row in rows.Skip(1)) foreach (var row in rows.Skip(1))
{ {
var release = new ReleaseInfo(); var release = new ReleaseInfo();
var link = row.Cq().Find("td:eq(1) a:eq(0)").First(); var link = row.QuerySelector("td:nth-of-type(2) a:nth-of-type(1)");
release.Guid = new Uri(SiteLink + link.Attr("href")); release.Guid = new Uri(SiteLink + link.GetAttribute("href"));
release.Comments = release.Guid; release.Comments = release.Guid;
release.Title = link.Text().Trim(); release.Title = link.TextContent.Trim();
release.Description = release.Title; release.Description = release.Title;
// If we search an get no results, we still get a table just with no info. // If we search an get no results, we still get a table just with no info.
@ -161,26 +164,27 @@ namespace Jackett.Common.Indexers
} }
// Check if the release has been assigned a category // Check if the release has been assigned a category
if (row.Cq().Find("td:eq(0) a").Length > 0) var category = row.QuerySelector("td:nth-of-type(1) a");
if (category != null)
{ {
var cat = row.Cq().Find("td:eq(0) a").First().Attr("href").Substring(15); var cat = category.GetAttribute("href").Substring(15);
release.Category = MapTrackerCatToNewznab(cat); release.Category = MapTrackerCatToNewznab(cat);
} }
var qLink = row.Cq().Find("td:eq(2) a").First(); var qLink = row.QuerySelector("td:nth-of-type(3) a");
release.Link = new Uri(SiteLink + qLink.Attr("href")); release.Link = new Uri(SiteLink + qLink.GetAttribute("href"));
var added = row.Cq().Find("td:eq(6)").First().Text().Trim(); //column changed from 7 to 6 var added = row.QuerySelector("td:nth-of-type(7)").TextContent.Trim(); //column changed from 7 to 6
var date = added.Substring(0, 10); var date = added.Substring(0, 10);
var time = added.Substring(11, 8); //date layout wasn't quite right var time = added.Substring(11, 8); //date layout wasn't quite right
var dateTime = date + time; var dateTime = date + time;
release.PublishDate = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); release.PublishDate = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
var sizeStr = row.Cq().Find("td:eq(5)").First().Text().Trim(); //size column moved from 8 to 5 var sizeStr = row.QuerySelector("td:nth-of-type(6)").TextContent.Trim(); //size column moved from 8 to 5
release.Size = ReleaseInfo.GetBytes(sizeStr); release.Size = ReleaseInfo.GetBytes(sizeStr);
release.Seeders = ParseUtil.CoerceInt(row.Cq().Find("td:eq(10)").First().Text().Trim()); release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(11)").TextContent.Trim());
release.Peers = ParseUtil.CoerceInt(row.Cq().Find("td:eq(11)").First().Text().Trim()) + release.Seeders; release.Peers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(12)").TextContent.Trim()) + release.Seeders;
releases.Add(release); releases.Add(release);
} }