mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
All Russian players now use format: /players/{player}/{id_type}/{id}
- id_type can be kp (Kinopoisk) or imdb
- Alloha, Lumex, Vibix, HDVB support both ID types
- Added validation for id_type parameter
- Updated handlers to parse id_type from path
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"neomovies-api/pkg/models"
|
|
"neomovies-api/pkg/services"
|
|
)
|
|
|
|
type SearchHandler struct {
|
|
tmdbService *services.TMDBService
|
|
kpService *services.KinopoiskService
|
|
}
|
|
|
|
func NewSearchHandler(tmdbService *services.TMDBService, kpService *services.KinopoiskService) *SearchHandler {
|
|
return &SearchHandler{
|
|
tmdbService: tmdbService,
|
|
kpService: kpService,
|
|
}
|
|
}
|
|
|
|
func (h *SearchHandler) MultiSearch(w http.ResponseWriter, r *http.Request) {
|
|
query := r.URL.Query().Get("query")
|
|
if query == "" {
|
|
http.Error(w, "Query parameter is required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
page := getIntQuery(r, "page", 1)
|
|
language := GetLanguage(r)
|
|
|
|
if services.ShouldUseKinopoisk(language) && h.kpService != nil {
|
|
kpSearch, err := h.kpService.SearchFilms(query, page)
|
|
if err == nil {
|
|
tmdbResp := services.MapKPSearchToTMDBResponse(kpSearch)
|
|
multiResults := make([]models.MultiSearchResult, 0)
|
|
for _, movie := range tmdbResp.Results {
|
|
multiResults = append(multiResults, models.MultiSearchResult{
|
|
ID: movie.ID,
|
|
MediaType: "movie",
|
|
Title: movie.Title,
|
|
OriginalTitle: movie.OriginalTitle,
|
|
Overview: movie.Overview,
|
|
PosterPath: movie.PosterPath,
|
|
BackdropPath: movie.BackdropPath,
|
|
ReleaseDate: movie.ReleaseDate,
|
|
VoteAverage: movie.VoteAverage,
|
|
VoteCount: movie.VoteCount,
|
|
Popularity: movie.Popularity,
|
|
Adult: movie.Adult,
|
|
OriginalLanguage: movie.OriginalLanguage,
|
|
})
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(models.APIResponse{
|
|
Success: true,
|
|
Data: models.MultiSearchResponse{
|
|
Page: page,
|
|
Results: multiResults,
|
|
TotalPages: tmdbResp.TotalPages,
|
|
TotalResults: tmdbResp.TotalResults,
|
|
},
|
|
})
|
|
return
|
|
}
|
|
}
|
|
|
|
results, err := h.tmdbService.SearchMulti(query, page, language)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(models.APIResponse{
|
|
Success: true,
|
|
Data: results,
|
|
})
|
|
}
|