mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Convert Nordbits to AngleSharp (#7402)
This commit is contained in:
@@ -8,7 +8,9 @@ using System.Reflection;
|
|||||||
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.Dom;
|
||||||
|
using AngleSharp.Html.Parser;
|
||||||
using Jackett.Common.Helpers;
|
using Jackett.Common.Helpers;
|
||||||
using Jackett.Common.Models;
|
using Jackett.Common.Models;
|
||||||
using Jackett.Common.Models.IndexerConfig.Bespoke;
|
using Jackett.Common.Models.IndexerConfig.Bespoke;
|
||||||
@@ -38,7 +40,7 @@ namespace Jackett.Common.Indexers
|
|||||||
private static string Directory => Path.Combine(Path.GetTempPath(), "Jackett", MethodBase.GetCurrentMethod().DeclaringType?.Name);
|
private static string Directory => Path.Combine(Path.GetTempPath(), "Jackett", MethodBase.GetCurrentMethod().DeclaringType?.Name);
|
||||||
|
|
||||||
private readonly Dictionary<string, string> _emulatedBrowserHeaders = new Dictionary<string, string>();
|
private readonly Dictionary<string, string> _emulatedBrowserHeaders = new Dictionary<string, string>();
|
||||||
private CQ _fDom;
|
|
||||||
private ConfigurationDataNorbits ConfigData => (ConfigurationDataNorbits)configData;
|
private ConfigurationDataNorbits ConfigData => (ConfigurationDataNorbits)configData;
|
||||||
|
|
||||||
public Norbits(IIndexerConfigurationService configService, Utils.Clients.WebClient w, Logger l, IProtectionService ps)
|
public Norbits(IIndexerConfigurationService configService, Utils.Clients.WebClient w, Logger l, IProtectionService ps)
|
||||||
@@ -225,7 +227,6 @@ namespace Jackett.Common.Indexers
|
|||||||
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
||||||
{
|
{
|
||||||
var releases = new List<ReleaseInfo>();
|
var releases = new List<ReleaseInfo>();
|
||||||
var torrentRowList = new List<CQ>();
|
|
||||||
var exactSearchTerm = query.GetQueryString();
|
var exactSearchTerm = query.GetQueryString();
|
||||||
var searchUrl = SearchUrl;
|
var searchUrl = SearchUrl;
|
||||||
|
|
||||||
@@ -261,107 +262,83 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
// Getting results & Store content
|
// Getting results & Store content
|
||||||
var response = await RequestStringWithCookiesAndRetry(request, ConfigData.CookieHeader.Value);
|
var response = await RequestStringWithCookiesAndRetry(request, ConfigData.CookieHeader.Value);
|
||||||
_fDom = response.Content;
|
var parser = new HtmlParser();
|
||||||
|
var dom = parser.ParseDocument(response.Content);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var firstPageRows = FindTorrentRows();
|
var firstPageRows = FindTorrentRows(dom);
|
||||||
|
|
||||||
// Add them to torrents list
|
|
||||||
torrentRowList.AddRange(firstPageRows.Select(fRow => fRow.Cq()));
|
|
||||||
|
|
||||||
// If pagination available
|
// If pagination available
|
||||||
int nbResults;
|
int nbResults;
|
||||||
int pageLinkCount;
|
var pageLinkCount = 1;
|
||||||
nbResults = 1;
|
|
||||||
pageLinkCount = 1;
|
|
||||||
|
|
||||||
// Check if we have a minimum of one result
|
// Check if we have a minimum of one result
|
||||||
if (firstPageRows.Length > 1)
|
if (firstPageRows?.Length > 1)
|
||||||
{
|
{
|
||||||
// Retrieve total count on our alone page
|
// Retrieve total count on our alone page
|
||||||
nbResults = firstPageRows.Count();
|
nbResults = firstPageRows.Count();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if no result
|
|
||||||
if (torrentRowList.Count == 0)
|
|
||||||
{
|
|
||||||
// No results found
|
|
||||||
Output("\nNo result found for your query, please try another search term ...\n", "info");
|
|
||||||
|
|
||||||
// No result found for this query
|
// No result found for this query
|
||||||
|
Output("\nNo result found for your query, please try another search term ...\n", "info");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Output("\nFound " + nbResults + " result(s) (+/- " + firstPageRows.Length + ") in " + pageLinkCount + " page(s) for this query !");
|
Output("\nFound " + nbResults + " result(s) (+/- " + firstPageRows.Length + ") in " + pageLinkCount + " page(s) for this query !");
|
||||||
Output("\nThere are " + firstPageRows.Length + " results on the first page !");
|
Output("\nThere are " + firstPageRows.Length + " results on the first page !");
|
||||||
|
|
||||||
// Loop on results
|
// Loop on results
|
||||||
|
|
||||||
foreach (var tRow in torrentRowList)
|
foreach (var row in firstPageRows)
|
||||||
{
|
{
|
||||||
Output("Torrent #" + (releases.Count + 1));
|
Output("Torrent #" + (releases.Count + 1));
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
var id = tRow.Find("td:eq(1) > a:eq(0)").Attr("href").Split('=').Last();
|
var id = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("href").Split('=').Last();
|
||||||
Output("ID: " + id);
|
Output("ID: " + id);
|
||||||
|
|
||||||
// Release Name
|
// Release Name
|
||||||
var name = tRow.Find("td:eq(1) > a:eq(0)").Attr("title");
|
var name = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(1)").GetAttribute("title");
|
||||||
|
|
||||||
// Category
|
// Category
|
||||||
var categoryId = tRow.Find("td:eq(0) > div > a:eq(0)").Attr("href").Split('?').Last();
|
var categoryName = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("title");
|
||||||
var categoryName = tRow.Find("td:eq(0) > div > a:eq(0)").Attr("title");
|
var mainCat = row.QuerySelector("td:nth-of-type(1) > div > a:nth-of-type(1)").GetAttribute("href").Split('?').Last();
|
||||||
|
var qSubCat2 = row.QuerySelector("td:nth-of-type(1) > div > a[href^=\"/browse.php?sub2_cat[]=\"]");
|
||||||
|
|
||||||
var MainCat = tRow.Find("td:eq(0) > div > a:eq(0)").Attr("href").Split('?').Last();
|
var cat = mainCat;
|
||||||
var SubCat1 = "none";
|
if (qSubCat2 != null)
|
||||||
var SubCat2 = "none";
|
cat += '&' + qSubCat2.GetAttribute("href").Split('?').Last();
|
||||||
|
|
||||||
var testcat = MainCat;
|
Output("Category: " + cat + " - " + categoryName);
|
||||||
|
|
||||||
if (tRow.Find("td:eq(0) > div > a:eq(1)").Length == 1)
|
|
||||||
{
|
|
||||||
SubCat1 = tRow.Find("td:eq(0) > div > a:eq(1)").Attr("href").Split('?').Last();
|
|
||||||
}
|
|
||||||
if (tRow.Find("td:eq(0) > div > a[href^=\"/browse.php?sub2_cat[]=\"]").Length == 1)
|
|
||||||
{
|
|
||||||
SubCat2 = tRow.Find("td:eq(0) > div > a[href^=\"/browse.php?sub2_cat[]=\"]").Attr("href").Split('?').Last();
|
|
||||||
testcat = MainCat + '&' + SubCat2;
|
|
||||||
}
|
|
||||||
|
|
||||||
Output("Category: " + testcat + " - " + categoryName);
|
|
||||||
|
|
||||||
// Seeders
|
// Seeders
|
||||||
var seeders = ParseUtil.CoerceInt(tRow.Find("td:eq(8)").Text());
|
var seeders = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(9)").TextContent);
|
||||||
Output("Seeders: " + seeders);
|
Output("Seeders: " + seeders);
|
||||||
|
|
||||||
// Leechers
|
// Leechers
|
||||||
var leechers = ParseUtil.CoerceInt(tRow.Find("td:eq(9)").Text());
|
var leechers = ParseUtil.CoerceInt(row.QuerySelector("td:nth-of-type(10)").TextContent);
|
||||||
Output("Leechers: " + leechers);
|
Output("Leechers: " + leechers);
|
||||||
|
|
||||||
// Completed
|
// Completed
|
||||||
var regexObj = new Regex(@"[^\d]");
|
var regexObj = new Regex(@"[^\d]");
|
||||||
var completed2 = tRow.Find("td:eq(7)").Text();
|
var completed2 = row.QuerySelector("td:nth-of-type(8)").TextContent;
|
||||||
var completed = ParseUtil.CoerceLong(regexObj.Replace(completed2, ""));
|
var completed = ParseUtil.CoerceLong(regexObj.Replace(completed2, ""));
|
||||||
Output("Completed: " + completed);
|
Output("Completed: " + completed);
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
var files = 1;
|
var qFiles = row.QuerySelector("td:nth-of-type(3) > a");
|
||||||
if (tRow.Find("td:eq(2) > a").Length == 1)
|
var files = qFiles != null ? ParseUtil.CoerceInt(Regex.Match(qFiles.TextContent, @"\d+").Value) : 1;
|
||||||
{
|
|
||||||
files = ParseUtil.CoerceInt(Regex.Match(tRow.Find("td:eq(2) > a").Text(), @"\d+").Value);
|
|
||||||
}
|
|
||||||
Output("Files: " + files);
|
Output("Files: " + files);
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
var humanSize = tRow.Find("td:eq(6)").Text().ToLowerInvariant();
|
var humanSize = row.QuerySelector("td:nth-of-type(7)").TextContent.ToLowerInvariant();
|
||||||
var size = ReleaseInfo.GetBytes(humanSize);
|
var size = ReleaseInfo.GetBytes(humanSize);
|
||||||
Output("Size: " + humanSize + " (" + size + " bytes)");
|
Output("Size: " + humanSize + " (" + size + " bytes)");
|
||||||
|
|
||||||
// --> Date
|
// --> Date
|
||||||
var dateTimeOrig = tRow.Find("td:eq(4)").Text();
|
var dateTimeOrig = row.QuerySelector("td:nth-of-type(5)").TextContent;
|
||||||
var dateTime = Regex.Replace(dateTimeOrig, @"<[^>]+>| ", "").Trim();
|
var dateTime = Regex.Replace(dateTimeOrig, @"<[^>]+>| ", "").Trim();
|
||||||
var date = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
var date = DateTime.ParseExact(dateTime, "yyyy-MM-ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
||||||
Output("Released on: " + date);
|
Output("Released on: " + date);
|
||||||
@@ -375,7 +352,7 @@ namespace Jackett.Common.Indexers
|
|||||||
Output("Comments Link: " + commentsLink.AbsoluteUri);
|
Output("Comments Link: " + commentsLink.AbsoluteUri);
|
||||||
|
|
||||||
// Torrent Download URL
|
// Torrent Download URL
|
||||||
var passkey = tRow.Find("td:eq(1) > a:eq(1)").Attr("href");
|
var passkey = row.QuerySelector("td:nth-of-type(2) > a:nth-of-type(2)").GetAttribute("href");
|
||||||
var key = Regex.Match(passkey, "(?<=passkey\\=)([a-zA-z0-9]*)");
|
var key = Regex.Match(passkey, "(?<=passkey\\=)([a-zA-z0-9]*)");
|
||||||
var downloadLink = new Uri(TorrentDownloadUrl.Replace("{id}", id.ToString()).Replace("{passkey}", key.ToString()));
|
var downloadLink = new Uri(TorrentDownloadUrl.Replace("{id}", id.ToString()).Replace("{passkey}", key.ToString()));
|
||||||
Output("Download Link: " + downloadLink.AbsoluteUri);
|
Output("Download Link: " + downloadLink.AbsoluteUri);
|
||||||
@@ -383,7 +360,7 @@ namespace Jackett.Common.Indexers
|
|||||||
// Building release infos
|
// Building release infos
|
||||||
var release = new ReleaseInfo
|
var release = new ReleaseInfo
|
||||||
{
|
{
|
||||||
Category = MapTrackerCatToNewznab(testcat.ToString()),
|
Category = MapTrackerCatToNewznab(cat),
|
||||||
Title = name,
|
Title = name,
|
||||||
Seeders = seeders,
|
Seeders = seeders,
|
||||||
Peers = seeders + leechers,
|
Peers = seeders + leechers,
|
||||||
@@ -398,19 +375,19 @@ namespace Jackett.Common.Indexers
|
|||||||
MinimumSeedTime = 172800 // 48 hours
|
MinimumSeedTime = 172800 // 48 hours
|
||||||
};
|
};
|
||||||
|
|
||||||
var genres = tRow.Find("span.genres").Text();
|
var genres = row.QuerySelector("span.genres")?.TextContent;
|
||||||
if (!string.IsNullOrEmpty(genres))
|
if (!string.IsNullOrEmpty(genres))
|
||||||
release.Description = genres;
|
release.Description = genres;
|
||||||
|
|
||||||
// IMDB
|
// IMDB
|
||||||
var imdbLink = tRow.Find("a[href*=\"imdb.com/title/tt\"]").First().Attr("href");
|
var imdbLink = row.QuerySelector("a[href*=\"imdb.com/title/tt\"]")?.GetAttribute("href");
|
||||||
release.Imdb = ParseUtil.GetLongFromString(imdbLink);
|
release.Imdb = ParseUtil.GetLongFromString(imdbLink);
|
||||||
|
|
||||||
if (tRow.Find("img[title=\"100% freeleech\"]").Length >= 1)
|
if (row.QuerySelector("img[title=\"100% freeleech\"]") != null)
|
||||||
release.DownloadVolumeFactor = 0;
|
release.DownloadVolumeFactor = 0;
|
||||||
else if (tRow.Find("img[title=\"Halfleech\"]").Length >= 1)
|
else if (row.QuerySelector("img[title=\"Halfleech\"]") != null)
|
||||||
release.DownloadVolumeFactor = 0.5;
|
release.DownloadVolumeFactor = 0.5;
|
||||||
else if (tRow.Find("img[title=\"90% Freeleech\"]").Length >= 1)
|
else if (row.QuerySelector("img[title=\"90% Freeleech\"]") != null)
|
||||||
release.DownloadVolumeFactor = 0.1;
|
release.DownloadVolumeFactor = 0.1;
|
||||||
else
|
else
|
||||||
release.DownloadVolumeFactor = 1;
|
release.DownloadVolumeFactor = 1;
|
||||||
@@ -630,13 +607,9 @@ namespace Jackett.Common.Indexers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Find torrent rows in search pages
|
/// Find torrent rows in search pages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>JQuery Object</returns>
|
/// <returns>List of rows</returns>
|
||||||
private CQ FindTorrentRows()
|
private IHtmlCollection<IElement> FindTorrentRows(IHtmlDocument dom) =>
|
||||||
{
|
dom.QuerySelectorAll("#torrentTable > tbody > tr").Skip(1).ToCollection();
|
||||||
// Return all occurencis of torrents found
|
|
||||||
//return _fDom["#content > table > tr"];
|
|
||||||
return _fDom["# torrentTable > tbody > tr:not(:first)"];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Download torrent file from tracker
|
/// Download torrent file from tracker
|
||||||
|
Reference in New Issue
Block a user