From 097b42023cfd20a8781cc962b21015bd431ea2e1 Mon Sep 17 00:00:00 2001 From: baliasnyifeliks Date: Wed, 4 Feb 2026 19:34:57 +0200 Subject: [PATCH] fix(makhno): redirect to valid season when requested season is unavailable When a user requests a season that doesn't exist for a selected voice, the system now redirects to the first available season for that voice instead of silently using the first season. This ensures users are always directed to valid content and prevents confusion when season data is inconsistent across different voice options. --- Makhno/Controller.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Makhno/Controller.cs b/Makhno/Controller.cs index 57c7d38..236247f 100644 --- a/Makhno/Controller.cs +++ b/Makhno/Controller.cs @@ -235,10 +235,12 @@ namespace Makhno var voice_tpl = new VoiceTpl(); var episode_tpl = new EpisodeTpl(); + int requestedSeason = seasonNumbers.Contains(season) ? season : seasonNumbers.First(); + string selectedVoice = t; if (string.IsNullOrEmpty(selectedVoice) || !int.TryParse(selectedVoice, out _)) { - var voiceWithSeason = voiceSeasons.FirstOrDefault(v => v.Seasons.Any(s => s.Number == season)); + var voiceWithSeason = voiceSeasons.FirstOrDefault(v => v.Seasons.Any(s => s.Number == requestedSeason)); selectedVoice = voiceWithSeason != null ? voiceWithSeason.Index.ToString() : voiceSeasons.First().Index.ToString(); } @@ -250,8 +252,8 @@ namespace Makhno if (seasonsForVoice.Count == 0) continue; - int seasonNumber = seasonsForVoice.Any(s => s.Number == season) - ? season + int seasonNumber = seasonsForVoice.Any(s => s.Number == requestedSeason) + ? requestedSeason : seasonsForVoice.Min(s => s.Number); string voiceLink = $"{host}/makhno?imdb_id={imdb_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial=1&season={seasonNumber}&t={i}"; @@ -265,10 +267,16 @@ namespace Makhno var seasonsForVoice = GetSeasonsWithNumbers(selectedVoiceData); if (seasonsForVoice.Count > 0) { - int effectiveSeasonNumber = seasonsForVoice.Any(s => s.Number == season) - ? season + int effectiveSeasonNumber = seasonsForVoice.Any(s => s.Number == requestedSeason) + ? requestedSeason : seasonsForVoice.Min(s => s.Number); + if (effectiveSeasonNumber != season) + { + string redirectUrl = $"{host}/makhno?imdb_id={imdb_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial=1&season={effectiveSeasonNumber}&t={voiceIndex}"; + return UpdateService.Validate(Redirect(redirectUrl)); + } + var selectedSeason = seasonsForVoice.First(s => s.Number == effectiveSeasonNumber).Season; var sortedEpisodes = selectedSeason.Episodes.OrderBy(e => ExtractEpisodeNumber(e.Title)).ToList();