From 52d7e48bdbce138b49a872c59fca14518e26e668 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 4 Oct 2025 21:12:29 +0000 Subject: [PATCH] fix: restore original Alloha API method with season/episode support - Use Data.Iframe from Alloha API response (original method) - Add season, episode, translation query parameters to iframe URL - Keep season/episode support for Lumex and Vibix - All Russian players now work with episode selection --- pkg/handlers/players.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/pkg/handlers/players.go b/pkg/handlers/players.go index ea64284..fafbdb4 100644 --- a/pkg/handlers/players.go +++ b/pkg/handlers/players.go @@ -78,8 +78,7 @@ func (h *PlayersHandler) GetAllohaPlayer(w http.ResponseWriter, r *http.Request) var allohaResponse struct { Status string `json:"status"` Data struct { - TokenMovie string `json:"token_movie"` - Iframe string `json:"iframe"` + Iframe string `json:"iframe"` } `json:"data"` } @@ -89,8 +88,8 @@ func (h *PlayersHandler) GetAllohaPlayer(w http.ResponseWriter, r *http.Request) return } - if allohaResponse.Status != "success" { - log.Printf("Video not found") + if allohaResponse.Status != "success" || allohaResponse.Data.Iframe == "" { + log.Printf("Video not found or empty iframe") http.Error(w, "Video not found", http.StatusNotFound) return } @@ -103,27 +102,29 @@ func (h *PlayersHandler) GetAllohaPlayer(w http.ResponseWriter, r *http.Request) translation = "66" // дефолтная озвучка } - // Строим URL плеера + // Используем iframe URL из API + iframeCode := allohaResponse.Data.Iframe + + // Если это не HTML код, а просто URL var playerURL string - if allohaResponse.Data.TokenMovie != "" { - // Используем новый API с token_movie - baseURL := "https://torso.as.allohafr.live" - playerURL = fmt.Sprintf("%s/%s", baseURL, allohaResponse.Data.TokenMovie) + if !strings.Contains(iframeCode, "<") { + playerURL = iframeCode + // Добавляем параметры для сериалов if season != "" && episode != "" { - playerURL = fmt.Sprintf("%s?season=%s&episode=%s&translation=%s", playerURL, season, episode, translation) + separator := "?" + if strings.Contains(playerURL, "?") { + separator = "&" + } + playerURL = fmt.Sprintf("%s%sseason=%s&episode=%s&translation=%s", playerURL, separator, season, episode, translation) } - } else if allohaResponse.Data.Iframe != "" { - // Fallback на старый iframe - playerURL = allohaResponse.Data.Iframe - } else { - http.Error(w, "Video not found", http.StatusNotFound) - return + iframeCode = fmt.Sprintf(``, playerURL) } - log.Printf("Generated Alloha player URL: %s", playerURL) + htmlDoc := fmt.Sprintf(`Alloha Player%s`, iframeCode) - iframe := fmt.Sprintf(``, playerURL) - htmlDoc := fmt.Sprintf(`Alloha Player%s`, iframe) + // Авто-исправление экранированных кавычек + htmlDoc = strings.ReplaceAll(htmlDoc, `\"`, `"`) + htmlDoc = strings.ReplaceAll(htmlDoc, `\'`, `'`) w.Header().Set("Content-Type", "text/html") w.Write([]byte(htmlDoc))