From 87b5500c84ea3e953f81a281186fa26e92815b17 Mon Sep 17 00:00:00 2001 From: XYZJR <50780760+XYZJR@users.noreply.github.com> Date: Tue, 23 Feb 2021 06:24:02 +0100 Subject: [PATCH] RuTracker: Add config option to move tags to end of release title. Resolves #11109 (#11125) --- src/Jackett.Common/Indexers/RuTracker.cs | 45 +++++++++++++++++++ .../Bespoke/ConfigurationDataRutracker.cs | 11 +++++ 2 files changed, 56 insertions(+) diff --git a/src/Jackett.Common/Indexers/RuTracker.cs b/src/Jackett.Common/Indexers/RuTracker.cs index 9ed906fcd..b82465c09 100644 --- a/src/Jackett.Common/Indexers/RuTracker.cs +++ b/src/Jackett.Common/Indexers/RuTracker.cs @@ -34,6 +34,8 @@ namespace Jackett.Common.Indexers "https://rutracker.net/" }; + private Regex _regexToFindTagsInReleaseTitle = new Regex(@"\[[^\[]+\]|\([^(]+\)"); + public RuTracker(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps, ICacheService cs) : base(id: "rutracker", @@ -1526,6 +1528,15 @@ namespace Jackett.Common.Indexers release.Title = regex.Replace(release.Title, ""); } + if (configData.MoveAllTagsToEndOfReleaseTitle.Value) + { + release.Title = MoveAllTagsToEndOfReleaseTitle(release.Title); + } + else if (configData.MoveFirstTagsToEndOfReleaseTitle.Value) + { + release.Title = MoveFirstTagsToEndOfReleaseTitle(release.Title); + } + releases.Add(release); } catch (Exception ex) @@ -1540,5 +1551,39 @@ namespace Jackett.Common.Indexers return releases; } + + private string MoveAllTagsToEndOfReleaseTitle(string input) + { + var output = input + " "; + foreach (Match match in _regexToFindTagsInReleaseTitle.Matches(input)) + { + var tag = match.ToString(); + output = output.Replace(tag, "") + tag; + } + output = output.Trim(); + return output; + } + + private string MoveFirstTagsToEndOfReleaseTitle(string input) + { + var output = input + " "; + var expectedIndex = 0; + foreach (Match match in _regexToFindTagsInReleaseTitle.Matches(input)) + { + if (match.Index > expectedIndex) + { + var substring = input.Substring(expectedIndex, match.Index - expectedIndex); + if (string.IsNullOrWhiteSpace(substring)) + expectedIndex = match.Index; + else + break; + } + var tag = match.ToString(); + output = output.Replace(tag, "") + tag; + expectedIndex += tag.Length; + } + output = output.Trim(); + return output; + } } } diff --git a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataRutracker.cs b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataRutracker.cs index 940ba27ee..2f0eec418 100644 --- a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataRutracker.cs +++ b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataRutracker.cs @@ -6,12 +6,23 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke internal class ConfigurationDataRutracker : ConfigurationDataCaptchaLogin { public BoolItem StripRussianLetters { get; private set; } + public DisplayItem MoveTagsInfo { get; private set; } + public BoolItem MoveFirstTagsToEndOfReleaseTitle { get; private set; } + public BoolItem MoveAllTagsToEndOfReleaseTitle { get; private set; } public DisplayItem CaptchaWarning { get; private set; } public ConfigurationDataRutracker() : base() { StripRussianLetters = new BoolItem() { Name = "Strip Russian Letters", Value = true }; + MoveTagsInfo = new DisplayItem("About moving tags: "+ + "We define a tag as a part of the release title between round or square brackets. "+ + "If the release title contains tags then these options will move those tags and their brackets to the end of the release title. "+ + "Moving only the first tags will try to detect where the actual title of the release begins, and move only the tags that are found before that point. "+ + "Enabling both options will enable moving of all tags.") + { Name = "Move Tags Info" }; + MoveFirstTagsToEndOfReleaseTitle = new BoolItem() { Name = "Move first tags to end of release title", Value = false }; + MoveAllTagsToEndOfReleaseTitle = new BoolItem() { Name = "Move all tags to end of release title", Value = false }; CaptchaWarning = new DisplayItem("About Captcha: If the Captcha Image is missing then leave the Captcha Text empty.") { Name = "Captcha Info" }; } }