hd-torrents: Add global freeleech check. resolves #7734 (#7751)

This commit is contained in:
Cory 2020-03-20 16:58:31 -05:00 committed by GitHub
parent 869b09f574
commit b2040d3a5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 43 deletions

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
@ -49,6 +50,7 @@ namespace Jackett.Common.Indexers
Type = "private";
TorznabCaps.SupportsImdbMovieSearch = true;
TorznabCaps.SupportsImdbTVSearch = true;
TorznabCaps.Categories.Clear();
@ -107,22 +109,17 @@ namespace Jackett.Common.Indexers
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var releases = new List<ReleaseInfo>();
var searchUrl = SearchUrl;// string.Format(SearchUrl, HttpUtility.UrlEncode()));
var queryCollection = new NameValueCollection();
var searchString = query.GetQueryString();
var searchUrl = SearchUrl + string.Join(
string.Empty, MapTorznabCapsToTrackers(query).Select(cat => $"category[]={cat}&"));
var queryCollection = new NameValueCollection
{
{"search", query.ImdbID ?? query.GetQueryString()},
{"active", "0"},
{"options", "0"}
};
foreach (var cat in MapTorznabCapsToTrackers(query))
searchUrl += "category%5B%5D=" + cat + "&";
if (query.ImdbID != null)
queryCollection.Add("search", query.ImdbID);
else if (!string.IsNullOrWhiteSpace(searchString))
queryCollection.Add("search", searchString);
queryCollection.Add("active", "0");
queryCollection.Add("options", "0");
searchUrl += queryCollection.GetQueryString().Replace("(", "%28").Replace(")", "%29"); // maually url encode brackets to prevent "hacking" detection
// manually url encode parenthesis to prevent "hacking" detection
searchUrl += queryCollection.GetQueryString().Replace("(", "%28").Replace(")", "%29");
var results = await RequestStringWithCookiesAndRetry(searchUrl);
try
@ -130,8 +127,8 @@ namespace Jackett.Common.Indexers
var parser = new HtmlParser();
var dom = parser.ParseDocument(results.Content);
var userInfo = dom.QuerySelector(".mainmenu > table > tbody > tr:has(td[title=\"Active-Torrents\"])");
var rank = userInfo.QuerySelector("td:nth-child(2)").TextContent.Substring(6);
var userInfo = dom.QuerySelector("table.navus tr");
var rank = userInfo.Children[1].TextContent.Replace("Rank:", string.Empty).Trim();
var freeleechRanks = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
@ -144,48 +141,52 @@ namespace Jackett.Common.Indexers
};
var hasFreeleech = freeleechRanks.Contains(rank);
var rows = dom.QuerySelectorAll(".mainblockcontenttt > tbody > tr:has(a[href^=\"details.php?id=\"])");
foreach (var row in rows)
var rows = dom.QuerySelectorAll("table.mainblockcontenttt tr:has(td.mainblockcontent)");
foreach (var row in rows.Skip(1))
{
var release = new ReleaseInfo();
release.Title = row.QuerySelector("td.mainblockcontent b a").TextContent;
release.Description = row.QuerySelector("td:nth-child(3) > span").TextContent;
var mainLink = row.Children[2].QuerySelector("a");
release.Title = mainLink.TextContent;
release.Description = row.Children[2].QuerySelector("span").TextContent;
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800; // 48 hours
var tdIndex = 0;
if (row.QuerySelector("td:nth-last-child(1)").TextContent == "Edit")
tdIndex = 1;
// moderators get additional delete, recomend and like links
if (row.QuerySelector("td:nth-last-child(4)").TextContent == "Edit")
tdIndex = 4;
// Sometimes the uploader column is missing, so seeders, leechers, and grabs may be at a different index.
// There's room for improvement, but this works for now.
var endIndex = row.Children.Length;
// Sometimes the uploader column is missing
if (ParseUtil.TryCoerceInt(row.QuerySelector($"td:nth-last-child({tdIndex + 3})").TextContent, out var seeders))
//Maybe use row.Children.Index(Node) after searching for an element instead?
if (row.Children[endIndex - 1].TextContent == "Edit")
endIndex -= 1;
// moderators get additional delete, recommend and like links
else if (row.Children[endIndex - 4].TextContent == "Edit")
endIndex -= 4;
if (ParseUtil.TryCoerceInt(row.Children[endIndex - 3].TextContent, out var seeders))
{
release.Seeders = seeders;
if (ParseUtil.TryCoerceInt(row.QuerySelector($"td:nth-last-child({tdIndex + 2})").TextContent, out var peers))
if (ParseUtil.TryCoerceInt(row.Children[endIndex - 2].TextContent, out var peers))
release.Peers = peers + release.Seeders;
}
// Sometimes the grabs column is missing
if (ParseUtil.TryCoerceLong(row.QuerySelector($"td:nth-last-child({tdIndex + 1})").TextContent, out var grabs))
if (ParseUtil.TryCoerceLong(row.Children[endIndex - 1].TextContent, out var grabs))
release.Grabs = grabs;
var fullSize = row.QuerySelectorAll("td.mainblockcontent")[6].TextContent;
var fullSize = row.Children[7].TextContent;
release.Size = ReleaseInfo.GetBytes(fullSize);
release.Guid = new Uri(SiteLink + row.QuerySelector("td.mainblockcontent b a").GetAttribute("href"));
release.Link = new Uri(SiteLink + row.QuerySelectorAll("td.mainblockcontent")[3].FirstElementChild.GetAttribute("href"));
release.Comments = new Uri(SiteLink + row.QuerySelector("td.mainblockcontent b a").GetAttribute("href"));
release.Guid = new Uri(SiteLink + mainLink.GetAttribute("href"));
release.Link = new Uri(SiteLink + row.Children[4].FirstElementChild.GetAttribute("href"));
release.Comments = new Uri(SiteLink + mainLink.GetAttribute("href"));
var dateSplit = row.QuerySelectorAll("td.mainblockcontent")[5].InnerHtml.Split(',');
var dateString = dateSplit[1].Substring(0, dateSplit[1].IndexOf('>')).Replace("=\"\"", "").Trim();
var dateTag = row.Children[6].FirstElementChild;
var dateString = string.Join(" ", dateTag.Attributes.Select(attr => attr.Name));
release.PublishDate = DateTime.ParseExact(dateString, "dd MMM yyyy HH:mm:ss zz00", CultureInfo.InvariantCulture).ToLocalTime();
var category = row.QuerySelector("td:nth-of-type(1) a").GetAttribute("href").Replace("torrents.php?category=", "");
var category = row.FirstElementChild.FirstElementChild.GetAttribute("href").Split('=')[1];
release.Category = MapTrackerCatToNewznab(category);
release.UploadVolumeFactor = 1;
@ -195,7 +196,7 @@ namespace Jackett.Common.Indexers
release.DownloadVolumeFactor = 0;
release.UploadVolumeFactor = 0;
}
else if (hasFreeleech)
else if (hasFreeleech || row.QuerySelector("img[alt=\"Golden Torrent\"]") != null)
release.DownloadVolumeFactor = 0;
else if (row.QuerySelector("img[alt=\"Silver Torrent\"]") != null)
release.DownloadVolumeFactor = 0.5;
@ -206,9 +207,9 @@ namespace Jackett.Common.Indexers
else
release.DownloadVolumeFactor = 1;
var imdblink = row.QuerySelector("a[href*=\"www.imdb.com/title/\"]")?.GetAttribute("href");
if (!string.IsNullOrWhiteSpace(imdblink))
release.Imdb = ParseUtil.GetLongFromString(imdblink);
var imdbLink = row.QuerySelector("a[href*=\"www.imdb.com/title/\"]")?.GetAttribute("href");
if (!string.IsNullOrWhiteSpace(imdbLink))
release.Imdb = ParseUtil.GetLongFromString(imdbLink);
releases.Add(release);
}