Skip to content

Commit

Permalink
fix: readjust season id read from path before use
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Jan 20, 2025
1 parent 3e9f866 commit 44798c8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Shokofin/API/ShokoAPIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ public bool TryGetSeasonIdForEpisodeId(string episodeId, [NotNullWhen(true)] out
}
}

[System.Text.RegularExpressions.GeneratedRegex(@"Season (\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-US")]
[System.Text.RegularExpressions.GeneratedRegex(@"Season (?<seasonNumber>\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-US")]
private static partial Regex SeasonNameRegex();

private async Task<string?> GetSeasonIdForPath(string path) {
Expand All @@ -1500,12 +1500,26 @@ public bool TryGetSeasonIdForEpisodeId(string episodeId, [NotNullWhen(true)] out
// Fast-path for VFS.
if (path.StartsWith(Plugin.Instance.VirtualRoot + Path.DirectorySeparatorChar)) {
var fileName = Path.GetFileName(path);
if (SeasonNameRegex().IsMatch(fileName))
var seasonNumberResult = SeasonNameRegex().Match(fileName);
if (seasonNumberResult.Success)
fileName = Path.GetFileName(Path.GetDirectoryName(path)!);

if (!fileName.TryGetAttributeValue(ShokoSeriesId.Name, out seasonId))
return null;

if (seasonNumberResult.Success) {
var seasonNumber = int.Parse(seasonNumberResult.Groups["seasonNumber"].Value);
var showInfo = await GetShowInfoBySeasonId(seasonId).ConfigureAwait(false);
if (showInfo == null)
return null;

var seasonInfo = showInfo.GetSeasonInfoBySeasonNumber(seasonNumber);
if (seasonInfo == null)
return null;

seasonId = seasonInfo.Id;
}

PathToSeasonIdDictionary[path] = seasonId;
return seasonId;
}
Expand Down

0 comments on commit 44798c8

Please sign in to comment.