From 2b9d950f39bbb3ca77e6f84474ef90936bee9cd8 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 2 Jun 2023 23:42:00 +0300 Subject: [PATCH] speedapptracker: add freeleech only (#14415) --- .../Indexers/Abstract/SpeedAppTracker.cs | 20 ++++++++++++------- .../ConfigurationDataSpeedAppTracker.cs | 15 ++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataSpeedAppTracker.cs diff --git a/src/Jackett.Common/Indexers/Abstract/SpeedAppTracker.cs b/src/Jackett.Common/Indexers/Abstract/SpeedAppTracker.cs index 2edeeb036..c0f52ced6 100644 --- a/src/Jackett.Common/Indexers/Abstract/SpeedAppTracker.cs +++ b/src/Jackett.Common/Indexers/Abstract/SpeedAppTracker.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using Jackett.Common.Models; -using Jackett.Common.Models.IndexerConfig; +using Jackett.Common.Models.IndexerConfig.Bespoke; using Jackett.Common.Services.Interfaces; using Jackett.Common.Utils; using Jackett.Common.Utils.Clients; @@ -35,7 +35,7 @@ namespace Jackett.Common.Indexers.Abstract private string SearchUrl => SiteLink + "api/torrent"; private string _token; - private new ConfigurationDataBasicLoginWithEmail configData => (ConfigurationDataBasicLoginWithEmail)base.configData; + private new ConfigurationDataSpeedAppTracker configData => (ConfigurationDataSpeedAppTracker)base.configData; protected SpeedAppTracker(IIndexerConfigurationService configService, WebClient client, Logger logger, IProtectionService p, ICacheService cs) : base(configService: configService, @@ -43,7 +43,7 @@ namespace Jackett.Common.Indexers.Abstract logger: logger, p: p, cacheService: cs, - configData: new ConfigurationDataBasicLoginWithEmail()) + configData: new ConfigurationDataSpeedAppTracker()) { } @@ -120,8 +120,17 @@ namespace Jackett.Common.Indexers.Abstract try { var rows = JArray.Parse(response.ContentString); + foreach (var row in rows) { + var dlVolumeFactor = row.Value("download_volume_factor"); + + // skip non-freeleech results when freeleech only is set + if (configData.FreeleechOnly.Value && dlVolumeFactor != 0) + { + continue; + } + var id = row.Value("id"); var link = new Uri($"{SiteLink}api/torrent/{id}/download"); var urlStr = row.Value("url"); @@ -141,9 +150,6 @@ namespace Jackett.Common.Indexers.Abstract var posterStr = row.Value("poster"); var poster = Uri.TryCreate(posterStr, UriKind.Absolute, out var posterUri) ? posterUri : null; - var dlVolumeFactor = row.Value("download_volume_factor"); - var ulVolumeFactor = row.Value("upload_volume_factor"); - var title = row.Value("name"); // fix for #10883 if (UseP2PReleaseName && !string.IsNullOrWhiteSpace(row.Value("p2p_release_name"))) @@ -167,7 +173,7 @@ namespace Jackett.Common.Indexers.Abstract Seeders = row.Value("seeders"), Peers = row.Value("leechers") + row.Value("seeders"), DownloadVolumeFactor = dlVolumeFactor, - UploadVolumeFactor = ulVolumeFactor, + UploadVolumeFactor = row.Value("upload_volume_factor"), MinimumRatio = 1, MinimumSeedTime = minimumSeedTime }; diff --git a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataSpeedAppTracker.cs b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataSpeedAppTracker.cs new file mode 100644 index 000000000..ae3a0c6ff --- /dev/null +++ b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataSpeedAppTracker.cs @@ -0,0 +1,15 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Jackett.Common.Models.IndexerConfig.Bespoke +{ + [ExcludeFromCodeCoverage] + internal class ConfigurationDataSpeedAppTracker : ConfigurationDataBasicLoginWithEmail + { + public BoolConfigurationItem FreeleechOnly { get; private set; } + + public ConfigurationDataSpeedAppTracker() + { + FreeleechOnly = new BoolConfigurationItem("Show freeleech only") { Value = false }; + } + } +}