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.
This commit is contained in:
baliasnyifeliks 2026-02-04 19:34:57 +02:00
parent e3aa03089c
commit 097b42023c

View File

@ -235,10 +235,12 @@ namespace Makhno
var voice_tpl = new VoiceTpl(); var voice_tpl = new VoiceTpl();
var episode_tpl = new EpisodeTpl(); var episode_tpl = new EpisodeTpl();
int requestedSeason = seasonNumbers.Contains(season) ? season : seasonNumbers.First();
string selectedVoice = t; string selectedVoice = t;
if (string.IsNullOrEmpty(selectedVoice) || !int.TryParse(selectedVoice, out _)) 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(); selectedVoice = voiceWithSeason != null ? voiceWithSeason.Index.ToString() : voiceSeasons.First().Index.ToString();
} }
@ -250,8 +252,8 @@ namespace Makhno
if (seasonsForVoice.Count == 0) if (seasonsForVoice.Count == 0)
continue; continue;
int seasonNumber = seasonsForVoice.Any(s => s.Number == season) int seasonNumber = seasonsForVoice.Any(s => s.Number == requestedSeason)
? season ? requestedSeason
: seasonsForVoice.Min(s => s.Number); : 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}"; 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); var seasonsForVoice = GetSeasonsWithNumbers(selectedVoiceData);
if (seasonsForVoice.Count > 0) if (seasonsForVoice.Count > 0)
{ {
int effectiveSeasonNumber = seasonsForVoice.Any(s => s.Number == season) int effectiveSeasonNumber = seasonsForVoice.Any(s => s.Number == requestedSeason)
? season ? requestedSeason
: seasonsForVoice.Min(s => s.Number); : 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 selectedSeason = seasonsForVoice.First(s => s.Number == effectiveSeasonNumber).Season;
var sortedEpisodes = selectedSeason.Episodes.OrderBy(e => ExtractEpisodeNumber(e.Title)).ToList(); var sortedEpisodes = selectedSeason.Episodes.OrderBy(e => ExtractEpisodeNumber(e.Title)).ToList();