1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-28 02:39:26 +00:00

Convert AnimeTorrents to AngleSharp (#7354) #7292

This commit is contained in:
Cory 2020-02-28 15:22:13 -06:00 committed by GitHub
parent 68b25de828
commit 49eebc90e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,8 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
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;
@ -80,8 +81,9 @@ namespace Jackett.Common.Indexers
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true); var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, loginPage.Cookies, true);
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 errorMessage = dom[".ui-state-error"].Text().Trim(); var dom = parser.ParseDocument(result.Content);
var errorMessage = dom.QuerySelector(".ui-state-error").Text().Trim();
throw new ExceptionWithConfigData(errorMessage, configData); throw new ExceptionWithConfigData(errorMessage, configData);
}); });
@ -125,15 +127,15 @@ 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["tr"]; var rows = dom.QuerySelectorAll("tr");
foreach (var row in rows.Skip(1)) foreach (var row in rows.Skip(1))
{ {
var release = new ReleaseInfo(); var release = new ReleaseInfo();
var qRow = row.Cq(); var qTitleLink = row.QuerySelector("td:nth-of-type(2) a:nth-of-type(1)");
var qTitleLink = qRow.Find("td:eq(1) a:eq(0)").First(); release.Title = qTitleLink.TextContent.Trim();
release.Title = qTitleLink.Text().Trim();
// 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.
if (string.IsNullOrWhiteSpace(release.Title)) if (string.IsNullOrWhiteSpace(release.Title))
@ -141,16 +143,16 @@ namespace Jackett.Common.Indexers
break; break;
} }
release.Guid = new Uri(qTitleLink.Attr("href")); release.Guid = new Uri(qTitleLink.GetAttribute("href"));
release.Comments = release.Guid; release.Comments = release.Guid;
var dateString = qRow.Find("td:eq(4)").Text(); var dateString = row.QuerySelector("td:nth-of-type(5)").TextContent;
release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yy", CultureInfo.InvariantCulture); release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yy", CultureInfo.InvariantCulture);
var qLink = qRow.Find("td:eq(2) a"); var qLink = row.QuerySelector("td:nth-of-type(3) a");
if (qLink.Length != 0) // newbie users don't see DL links if (qLink != null) // newbie users don't see DL links
{ {
release.Link = new Uri(qLink.Attr("href")); release.Link = new Uri(qLink.GetAttribute("href"));
} }
else else
{ {
@ -160,16 +162,16 @@ namespace Jackett.Common.Indexers
release.Link = release.Comments; release.Link = release.Comments;
} }
var sizeStr = qRow.Find("td:eq(5)").Text(); var sizeStr = row.QuerySelector("td:nth-of-type(6)").TextContent;
release.Size = ReleaseInfo.GetBytes(sizeStr); release.Size = ReleaseInfo.GetBytes(sizeStr);
var connections = qRow.Find("td:eq(7)").Text().Trim().Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var connections = row.QuerySelector("td:nth-of-type(8)").TextContent.Trim().Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
release.Seeders = ParseUtil.CoerceInt(connections[0].Trim()); release.Seeders = ParseUtil.CoerceInt(connections[0].Trim());
release.Peers = ParseUtil.CoerceInt(connections[1].Trim()) + release.Seeders; release.Peers = ParseUtil.CoerceInt(connections[1].Trim()) + release.Seeders;
release.Grabs = ParseUtil.CoerceLong(connections[2].Trim()); release.Grabs = ParseUtil.CoerceLong(connections[2].Trim());
var rCat = row.Cq().Find("td:eq(0) a").First().Attr("href"); var rCat = row.QuerySelector("td:nth-of-type(1) a").GetAttribute("href");
var rCatIdx = rCat.IndexOf("cat="); var rCatIdx = rCat.IndexOf("cat=");
if (rCatIdx > -1) if (rCatIdx > -1)
{ {
@ -178,17 +180,17 @@ namespace Jackett.Common.Indexers
release.Category = MapTrackerCatToNewznab(rCat); release.Category = MapTrackerCatToNewznab(rCat);
if (qRow.Find("img[alt=\"Gold Torrent\"]").Length >= 1) if (row.QuerySelector("img[alt=\"Gold Torrent\"]") != null)
release.DownloadVolumeFactor = 0; release.DownloadVolumeFactor = 0;
else if (qRow.Find("img[alt=\"Silver Torrent\"]").Length >= 1) else if (row.QuerySelector("img[alt=\"Silver Torrent\"]") != null)
release.DownloadVolumeFactor = 0.5; release.DownloadVolumeFactor = 0.5;
else else
release.DownloadVolumeFactor = 1; release.DownloadVolumeFactor = 1;
var ULFactorImg = qRow.Find("img[alt*=\"x Multiplier Torrent\"]"); var ULFactorImg = row.QuerySelector("img[alt*=\"x Multiplier Torrent\"]");
if (ULFactorImg.Length >= 1) if (ULFactorImg != null)
{ {
release.UploadVolumeFactor = ParseUtil.CoerceDouble(ULFactorImg.Attr("alt").Split('x')[0]); release.UploadVolumeFactor = ParseUtil.CoerceDouble(ULFactorImg.GetAttribute("alt").Split('x')[0]);
} }
else else
{ {
@ -196,7 +198,7 @@ namespace Jackett.Common.Indexers
} }
qTitleLink.Remove(); qTitleLink.Remove();
release.Description = qRow.Find("td:eq(1)").Text(); release.Description = row.QuerySelector("td:nth-of-type(2)").TextContent;
releases.Add(release); releases.Add(release);
} }