iptorrents: some fixes and code cleanup (#8034)

* Add SupportsImdbTVSearch
* Fix 4k category
* Remove files code, not available in the website
* Add description
* Add configuration advice
* Code cleanup

Tested
This commit is contained in:
Diego Heras
2020-04-04 22:34:19 +02:00
committed by GitHub
parent 4fa14efc89
commit 45e5d032f7

View File

@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AngleSharp.Html.Parser; using AngleSharp.Html.Parser;
@@ -17,7 +16,7 @@ namespace Jackett.Common.Indexers
{ {
public class IPTorrents : BaseWebIndexer public class IPTorrents : BaseWebIndexer
{ {
private string BrowseUrl => SiteLink + "t"; private string SearchUrl => SiteLink + "t";
public override string[] AlternativeSiteLinks { get; protected set; } = { public override string[] AlternativeSiteLinks { get; protected set; } = {
"https://iptorrents.com/", "https://iptorrents.com/",
@@ -42,25 +41,22 @@ namespace Jackett.Common.Indexers
"https://ipt.world/", "https://ipt.world/",
}; };
private new ConfigurationDataCookie configData private new ConfigurationDataCookie configData => (ConfigurationDataCookie)base.configData;
{
get => (ConfigurationDataCookie)base.configData;
set => base.configData = value;
}
public IPTorrents(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps) public IPTorrents(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
: base(name: "IPTorrents", : base("IPTorrents",
description: "Always a step ahead.", description: "Always a step ahead.",
link: "https://iptorrents.com/", link: "https://iptorrents.com/",
caps: new TorznabCapabilities caps: new TorznabCapabilities
{ {
SupportsImdbMovieSearch = true SupportsImdbMovieSearch = true,
SupportsImdbTVSearch = true
}, },
configService: configService, configService: configService,
client: wc, client: wc,
logger: l, logger: l,
p: ps, p: ps,
configData: new ConfigurationDataCookie()) configData: new ConfigurationDataCookie("For best results, change the 'Torrents per page' option to 100 in the website Settings."))
{ {
Encoding = Encoding.UTF8; Encoding = Encoding.UTF8;
Language = "en-us"; Language = "en-us";
@@ -69,7 +65,7 @@ namespace Jackett.Common.Indexers
AddCategoryMapping(72, TorznabCatType.Movies, "Movies"); AddCategoryMapping(72, TorznabCatType.Movies, "Movies");
AddCategoryMapping(87, TorznabCatType.Movies3D, "Movie/3D"); AddCategoryMapping(87, TorznabCatType.Movies3D, "Movie/3D");
AddCategoryMapping(77, TorznabCatType.MoviesSD, "Movie/480p"); AddCategoryMapping(77, TorznabCatType.MoviesSD, "Movie/480p");
AddCategoryMapping(101, TorznabCatType.MoviesHD, "Movie/4K"); AddCategoryMapping(101, TorznabCatType.MoviesUHD, "Movie/4K");
AddCategoryMapping(89, TorznabCatType.MoviesHD, "Movie/BD-R"); AddCategoryMapping(89, TorznabCatType.MoviesHD, "Movie/BD-R");
AddCategoryMapping(90, TorznabCatType.MoviesSD, "Movie/BD-Rip"); AddCategoryMapping(90, TorznabCatType.MoviesSD, "Movie/BD-Rip");
AddCategoryMapping(96, TorznabCatType.MoviesSD, "Movie/Cam"); AddCategoryMapping(96, TorznabCatType.MoviesSD, "Movie/Cam");
@@ -165,22 +161,19 @@ 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 searchString = query.GetQueryString();
var searchUrl = BrowseUrl;
var queryCollection = new NameValueCollection();
if (!string.IsNullOrWhiteSpace(query.ImdbID)) var qc = new NameValueCollection();
queryCollection.Add("q", query.ImdbID);
else if (!string.IsNullOrWhiteSpace(searchString)) if (query.IsImdbQuery)
queryCollection.Add("q", searchString); qc.Add("q", query.ImdbID);
else if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
qc.Add("q", query.GetQueryString());
foreach (var cat in MapTorznabCapsToTrackers(query)) foreach (var cat in MapTorznabCapsToTrackers(query))
queryCollection.Add(cat, string.Empty); qc.Add(cat, string.Empty);
if (queryCollection.Count > 0) var searchUrl = SearchUrl + "?" + qc.GetQueryString();
searchUrl += "?" + queryCollection.GetQueryString(); var response = await RequestStringWithCookiesAndRetry(searchUrl, null, SearchUrl);
var response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);
var results = response.Content; var results = response.Content;
if (results == null || !results.Contains("/lout.php")) if (results == null || !results.Contains("/lout.php"))
@@ -191,54 +184,60 @@ namespace Jackett.Common.Indexers
try try
{ {
var htmlParser = new HtmlParser(); var parser = new HtmlParser();
var dom = htmlParser.ParseDocument(results); var doc = parser.ParseDocument(results);
var rows = dom.QuerySelectorAll("table[id='torrents'] > tbody > tr"); var rows = doc.QuerySelectorAll("table[id='torrents'] > tbody > tr");
foreach (var row in rows.Skip(1)) foreach (var row in rows.Skip(1))
{ {
var release = new ReleaseInfo();
var qTitleLink = row.QuerySelector("a[href^=\"/details.php?id=\"]"); var qTitleLink = row.QuerySelector("a[href^=\"/details.php?id=\"]");
// drop invalid char that seems to have cropped up in some titles. #6582 // drop invalid char that seems to have cropped up in some titles. #6582
release.Title = qTitleLink?.TextContent.Trim().Replace("\u000f", ""); var title = qTitleLink.TextContent.Trim().Replace("\u000f", "");
var comments = new Uri(SiteLink + qTitleLink.GetAttribute("href").TrimStart('/'));
// If we search an get no results, we still get a table just with no info.
if (string.IsNullOrWhiteSpace(release.Title))
break;
release.Guid = new Uri(SiteLink + qTitleLink.GetAttribute("href").Substring(1));
release.Comments = release.Guid;
var descString = row.QuerySelector(".t_ctime").TextContent;
var dateString = descString.Split('|').Last().Trim();
dateString = dateString.Split(new[] { " by " }, StringSplitOptions.None)[0];
release.PublishDate = DateTimeUtil.FromTimeAgo(dateString);
var qLink = row.QuerySelector("a[href^=\"/download.php/\"]"); var qLink = row.QuerySelector("a[href^=\"/download.php/\"]");
release.Link = new Uri(SiteLink + WebUtility.UrlEncode(qLink.GetAttribute("href").TrimStart('/'))); var link = new Uri(SiteLink + qLink.GetAttribute("href").TrimStart('/'));
var sizeStr = row.Children[5].TextContent; var descrSplit = row.QuerySelector(".t_ctime").TextContent.Split('|');
release.Size = ReleaseInfo.GetBytes(sizeStr); var dateSplit = descrSplit.Last().Trim().Split(new[] { " by " }, StringSplitOptions.None);
var publishDate = DateTimeUtil.FromTimeAgo(dateSplit.First());
release.Seeders = ParseUtil.CoerceInt(row.QuerySelector(".t_seeders").TextContent.Trim()); var description = descrSplit.Length > 1 ? "Tags: " + descrSplit.First().Trim() : "";
release.Peers = ParseUtil.CoerceInt(row.QuerySelector(".t_leechers").TextContent.Trim()) + release.Seeders; if (dateSplit.Length > 1)
description += " Uploader: " + dateSplit.Last();
description = description.Trim();
var catIcon = row.QuerySelector("td:nth-of-type(1) a"); var catIcon = row.QuerySelector("td:nth-of-type(1) a");
if (catIcon != null) // Torrents - Category column == Icons if (catIcon == null)
release.Category = MapTrackerCatToNewznab(catIcon.GetAttribute("href").Substring(1)); // Torrents - Category column == Text or Code
else // Torrents - Category column == Text or Code
// release.Category = MapTrackerCatDescToNewznab(row.Cq().Find("td:eq(0)").Text()); // Works for "Text" but only contains the parent category // release.Category = MapTrackerCatDescToNewznab(row.Cq().Find("td:eq(0)").Text()); // Works for "Text" but only contains the parent category
throw new Exception("Please go to " + SiteLink + "settings.php and change the \"Torrents - Category column\" option to \"Icons\". Wait a minute (cache) and then try again."); throw new Exception("Please, change the 'Torrents - Category column' option to 'Icons' in the website Settings. Wait a minute (cache) and then try again.");
// Torrents - Category column == Icons
var cat = MapTrackerCatToNewznab(catIcon.GetAttribute("href").Substring(1));
var filesElement = row.QuerySelector("a[href*=\"/files\"]"); // optional var grabs = ParseUtil.CoerceInt(row.QuerySelector("td:nth-last-child(3)").TextContent);
if (filesElement != null) var size = ReleaseInfo.GetBytes(row.Children[5].TextContent);
release.Files = ParseUtil.CoerceLong(filesElement.TextContent); var seeders = ParseUtil.CoerceInt(row.QuerySelector(".t_seeders").TextContent.Trim());
var leechers = ParseUtil.CoerceInt(row.QuerySelector(".t_leechers").TextContent.Trim());
var dlVolumeFactor = row.QuerySelector("span.t_tag_free_leech") != null ? 0 : 1;
var grabs = row.QuerySelector("td:nth-last-child(3)").TextContent; var release = new ReleaseInfo
release.Grabs = ParseUtil.CoerceInt(grabs); {
Title = title,
release.DownloadVolumeFactor = row.QuerySelector("span.t_tag_free_leech") != null ? 0 : 1; Comments = comments,
release.UploadVolumeFactor = 1; Guid = comments,
Link = link,
PublishDate = publishDate,
Category = cat,
Description = description,
Size = size,
Grabs = grabs,
Seeders = seeders,
Peers = seeders + leechers,
DownloadVolumeFactor = dlVolumeFactor,
UploadVolumeFactor = 1,
MinimumRatio = 1,
MinimumSeedTime = 1209600 // 336 hours
};
releases.Add(release); releases.Add(release);
} }