RuTracker: Add config option to move tags to end of release title. Resolves #11109 (#11125)

This commit is contained in:
XYZJR 2021-02-23 06:24:02 +01:00 committed by GitHub
parent 0e2342b8de
commit 87b5500c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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("<b>About moving tags:</b> "+
"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("<b>About Captcha:</b> If the Captcha Image is missing then leave the Captcha Text empty.") { Name = "Captcha Info" };
}
}