From 6d134750ffd46195b3251417503f92bee869717a Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 27 Nov 2023 05:32:50 +0200 Subject: [PATCH] New: (Redacted) Add Freeload Only option --- .../Indexers/Definitions/Redacted.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs b/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs index b54bf41990f..a3c5356cb95 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs @@ -193,6 +193,11 @@ private IEnumerable GetPagedRequests(SearchCriteriaBase searchCr queryCats.ForEach(cat => parameters.Set($"filter_cat[{cat}]", "1")); } + if (_settings.FreeloadOnly) + { + parameters.Set("freetorrent", "4"); + } + var searchUrl = _settings.BaseUrl.TrimEnd('/') + $"/ajax.php?{parameters.GetQueryString()}"; var request = new IndexerRequest(searchUrl, HttpAccept.Json); @@ -242,6 +247,12 @@ public IList ParseResponse(IndexerResponse indexerResponse) { foreach (var torrent in result.Torrents) { + // skip non-freeload results when freeload only is set + if (_settings.FreeloadOnly && !torrent.IsFreeload) + { + continue; + } + var id = torrent.TorrentId; var title = GetTitle(result, torrent); @@ -251,7 +262,7 @@ public IList ParseResponse(IndexerResponse indexerResponse) { Guid = infoUrl, InfoUrl = infoUrl, - DownloadUrl = GetDownloadUrl(id, torrent.CanUseToken), + DownloadUrl = GetDownloadUrl(id, torrent.CanUseToken && !torrent.IsFreeload), Title = WebUtility.HtmlDecode(title), Artist = WebUtility.HtmlDecode(result.Artist), Album = WebUtility.HtmlDecode(result.GroupName), @@ -286,6 +297,12 @@ public IList ParseResponse(IndexerResponse indexerResponse) // Non-Audio files are formatted a little differently (1:1 for group and torrents) else { + // skip non-freeload results when freeload only is set + if (_settings.FreeloadOnly && !result.IsFreeload) + { + continue; + } + var id = result.TorrentId; var infoUrl = GetInfoUrl(result.GroupId, id); @@ -294,7 +311,7 @@ public IList ParseResponse(IndexerResponse indexerResponse) Guid = infoUrl, Title = WebUtility.HtmlDecode(result.GroupName), Size = long.Parse(result.Size), - DownloadUrl = GetDownloadUrl(id, result.CanUseToken), + DownloadUrl = GetDownloadUrl(id, result.CanUseToken && !result.IsFreeload), InfoUrl = infoUrl, Seeders = int.Parse(result.Seeders), Peers = int.Parse(result.Leechers) + int.Parse(result.Seeders), @@ -394,12 +411,15 @@ public RedactedSettings() UseFreeleechToken = false; } - [FieldDefinition(2, Label = "API Key", HelpText = "API Key from the Site (Found in Settings => Access Settings)", Privacy = PrivacyLevel.ApiKey)] + [FieldDefinition(2, Label = "API Key", Privacy = PrivacyLevel.ApiKey, HelpText = "API Key from the Site (Found in Settings => Access Settings)")] public string Apikey { get; set; } - [FieldDefinition(3, Label = "Use Freeleech Tokens", HelpText = "Use freeleech tokens when available", Type = FieldType.Checkbox)] + [FieldDefinition(3, Label = "Use Freeleech Tokens", Type = FieldType.Checkbox, HelpText = "Use freeleech tokens when available")] public bool UseFreeleechToken { get; set; } + [FieldDefinition(4, Label = "Freeload Only", Type = FieldType.Checkbox, Advanced = true, HelpTextWarning = "Search freeload torrents only. End date: 6 January 2024, 23:59 UTC.")] + public bool FreeloadOnly { get; set; } + public override NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this));