Convert BitCityReloaded to AngleSharp (#7357) #7292

This commit is contained in:
Cory 2020-02-28 15:24:26 -06:00 committed by GitHub
parent b4075d1d35
commit 99c269c896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 21 deletions

View File

@ -2,9 +2,11 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsQuery;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Services.Interfaces;
@ -95,8 +97,9 @@ namespace Jackett.Common.Indexers
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, LoginUrl);
await ConfigureIfOK(result.Cookies, result.Content != null && result.Content.Contains("logout.php"), () =>
{
CQ dom = result.Content;
var errorMessage = dom["#login_error"].Text().Trim();
var parser = new HtmlParser();
var dom = parser.ParseDocument(result.Content);
var errorMessage = dom.QuerySelector("#login_error").Text().Trim();
throw new ExceptionWithConfigData(errorMessage, configData);
});
return IndexerConfigurationStatus.RequiresTesting;
@ -131,8 +134,9 @@ namespace Jackett.Common.Indexers
var results = response.Content;
try
{
CQ dom = results;
var rows = dom["table.tableinborder[cellpadding=0] > tbody > tr"];
var parser = new HtmlParser();
var dom = parser.ParseDocument(results);
var rows = dom.QuerySelectorAll("table.tableinborder[cellpadding=0] > tbody > tr");
foreach (var row in rows)
{
@ -142,23 +146,22 @@ namespace Jackett.Common.Indexers
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1;
var qRow = row.Cq();
var flagImgs = qRow.Find("table tbody tr: eq(0) td > img");
var flagImgs = row.QuerySelectorAll("table tbody tr:nth-of-type(1) td > img");
var flags = new List<string>();
flagImgs.Each(flagImg =>
foreach (var flagImg in flagImgs)
{
var flag = flagImg.GetAttribute("src").Replace("pic/torrent_", "").Replace(".gif", "").ToUpper();
if (flag == "OU")
release.DownloadVolumeFactor = 0;
else
flags.Add(flag);
});
}
var titleLink = qRow.Find("table tbody tr:eq(0) td a:has(b)").First();
var DLLink = qRow.Find("td.tableb > a:has(img[title=\"Torrent herunterladen\"])").First();
release.Comments = new Uri(SiteLink + titleLink.Attr("href").Replace("&hit=1", ""));
release.Link = new Uri(SiteLink + DLLink.Attr("href"));
release.Title = titleLink.Text().Trim();
var titleLink = row.QuerySelector("table tbody tr:nth-of-type(1) td a:has(b)");
var DLLink = row.QuerySelector("td.tableb > a:has(img[title=\"Torrent herunterladen\"])");
release.Comments = new Uri(SiteLink + titleLink.GetAttribute("href").Replace("&hit=1", ""));
release.Link = new Uri(SiteLink + DLLink.GetAttribute("href"));
release.Title = titleLink.TextContent.Trim();
if (!query.MatchQueryStringAND(release.Title))
continue;
@ -166,24 +169,24 @@ namespace Jackett.Common.Indexers
release.Description = string.Join(", ", flags);
release.Guid = release.Link;
var dateStr = qRow.Find("table tbody tr:eq(1) td:eq(4)").Html().Replace("&nbsp;", " ").Trim();
var dateStr = row.QuerySelector("table tbody tr:nth-of-type(2) td:nth-of-type(5)").Html().Replace("&nbsp;", " ").Trim();
var dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Unspecified);
var pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz);
release.PublishDate = pubDateUtc.ToLocalTime();
var sizeStr = qRow.Find("table tbody tr:eq(1) td b").First().Text().Trim();
var sizeStr = row.QuerySelector("table tbody tr:nth-of-type(2) td b").TextContent.Trim();
release.Size = ReleaseInfo.GetBytes(sizeStr.Replace(",", "."));
release.Seeders = ParseUtil.CoerceInt(qRow.Find("table tbody tr:eq(1) td:eq(1) b:eq(0) font").Text().Trim());
release.Peers = ParseUtil.CoerceInt(qRow.Find("table tbody tr:eq(1) td:eq(1) b:eq(1) font").Text().Trim()) + release.Seeders;
release.Seeders = ParseUtil.CoerceInt(row.QuerySelector("table tbody tr:nth-of-type(2) td:nth-of-type(2) b:nth-of-type(1) font").TextContent.Trim());
release.Peers = ParseUtil.CoerceInt(row.QuerySelector("table tbody tr:nth-of-type(2) td:nth-of-type(2) b:nth-of-type(2) font").TextContent.Trim()) + release.Seeders;
var catId = qRow.Find("td:eq(0) a").First().Attr("href").Split('=')[1];
var catId = row.QuerySelector("td:nth-of-type(1) a").GetAttribute("href").Split('=')[1];
release.Category = MapTrackerCatToNewznab(catId);
var files = qRow.Find("td:has(a[href*=\"&filelist=1\"])> b:nth-child(2)").Text();
var files = row.QuerySelector("td:has(a[href*=\"&filelist=1\"])> b:nth-child(2)").TextContent;
release.Files = ParseUtil.CoerceInt(files);
var grabs = qRow.Find("td:has(a[href*=\"&tosnatchers=1\"])> b:nth-child(1)").Text();
var grabs = row.QuerySelector("td:has(a[href*=\"&tosnatchers=1\"])> b:nth-child(1)").TextContent;
release.Grabs = ParseUtil.CoerceInt(grabs);
releases.Add(release);