mirror of
https://github.com/lampame/lampac-ukraine.git
synced 2026-04-16 09:22:21 +00:00
feat(makhno): enhance season template generation with voice-specific filtering
Implements dynamic season template building that respects voice-specific season availability. Adds proper handling of voice indices and creates filtered season lists based on available content for each voice option. This ensures season navigation remains synchronized when switching between different voice tracks with varying season availability.
This commit is contained in:
parent
ac9242308f
commit
bc4016b7c3
@ -267,12 +267,55 @@ namespace Makhno
|
|||||||
|
|
||||||
int requestedSeason = seasonNumbers.Contains(season) ? season : seasonNumbers.First();
|
int requestedSeason = seasonNumbers.Contains(season) ? season : seasonNumbers.First();
|
||||||
|
|
||||||
|
int? seasonVoiceIndexForTpl = null;
|
||||||
string selectedVoice = t;
|
string selectedVoice = t;
|
||||||
if (string.IsNullOrEmpty(selectedVoice) || !int.TryParse(selectedVoice, out _))
|
if (string.IsNullOrEmpty(selectedVoice) || !int.TryParse(selectedVoice, out int selectedVoiceIndex))
|
||||||
{
|
{
|
||||||
var voiceWithSeason = voiceSeasons.FirstOrDefault(v => v.Seasons.Any(s => s.Number == requestedSeason));
|
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();
|
||||||
}
|
}
|
||||||
|
else if (selectedVoiceIndex >= 0 && selectedVoiceIndex < playerData.Voices.Count)
|
||||||
|
{
|
||||||
|
seasonVoiceIndexForTpl = selectedVoiceIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build season template for selected voice (if valid) to keep season list in sync when switching voices.
|
||||||
|
var season_tpl = new SeasonTpl();
|
||||||
|
List<int> seasonNumbersForTpl = seasonNumbers;
|
||||||
|
if (seasonVoiceIndexForTpl.HasValue)
|
||||||
|
{
|
||||||
|
var seasonsForVoiceTpl = GetSeasonsWithNumbers(playerData.Voices[seasonVoiceIndexForTpl.Value])
|
||||||
|
.Select(s => s.Number)
|
||||||
|
.Distinct()
|
||||||
|
.OrderBy(n => n)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (seasonsForVoiceTpl.Count > 0)
|
||||||
|
seasonNumbersForTpl = seasonsForVoiceTpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var seasonNumber in seasonNumbersForTpl)
|
||||||
|
{
|
||||||
|
(Season Season, int Number)? seasonItem = null;
|
||||||
|
if (seasonVoiceIndexForTpl.HasValue)
|
||||||
|
{
|
||||||
|
var voiceSeasonsForT = GetSeasonsWithNumbers(playerData.Voices[seasonVoiceIndexForTpl.Value]);
|
||||||
|
var match = voiceSeasonsForT.FirstOrDefault(s => s.Number == seasonNumber);
|
||||||
|
seasonItem = match.Season != null ? match : ((Season Season, int Number)?)null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var match = voiceSeasons
|
||||||
|
.SelectMany(v => v.Seasons)
|
||||||
|
.FirstOrDefault(s => s.Number == seasonNumber);
|
||||||
|
seasonItem = match.Season != null ? match : ((Season Season, int Number)?)null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string voiceParam = seasonVoiceIndexForTpl.HasValue ? $"&t={seasonVoiceIndexForTpl.Value}" : string.Empty;
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < playerData.Voices.Count; i++)
|
for (int i = 0; i < playerData.Voices.Count; i++)
|
||||||
{
|
{
|
||||||
@ -331,6 +374,7 @@ namespace Makhno
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
episode_tpl.Append(season_tpl);
|
||||||
episode_tpl.Append(voice_tpl);
|
episode_tpl.Append(voice_tpl);
|
||||||
if (rjson)
|
if (rjson)
|
||||||
return Content(episode_tpl.ToJson(), "application/json; charset=utf-8");
|
return Content(episode_tpl.ToJson(), "application/json; charset=utf-8");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user