fix(makhno): handle null season items when filtering by season number

The code now properly handles cases where the requested season is not found in the voice seasons list by checking if the match has a valid Season before accessing its properties. This prevents potential null reference exceptions when generating season links.
This commit is contained in:
baliasnyifeliks 2026-02-04 20:58:48 +02:00
parent 55ee3b644d
commit ac9242308f

View File

@ -242,17 +242,19 @@ namespace Makhno
if (seasonVoiceIndex.HasValue)
{
var voiceSeasonsForT = GetSeasonsWithNumbers(playerData.Voices[seasonVoiceIndex.Value]);
seasonItem = voiceSeasonsForT.FirstOrDefault(s => s.Number == seasonNumber);
var match = voiceSeasonsForT.FirstOrDefault(s => s.Number == seasonNumber);
seasonItem = match.Season != null ? match : ((Season Season, int Number)?)null;
}
else
{
seasonItem = voiceSeasons
var match = voiceSeasons
.SelectMany(v => v.Seasons)
.FirstOrDefault(s => s.Number == seasonNumber);
seasonItem = match.Season != null ? match : ((Season Season, int Number)?)null;
}
string voiceParam = seasonVoiceIndex.HasValue ? $"&t={seasonVoiceIndex.Value}" : string.Empty;
string seasonName = seasonItem.Season?.Title ?? $"Сезон {seasonNumber}";
string seasonName = seasonItem.HasValue ? seasonItem.Value.Season?.Title ?? $"Сезон {seasonNumber}" : $"Сезон {seasonNumber}";
string link = $"{host}/makhno?imdb_id={imdb_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial=1&season={seasonNumber}{voiceParam}";
season_tpl.Append(seasonName, link, seasonNumber.ToString());
}