mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
fix(api): add TMDB ID enrichment for KP content via IMDB ID lookup
- Add TMDBID field to ExternalIDs model - Enhance GetExternalIDs in MovieService and TVService to fetch TMDB ID via FindTMDBIdByIMDB - Add EnrichKPWithTMDBID function to enrich unified content with TMDB IDs - Update unified handlers to automatically enrich KP content with TMDB IDs - Enrich search results with TMDB IDs by fetching full film data for each result This ensures that when using source=kp, the response includes TMDB IDs in externalIds when available through IMDB ID mapping, while preserving all original KP data.
This commit is contained in:
@@ -61,6 +61,10 @@ func (h *UnifiedHandler) GetMovie(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
data = services.MapKPToUnified(kpFilm)
|
||||
// Обогащаем TMDB ID если есть IMDB ID
|
||||
if h.tmdb != nil {
|
||||
services.EnrichKPWithTMDBID(data, h.tmdb)
|
||||
}
|
||||
} else {
|
||||
// tmdb
|
||||
movie, err := h.tmdb.GetMovie(id, language)
|
||||
@@ -99,6 +103,10 @@ func (h *UnifiedHandler) GetTV(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
data = services.MapKPToUnified(kpFilm)
|
||||
// Обогащаем TMDB ID если есть IMDB ID
|
||||
if h.tmdb != nil {
|
||||
services.EnrichKPWithTMDBID(data, h.tmdb)
|
||||
}
|
||||
} else {
|
||||
tv, err := h.tmdb.GetTVShow(id, language)
|
||||
if err != nil {
|
||||
@@ -139,6 +147,23 @@ func (h *UnifiedHandler) Search(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
items := services.MapKPSearchToUnifiedItems(kpSearch)
|
||||
// Обогащаем результаты поиска TMDB ID через получение полной информации о фильмах
|
||||
if h.tmdb != nil {
|
||||
for i := range items {
|
||||
if kpID, err := strconv.Atoi(items[i].ID); err == nil {
|
||||
if kpFilm, err := h.kp.GetFilmByKinopoiskId(kpID); err == nil && kpFilm.ImdbId != "" {
|
||||
items[i].ExternalIDs.IMDb = kpFilm.ImdbId
|
||||
mediaType := "movie"
|
||||
if items[i].Type == "tv" {
|
||||
mediaType = "tv"
|
||||
}
|
||||
if tmdbID, err := h.tmdb.FindTMDBIdByIMDB(kpFilm.ImdbId, mediaType, "ru-RU"); err == nil {
|
||||
items[i].ExternalIDs.TMDB = &tmdbID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resp := models.UnifiedSearchResponse{
|
||||
Success: true,
|
||||
Data: items,
|
||||
|
||||
Reference in New Issue
Block a user