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:
@@ -388,3 +388,37 @@ func FormatKPDate(year int) string {
|
||||
}
|
||||
return fmt.Sprintf("%d-01-01", year)
|
||||
}
|
||||
|
||||
// EnrichKPWithTMDBID обогащает KP контент TMDB ID через IMDB ID
|
||||
func EnrichKPWithTMDBID(content *models.UnifiedContent, tmdbService *TMDBService) {
|
||||
if content == nil || content.IMDbID == "" || content.ExternalIDs.TMDB != nil {
|
||||
return
|
||||
}
|
||||
|
||||
mediaType := "movie"
|
||||
if content.Type == "tv" {
|
||||
mediaType = "tv"
|
||||
}
|
||||
|
||||
if tmdbID, err := tmdbService.FindTMDBIdByIMDB(content.IMDbID, mediaType, "ru-RU"); err == nil {
|
||||
content.ExternalIDs.TMDB = &tmdbID
|
||||
}
|
||||
}
|
||||
|
||||
// EnrichKPSearchItemsWithTMDBID обогащает массив поисковых элементов TMDB ID
|
||||
func EnrichKPSearchItemsWithTMDBID(items []models.UnifiedSearchItem, tmdbService *TMDBService) {
|
||||
for i := range items {
|
||||
if items[i].ExternalIDs.IMDb == "" || items[i].ExternalIDs.TMDB != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
mediaType := "movie"
|
||||
if items[i].Type == "tv" {
|
||||
mediaType = "tv"
|
||||
}
|
||||
|
||||
if tmdbID, err := tmdbService.FindTMDBIdByIMDB(items[i].ExternalIDs.IMDb, mediaType, "ru-RU"); err == nil {
|
||||
items[i].ExternalIDs.TMDB = &tmdbID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user