Convert DigitalHive to AngleSharp (#7359) #7292

This commit is contained in:
Cory 2020-02-28 15:40:27 -06:00 committed by GitHub
parent d8cbae68d5
commit 03bbafb0c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 20 deletions

View File

@ -4,7 +4,8 @@ using System.Collections.Specialized;
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,8 +91,9 @@ namespace Jackett.Common.Indexers
public override async Task<ConfigurationData> GetConfigurationForSetup() public override async Task<ConfigurationData> GetConfigurationForSetup()
{ {
var loginPage = await RequestStringWithCookies(LoginUrl, configData.CookieHeader.Value); var loginPage = await RequestStringWithCookies(LoginUrl, configData.CookieHeader.Value);
CQ cq = loginPage.Content; var parser = new HtmlParser();
var recaptchaSiteKey = cq.Find(".g-recaptcha").Attr("data-sitekey"); var cq = parser.ParseDocument(loginPage.Content);
var recaptchaSiteKey = cq.QuerySelector(".g-recaptcha").GetAttribute("data-sitekey");
if (recaptchaSiteKey != null) if (recaptchaSiteKey != null)
{ {
var result = configData; var result = configData;
@ -149,7 +151,8 @@ namespace Jackett.Common.Indexers
await ConfigureIfOK(result.Cookies, result.Content.Contains("logout.php"), () => await ConfigureIfOK(result.Cookies, result.Content.Contains("logout.php"), () =>
{ {
CQ errorMessage = result.Content; var parser = new HtmlParser();
var errorMessage = parser.ParseDocument(result.Content);
throw new ExceptionWithConfigData(errorMessage.Text(), configData); throw new ExceptionWithConfigData(errorMessage.Text(), configData);
}); });
@ -195,43 +198,47 @@ namespace Jackett.Common.Indexers
return releases; return releases;
} }
private IEnumerable<ReleaseInfo> contentToReleaseInfos(TorznabQuery query, CQ dom) private IEnumerable<ReleaseInfo> contentToReleaseInfos(TorznabQuery query, string content)
{ {
var parser = new HtmlParser();
var dom = parser.ParseDocument(content);
var releases = new List<ReleaseInfo>(); var releases = new List<ReleaseInfo>();
// Doesn't handle pagination yet... // Doesn't handle pagination yet...
var rows = dom["div.panel-body > table.table > tbody > tr"]; var rows = dom.QuerySelectorAll("div.panel-body > table.table > tbody > tr");
foreach (var row in rows) foreach (var row in rows)
{ {
var release = new ReleaseInfo(); var release = new ReleaseInfo();
release.MinimumRatio = 1; release.MinimumRatio = 1;
release.MinimumSeedTime = 259200; release.MinimumSeedTime = 259200;
var qRow = row.Cq();
release.Title = qRow.Find("td:nth-child(2) > a").First().Text().Trim(); release.Title = row.QuerySelector("td:nth-child(2) > a").TextContent.Trim();
if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) && !query.MatchQueryStringAND(release.Title)) if ((query.ImdbID == null || !TorznabCaps.SupportsImdbMovieSearch) && !query.MatchQueryStringAND(release.Title))
continue; continue;
release.Guid = new Uri(SiteLink + qRow.Find("td:nth-child(2) > a").First().Attr("href")); release.Guid = new Uri(SiteLink + row.QuerySelector("td:nth-child(2) > a").GetAttribute("href"));
release.Comments = release.Guid; release.Comments = release.Guid;
release.Link = new Uri(SiteLink + qRow.Find("td:nth-child(3) > a").First().Attr("href")); release.Link = new Uri(SiteLink + row.QuerySelector("td:nth-child(3) > a").GetAttribute("href"));
var pubDateElement = qRow.Find("td:nth-child(2) > span").First(); var pubDateElement = row.QuerySelector("td:nth-child(2) > span");
pubDateElement.Find("a").Remove(); // remove snatchinfo links (added after completing a torrent) // remove snatchinfo links (added after completing a torrent)
var pubDate = pubDateElement.Text().Trim().Replace("Added: ", ""); foreach (var element in pubDateElement.QuerySelectorAll("a"))
element.Remove();
var pubDate = pubDateElement.TextContent.Trim().Replace("Added: ", "");
release.PublishDate = DateTime.Parse(pubDate).ToLocalTime(); release.PublishDate = DateTime.Parse(pubDate).ToLocalTime();
release.Category = MapTrackerCatToNewznab(qRow.Find("td:nth-child(1) > a").First().Attr("href").Split('=')[1]); release.Category = MapTrackerCatToNewznab(row.QuerySelector("td:nth-child(1) > a").GetAttribute("href").Split('=')[1]);
release.Size = ReleaseInfo.GetBytes(qRow.Find("td:nth-child(7)").First().Text()); release.Size = ReleaseInfo.GetBytes(row.QuerySelector("td:nth-child(7)").TextContent);
release.Seeders = ParseUtil.CoerceInt(qRow.Find("td:nth-child(9)").First().Text()); release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(9)").TextContent);
release.Peers = ParseUtil.CoerceInt(qRow.Find("td:nth-child(10)").First().Text()) + release.Seeders; release.Peers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-child(10)").TextContent) + release.Seeders;
var files = row.Cq().Find("td:nth-child(5)").Text(); var files = row.QuerySelector("td:nth-child(5)").TextContent;
release.Files = ParseUtil.CoerceInt(files); release.Files = ParseUtil.CoerceInt(files);
var grabs = row.Cq().Find("td:nth-child(8)").Text(); var grabs = row.QuerySelector("td:nth-child(8)").TextContent;
release.Grabs = ParseUtil.CoerceInt(grabs); release.Grabs = ParseUtil.CoerceInt(grabs);
if (row.Cq().Find("i.fa-star").Any()) if (row.QuerySelector("i.fa-star") != null)
release.DownloadVolumeFactor = 0; release.DownloadVolumeFactor = 0;
else else
release.DownloadVolumeFactor = 1; release.DownloadVolumeFactor = 1;