diff --git a/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs b/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs index 42623e0e2..54318e20f 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs @@ -252,83 +252,72 @@ namespace NzbDrone.Core.Indexers.Definitions foreach (var torrent in group.Torrents) { - const string defaultReleaseInfo = "S01"; - var releaseInfo = defaultReleaseInfo; - string episode = null; + var releaseInfo = _settings.EnableSonarrCompatibility ? "S01" : ""; + int? episode = null; int? season = null; var editionTitle = torrent.EditionData.EditionTitle; if (!string.IsNullOrWhiteSpace(editionTitle)) { releaseInfo = WebUtility.HtmlDecode(editionTitle); - var simpleSeasonRegEx = new Regex(@"Season (\d+)", RegexOptions.Compiled); - var simpleSeasonRegExMatch = simpleSeasonRegEx.Match(releaseInfo); - if (simpleSeasonRegExMatch.Success) + if (_settings.EnableSonarrCompatibility) { - season = ParseUtil.CoerceInt(simpleSeasonRegExMatch.Groups[1].Value); + var simpleSeasonRegEx = new Regex(@"Season (\d+)", RegexOptions.Compiled); + var simpleSeasonRegExMatch = simpleSeasonRegEx.Match(releaseInfo); + if (simpleSeasonRegExMatch.Success) + { + season = ParseUtil.CoerceInt(simpleSeasonRegExMatch.Groups[1].Value); + } } var episodeRegEx = new Regex(@"Episode (\d+)", RegexOptions.Compiled); var episodeRegExMatch = episodeRegEx.Match(releaseInfo); if (episodeRegExMatch.Success) { - episode = episodeRegExMatch.Groups[1].Value; + episode = ParseUtil.CoerceInt(episodeRegExMatch.Groups[1].Value); } } - var advancedSeasonRegEx = new Regex(@"(\d+)(st|nd|rd|th) Season", RegexOptions.Compiled | RegexOptions.IgnoreCase); - var advancedSeasonRegExMatch = advancedSeasonRegEx.Match(mainTitle); - if (advancedSeasonRegExMatch.Success) + if (_settings.EnableSonarrCompatibility) { - season = ParseUtil.CoerceInt(advancedSeasonRegExMatch.Groups[1].Value); - } + var advancedSeasonRegEx = new Regex(@"(\d+)(st|nd|rd|th) Season", RegexOptions.Compiled | RegexOptions.IgnoreCase); + var advancedSeasonRegExMatch = advancedSeasonRegEx.Match(mainTitle); + if (advancedSeasonRegExMatch.Success) + { + season = ParseUtil.CoerceInt(advancedSeasonRegExMatch.Groups[1].Value); + } - var seasonCharactersRegEx = new Regex(@"(I{2,})$", RegexOptions.Compiled); - var seasonCharactersRegExMatch = seasonCharactersRegEx.Match(mainTitle); - if (seasonCharactersRegExMatch.Success) - { - season = seasonCharactersRegExMatch.Groups[1].Value.Length; - } + var seasonCharactersRegEx = new Regex(@"(I{2,})$", RegexOptions.Compiled); + var seasonCharactersRegExMatch = seasonCharactersRegEx.Match(mainTitle); + if (seasonCharactersRegExMatch.Success) + { + season = seasonCharactersRegExMatch.Groups[1].Value.Length; + } - var seasonNumberRegEx = new Regex(@"([2-9])$", RegexOptions.Compiled); - var seasonNumberRegExMatch = seasonNumberRegEx.Match(mainTitle); - if (seasonNumberRegExMatch.Success) - { - season = ParseUtil.CoerceInt(seasonNumberRegExMatch.Groups[1].Value); + var seasonNumberRegEx = new Regex(@"([2-9])$", RegexOptions.Compiled); + var seasonNumberRegExMatch = seasonNumberRegEx.Match(mainTitle); + if (seasonNumberRegExMatch.Success) + { + season = ParseUtil.CoerceInt(seasonNumberRegExMatch.Groups[1].Value); + } } - var foundSeason = false; - - if (season != null) + if (episode != null) { - releaseInfo = $"Season {season}"; - - foundSeason = true; + releaseInfo = episode is > 0 and < 10 + ? "0" + episode + : episode.ToString(); } - - if (episode != null) + else { - var epString = $"Episode {episode}"; - - if (foundSeason) - { - releaseInfo += $" {epString}"; - } - else + if (season != null && _settings.EnableSonarrCompatibility) { - releaseInfo = epString; + releaseInfo = $"S{season}"; } } - releaseInfo = releaseInfo.Replace("Episode ", string.Empty); - releaseInfo = releaseInfo.Replace("Season ", "S"); releaseInfo = releaseInfo.Trim(); - if (int.TryParse(releaseInfo, out _) && releaseInfo.Length == 1) - { - releaseInfo = "0" + releaseInfo; - } - var torrentId = torrent.Id; var property = torrent.Property.Replace(" | Freeleech", string.Empty); var link = torrent.Link; @@ -503,6 +492,7 @@ namespace NzbDrone.Core.Indexers.Definitions { Passkey = ""; Username = ""; + EnableSonarrCompatibility = true; } [FieldDefinition(1, Label = "Base Url", Type = FieldType.Select, SelectOptionsProviderAction = "getUrls", HelpText = "Select which baseurl Prowlarr will use for requests to the site")] @@ -514,7 +504,10 @@ namespace NzbDrone.Core.Indexers.Definitions [FieldDefinition(3, Label = "Username", HelpText = "Site Username", Privacy = PrivacyLevel.UserName)] public string Username { get; set; } - [FieldDefinition(4)] + [FieldDefinition(4, Label = "Enable Sonarr Compatibility", Type = FieldType.Checkbox, HelpText = "Makes Prowlarr try to add Season information into Release names, without this Sonarr can't match any Seasons, but it has a lot of false positives as well")] + public bool EnableSonarrCompatibility { get; set; } + + [FieldDefinition(5)] public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); public NzbDroneValidationResult Validate()