--- title: TMDB Integration tags: - backend - tmdb - external-api --- # TMDB Integration ## Overview Showy uses **TMDB API v3** as its source for movie, TV and people metadata. All TMDB calls go through the backend — the frontend never talks to TMDB directly, so the API key stays server-side. ## Configuration - API base URL: `settings.json` → `tmdbApiUrl` (e.g. `https://api.themoviedb.org/3/`) - API key: `settings.json` → `tmdbApiKey` - Read by `configService` ## Rate Limiting > [!info] File: `backend/services/tmdbService.js` → `tmdbGet(path, params)` Every TMDB request goes through one queue so bulk jobs (like the [[API Reference#Stale Entries Refresh|stale entries refresh]]) never get the IP blocked: - **20 requests per second**, **8 in flight** at once (TMDB allows ~50/s) - **429** → waits for `Retry-After`, then retries; **5xx / network errors** → exponential backoff - Up to 4 attempts per request - Requests are logged as `TMDB GET ?` **without** the API key Measured: 45 requests went out at 20 / 20 / 5 per second, all succeeded. The legacy [[Import System]] keeps its own extra throttle (35 requests per 10 s) on top. ## tmdbService ### Entry Data | Method | TMDB Endpoint | Notes | |---|---|---| | `fetchEntryData(tmdbId, isTV)` | `/movie/{id}` or `/tv/{id}` | Appends `external_ids`, `release_dates` (movie) / `content_ratings` (TV), `keywords`, `videos`, `watch/providers`, `alternative_titles` in the same request | | `fetchSeasonData(tmdbId, seasonNum)` | `/tv/{id}/season/{num}` | Appends `external_ids`; episodes include `crew` and `guest_stars` | | `fetchEntryMedia(tmdbId, isTV)` | `/{type}/{id}/images` | All languages (no `language` param) | | `fetchEntryCredits(tmdbId, isTV)` | `/movie/{id}/credits` or `/tv/{id}/aggregate_credits` | | | `fetchEntryRecommendations(tmdbId, isTV, page)` | `/{type}/{id}/recommendations` | Live, never stored | | `fetchCollectionData(collectionId)` | `/collection/{id}` | | ### Person Data | Method | TMDB Endpoint | |---|---| | `fetchPersonDetails(tmdbId)` | `/person/{id}` (+ `external_ids`) | | `fetchPersonCombinedCredits(tmdbId)` | `/person/{id}/combined_credits` | ### Browse & Search | Method | TMDB Endpoint | |---|---| | `fetchTrending(type)` | `/trending/{type}/week` | | `fetchPopular(type)` | `/{type}/popular` | | `fetchTopRated(type)` | `/{type}/top_rated` | | `fetchUpcoming()` | `/movie/upcoming` | | `searchMulti(query, page)` | `/search/multi` | | `searchPeople(query)` | `/search/person` | | `fetchPopularPeople()` | `/person/popular` | All methods return `null` on failure (after retries) and log the error. ## Entry Mapper > [!info] File: `backend/mappers/entryMapper.js` One place that turns TMDB responses into column values. Used by entry creation (`entryService.createEntry`), the refresh (`entryManager.refrechEntryById`), the season refresh (`seasonController.refreshSeason`), the legacy importer (`models-services/entryService.saveEntry`) and the TMDB preview endpoint. | Function | Fills | |---|---| | `mapEntryFields(data)` | Entry columns — title, dates, runtime (TV falls back to `episode_run_time` then the last episode's runtime), certification (US → GB → origin country; theatrical first for movies), network/studio, budget/revenue, languages, countries, companies, homepage, keywords, trimmed videos and watch providers, alternative titles, TV type/creators/season & episode counts/last air date/next & last episode | | `mapEntryIds(data)` | IMDb (from `external_ids` for TV), TVDB, Wikidata, Facebook, Instagram, X | | `mapEntryRatings(data)` | `tmdb_rating`, `tmdb_vote_count` | | `mapSeasonFields(seasonData)` | Season columns incl. `tvdb_id` | | `mapEpisodeFields(episode)` | Episode columns incl. vote count, production code, directors/writers, guest stars | See [[Models#Entry]] for every stored field. ## Refresh `PUT /entries/:id/refresh` (and the stale job) re-fetches and updates: - Entry, ids and ratings via the mapper - Genres and networks — **synced both ways** (added and removed); network name, country and logo refreshed - Seasons and episodes (matched by TMDB id) - Credits and people ### Stale Entries Refresh `POST /maintenance/stale-entries/refresh?hours=24` refreshes, one at a time, every entry whose `last_fetch` is older than `hours` (or never set), skipping entries with auto sync off. Progress is available from `GET /maintenance/stale-entries`; the UI is the TMDB Refresh card in [[Settings Page#TMDB Refresh]]. ## Frontend TMDB Proxy ``` Frontend → /api/v1/entries/tmdb/trending/movie → Backend → TMDB API → Response ``` See [[API Reference#TMDB Proxy]]. The preview endpoint (`/entries/tmdb/preview/:type/:tmdbId`) returns an `entry` object in the same shape as a library entry, so [[Pages#EntryDetailsPage|EntryDetailsPage]] renders titles that aren't in the library. ## Image URLs TMDB image base URL: `https://image.tmdb.org/t/p/` - Posters: `w185`, `w342`, `w500` - Backdrops: `w780`, `w1280`, `original` - Stills: `w300`, `w780`, `original` - Profiles: `w185`, `w300` - Logos / providers: `w92`, `w500` See [[Media Utilities]] for frontend URL resolution, [[Media System]] for local caching and [[Artwork]] for browsing and adding TMDB images.