From e0c6a3b46953d41ec611a59bdbaaa8d0735e6ac5 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 5 Feb 2023 04:30:20 +0200 Subject: [PATCH] immortalseed: category filtering and add sorting to skip sticky results (#13972) Also check for Sitewide Free Torrent. xspeeds: check for Sitewide Free Torrent. --- src/Jackett.Common/Indexers/ImmortalSeed.cs | 60 ++++++++++++++++++--- src/Jackett.Common/Indexers/XSpeeds.cs | 8 +-- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/Jackett.Common/Indexers/ImmortalSeed.cs b/src/Jackett.Common/Indexers/ImmortalSeed.cs index 43a336e1b..6e785522d 100644 --- a/src/Jackett.Common/Indexers/ImmortalSeed.cs +++ b/src/Jackett.Common/Indexers/ImmortalSeed.cs @@ -14,15 +14,15 @@ using Jackett.Common.Services.Interfaces; using Jackett.Common.Utils; using Newtonsoft.Json.Linq; using NLog; +using static Jackett.Common.Models.IndexerConfig.ConfigurationData; namespace Jackett.Common.Indexers { [ExcludeFromCodeCoverage] public class ImmortalSeed : BaseWebIndexer { - private string BrowsePage => SiteLink + "browse.php"; + private string SearchUrl => SiteLink + "browse.php"; private string LoginUrl => SiteLink + "takelogin.php"; - private string QueryString => "?do=search&keywords={0}&search_type=t_name&category=0&include_dead_torrents=no"; private readonly Regex _dateMatchRegex = new Regex(@"\d{4}-\d{2}-\d{2} \d{2}:\d{2} [AaPp][Mm]", RegexOptions.Compiled); public override string[] LegacySiteLinks { get; protected set; } = { @@ -116,8 +116,35 @@ namespace Jackett.Common.Indexers AddCategoryMapping(63, TorznabCatType.TVUHD, "TV Season Packs - 4K"); AddCategoryMapping(4, TorznabCatType.TVHD, "TV Season Packs - HD"); AddCategoryMapping(6, TorznabCatType.TVSD, "TV Season Packs - SD"); + + // Configure the sort selects + var sortBySelect = new SingleSelectConfigurationItem( + "Sort by", + new Dictionary + { + { "added", "created" }, + { "seeders", "seeders" }, + { "size", "size" }, + { "name", "title" } + }) + { Value = "added" }; + configData.AddDynamic("sortrequestedfromsite", sortBySelect); + + var orderSelect = new SingleSelectConfigurationItem( + "Order", + new Dictionary + { + { "desc", "descending" }, + { "asc", "ascending" } + }) + { Value = "desc" }; + configData.AddDynamic("orderrequestedfromsite", orderSelect); } + private string GetSortBy => ((SingleSelectConfigurationItem)configData.GetDynamic("sortrequestedfromsite")).Value; + + private string GetOrder => ((SingleSelectConfigurationItem)configData.GetDynamic("orderrequestedfromsite")).Value; + public override async Task ApplyConfiguration(JToken configJson) { LoadValuesFromJson(configJson); @@ -143,11 +170,28 @@ namespace Jackett.Common.Indexers protected override async Task> PerformQuery(TorznabQuery query) { - var releases = new List(); - var searchUrl = BrowsePage; + var searchParams = new Dictionary + { + { "category", "0" }, + { "include_dead_torrents", "yes" }, + { "sort", GetSortBy }, + { "order", GetOrder } + }; - if (!string.IsNullOrWhiteSpace(query.GetQueryString())) - searchUrl += string.Format(QueryString, WebUtility.UrlEncode(query.GetQueryString())); + var searchString = Regex.Replace(query.GetQueryString(), @"[ -._]+", " ").Trim(); + + if (!string.IsNullOrWhiteSpace(searchString)) + { + searchParams.Add("do", "search"); + searchParams.Add("keywords", searchString); + searchParams.Add("search_type", "t_name"); + } + + var categoryMapping = MapTorznabCapsToTrackers(query); + if (categoryMapping.Any()) + searchParams.Add("selectedcats2", string.Join(",", categoryMapping)); + + var searchUrl = $"{SearchUrl}?{searchParams.GetQueryString()}"; var results = await RequestWithCookiesAndRetryAsync(searchUrl); @@ -158,6 +202,8 @@ namespace Jackett.Common.Indexers results = await RequestWithCookiesAndRetryAsync(searchUrl); } + var releases = new List(); + try { var parser = new HtmlParser(); @@ -207,7 +253,7 @@ namespace Jackett.Common.Indexers var cover = row.QuerySelector("td:nth-of-type(2) > div > img[src]")?.GetAttribute("src")?.Trim(); release.Poster = !string.IsNullOrEmpty(cover) && cover.StartsWith("/") ? new Uri(SiteLink + cover.TrimStart('/')) : null; - if (row.QuerySelector("img[title^=\"Free Torrent\"]") != null) + if (row.QuerySelector("img[title^=\"Free Torrent\"], img[title^=\"Sitewide Free Torrent\"]") != null) release.DownloadVolumeFactor = 0; else if (row.QuerySelector("img[title^=\"Silver Torrent\"]") != null) release.DownloadVolumeFactor = 0.5; diff --git a/src/Jackett.Common/Indexers/XSpeeds.cs b/src/Jackett.Common/Indexers/XSpeeds.cs index 36a851d8d..d4984a6d7 100644 --- a/src/Jackett.Common/Indexers/XSpeeds.cs +++ b/src/Jackett.Common/Indexers/XSpeeds.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -325,17 +324,14 @@ namespace Jackett.Common.Indexers var cover = row.QuerySelector("td:nth-of-type(2) > div > img[src]")?.GetAttribute("src")?.Trim(); release.Poster = !string.IsNullOrEmpty(cover) && cover.StartsWith("http") ? new Uri(cover) : null; - if (row.QuerySelector("img[alt^=\"Free Torrent\"]") != null) + if (row.QuerySelector("img[alt^=\"Free Torrent\"], img[alt^=\"Sitewide Free Torrent\"]") != null) release.DownloadVolumeFactor = 0; else if (row.QuerySelector("img[alt^=\"Silver Torrent\"]") != null) release.DownloadVolumeFactor = 0.5; else release.DownloadVolumeFactor = 1; - if (row.QuerySelector("img[alt^=\"x2 Torrent\"]") != null) - release.UploadVolumeFactor = 2; - else - release.UploadVolumeFactor = 1; + release.UploadVolumeFactor = row.QuerySelector("img[alt^=\"x2 Torrent\"]") != null ? 2 : 1; release.MinimumRatio = 0.8;