Fixed: (AnimeBytes) Improve season detection

pull/1604/head
Bogdan 2 years ago
parent 29f049f766
commit 12526c1bb3

@ -340,44 +340,25 @@ namespace NzbDrone.Core.Indexers.Definitions
if (_settings.EnableSonarrCompatibility) if (_settings.EnableSonarrCompatibility)
{ {
var simpleSeasonRegEx = new Regex(@"Season (\d+)", RegexOptions.Compiled); var simpleSeasonRegex = new Regex(@"Season (\d+)", RegexOptions.Compiled);
var simpleSeasonRegExMatch = simpleSeasonRegEx.Match(releaseInfo); var simpleSeasonRegexMatch = simpleSeasonRegex.Match(releaseInfo);
if (simpleSeasonRegExMatch.Success) if (simpleSeasonRegexMatch.Success)
{ {
season = ParseUtil.CoerceInt(simpleSeasonRegExMatch.Groups[1].Value); season = ParseUtil.CoerceInt(simpleSeasonRegexMatch.Groups[1].Value);
} }
} }
var episodeRegEx = new Regex(@"Episode (\d+)", RegexOptions.Compiled); var episodeRegex = new Regex(@"Episode (\d+)", RegexOptions.Compiled);
var episodeRegExMatch = episodeRegEx.Match(releaseInfo); var episodeRegexMatch = episodeRegex.Match(releaseInfo);
if (episodeRegExMatch.Success) if (episodeRegexMatch.Success)
{ {
episode = ParseUtil.CoerceInt(episodeRegExMatch.Groups[1].Value); episode = ParseUtil.CoerceInt(episodeRegexMatch.Groups[1].Value);
} }
} }
if (_settings.EnableSonarrCompatibility) if (_settings.EnableSonarrCompatibility && season == null)
{ {
var advancedSeasonRegEx = new Regex(@"(\d+)(st|nd|rd|th) Season", RegexOptions.Compiled | RegexOptions.IgnoreCase); season = ParseSeasonFromTitles(synonyms);
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 seasonNumberRegEx = new Regex(@"([2-9])$", RegexOptions.Compiled);
var seasonNumberRegExMatch = seasonNumberRegEx.Match(mainTitle);
if (seasonNumberRegExMatch.Success)
{
season = ParseUtil.CoerceInt(seasonNumberRegExMatch.Groups[1].Value);
}
} }
if (episode is > 0) if (episode is > 0)
@ -551,6 +532,36 @@ namespace NzbDrone.Core.Indexers.Definitions
.ToArray(); .ToArray();
} }
private static int? ParseSeasonFromTitles(IReadOnlyCollection<string> titles)
{
var advancedSeasonRegex = new Regex(@"(\d+)(st|nd|rd|th) Season", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var seasonCharactersRegex = new Regex(@"(I{2,})$", RegexOptions.Compiled);
var seasonNumberRegex = new Regex(@"([2-9])$", RegexOptions.Compiled);
foreach (var title in titles)
{
var advancedSeasonRegexMatch = advancedSeasonRegex.Match(title);
if (advancedSeasonRegexMatch.Success)
{
return ParseUtil.CoerceInt(advancedSeasonRegexMatch.Groups[1].Value);
}
var seasonCharactersRegexMatch = seasonCharactersRegex.Match(title);
if (seasonCharactersRegexMatch.Success)
{
return seasonCharactersRegexMatch.Groups[1].Value.Length;
}
var seasonNumberRegexMatch = seasonNumberRegex.Match(title);
if (seasonNumberRegexMatch.Success)
{
return ParseUtil.CoerceInt(seasonNumberRegexMatch.Groups[1].Value);
}
}
return null;
}
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; } public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
} }

Loading…
Cancel
Save