Documentation
¶
Overview ¶
Package metadata talks to TMDB for movie and show information, artwork, discovery lists and genres.
Package metadata resolves titles against TMDB and powers the Discover panel's trending/popular lists. Talks to TMDB's REST API directly over net/http rather than an unofficial third-party Go SDK.
Index ¶
- Constants
- Variables
- func ClampPage(page int) int
- func PosterURL(posterPath string) string
- func ProfileURL(profilePath string) string
- func RoundRating(v float64) float64
- func ValidList(list string) bool
- func ValidSort(sort string) bool
- type CastMember
- type Client
- func (c *Client) DiscoverMovies(ctx context.Context, q DiscoverQuery) (*MoviePage, error)
- func (c *Client) DiscoverTV(ctx context.Context, q DiscoverQuery) (*ShowPage, error)
- func (c *Client) FindShowByTVDBID(ctx context.Context, tvdbID int) (Show, bool, error)
- func (c *Client) GenreNames(ctx context.Context, kind string, ids []int) []string
- func (c *Client) Genres(ctx context.Context, kind string) ([]Genre, error)
- func (c *Client) GetMovie(ctx context.Context, tmdbID int) (*Movie, error)
- func (c *Client) GetMovieDetail(ctx context.Context, tmdbID int) (*MovieDetail, error)
- func (c *Client) GetSeason(ctx context.Context, tmdbID, season int) ([]EpisodeInfo, error)
- func (c *Client) GetShow(ctx context.Context, tmdbID int) (*ShowDetail, error)
- func (c *Client) GetShowEpisodes(ctx context.Context, tmdbID int) (*ShowDetail, []EpisodeInfo, error)
- func (c *Client) GetShowFull(ctx context.Context, tmdbID int) (*ShowFull, error)
- func (c *Client) HasAPIKey() bool
- func (c *Client) MovieGenres(ctx context.Context, m Movie) []string
- func (c *Client) MovieList(ctx context.Context, list string, page int) (*MoviePage, error)
- func (c *Client) MultiGenres(ctx context.Context, r MultiResult) []string
- func (c *Client) PopularMovies(ctx context.Context) ([]Movie, error)
- func (c *Client) PopularTV(ctx context.Context) ([]Show, error)
- func (c *Client) RelatedMovies(ctx context.Context, tmdbID int, related string) ([]Movie, error)
- func (c *Client) RelatedShows(ctx context.Context, tmdbID int, related string) ([]Show, error)
- func (c *Client) SearchMovies(ctx context.Context, query string) ([]Movie, error)
- func (c *Client) SearchMulti(ctx context.Context, query string) ([]MultiResult, error)
- func (c *Client) SearchTV(ctx context.Context, query string) ([]Show, error)
- func (c *Client) SetAPIKey(key string)
- func (c *Client) ShowGenres(ctx context.Context, s Show) []string
- func (c *Client) SimilarMovies(ctx context.Context, tmdbID int) ([]Movie, error)
- func (c *Client) TVList(ctx context.Context, list string, page int) (*ShowPage, error)
- func (c *Client) TrendingMovies(ctx context.Context) ([]Movie, error)
- func (c *Client) TrendingTV(ctx context.Context) ([]Show, error)
- func (c *Client) WithAPIKey(key string) *Client
- func (c *Client) WrapTransport(wrap func(http.RoundTripper) http.RoundTripper)
- type CrewMember
- type DiscoverQuery
- type EpisodeInfo
- type Genre
- type Movie
- type MovieDetail
- type MoviePage
- type MultiResult
- type SeasonSummary
- type Show
- type ShowDetail
- type ShowFull
- type ShowPage
- type StatusError
- type Trailer
- type Video
Constants ¶
const ( SortPopular = "popular" // most popular first (the default) SortRating = "rating" // best rated first, among titles with enough votes SortNewest = "newest" // latest release or first-air date first SortOldest = "oldest" )
Browse sort orders accepted by DiscoverQuery.Sort.
const ( ListTrending = "trending" // TMDB's trending this week ListPopular = "popular" // TMDB's popular list ListUpcoming = "upcoming" // not released (or first aired) yet, most popular first )
Discover list names accepted by MovieList and TVList.
const ( RelatedRecommended = "recommendations" // what people who liked it also liked RelatedSimilar = "similar" // matched on genre and keywords )
Kinds of related list TMDB offers for a title.
Variables ¶
var ErrInvalidKey = fmt.Errorf("TMDB rejected this API key")
ErrInvalidKey is returned when TMDB rejects the API key.
var ErrNoAPIKey = fmt.Errorf("no TMDB API key has been added yet")
ErrNoAPIKey is returned by any call when no TMDB API key is configured yet — callers should surface this as a "set up metadata in Settings" prompt rather than a generic failure.
Functions ¶
func ClampPage ¶
ClampPage keeps a requested page number between 1 and the deepest page TMDB serves.
func PosterURL ¶
PosterURL builds a full poster image URL from a poster_path fragment TMDB returns, using its "w500" size — good enough for a poster-grid library view without the app needing to know all TMDB's image size variants.
func ProfileURL ¶
ProfileURL builds an actor photo URL (small size, these are thumbnails).
func RoundRating ¶
RoundRating rounds a TMDB vote average to one decimal place.
Types ¶
type CastMember ¶
type CastMember struct {
Name string `json:"name"`
Character string `json:"character"`
ProfilePath string `json:"profile_path"`
Order int `json:"order"`
}
CastMember is one billed actor.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
New constructs a client. apiKey may be empty; calls will return ErrNoAPIKey until SetAPIKey is used or a new Client is built with one.
func NewWithBaseURL ¶
NewWithBaseURL is used by tests to point the client at a local fixture server instead of the real TMDB API (tests use local fixtures, not live network calls).
func (*Client) DiscoverMovies ¶
DiscoverMovies browses TMDB's movies by genre, year and sort order.
func (*Client) DiscoverTV ¶
DiscoverTV is DiscoverMovies for shows.
func (*Client) FindShowByTVDBID ¶
FindShowByTVDBID looks a show up by its TheTVDB id (TMDB's /find endpoint), for titles coming from apps keyed by TVDB such as Sonarr. ok is false when TMDB knows no show with that id.
func (*Client) GenreNames ¶
GenreNames resolves genre ids to English names using TMDB's genre lists for kind ("movie" or "tv"). Each table is fetched lazily, once per process: a failed fetch is not cached, so a later call retries, and in the meantime the caller simply gets no names rather than an error (genres are garnish on a list, never worth failing the list for). Unknown ids are skipped.
func (*Client) Genres ¶
Genres lists TMDB's genres for kind ("movie" or "tv"), sorted by name, from the same once-per-process cache GenreNames uses.
func (*Client) GetMovieDetail ¶
GetMovieDetail fetches everything the movie detail page shows in one call. The answer is kept for a few minutes (the page asks again every few seconds while it is open, and the same title is opened over and over from lists), and must not be modified.
func (*Client) GetShowEpisodes ¶
func (c *Client) GetShowEpisodes(ctx context.Context, tmdbID int) (*ShowDetail, []EpisodeInfo, error)
GetShowEpisodes fetches a show's details plus every episode of every real season. Season 0 ("Specials") is skipped: specials are rarely posted in a searchable form and would show up as permanently "missing" noise in every library — same default Sonarr uses (specials unmonitored).
func (*Client) GetShowFull ¶
GetShowFull fetches everything the TV detail page shows in one call. Like GetMovieDetail, the answer is kept for a few minutes and must not be modified.
func (*Client) MovieGenres ¶
MovieGenres is the genre names for m, whether it came from a list (ids) or the single-movie endpoint (objects).
func (*Client) MovieList ¶
MovieList fetches one page (TMDB serves 20 per page, up to page 500) of the trending, popular or upcoming movies.
func (*Client) MultiGenres ¶
func (c *Client) MultiGenres(ctx context.Context, r MultiResult) []string
MultiGenres resolves a combined-search hit's genres from its own media type.
func (*Client) PopularMovies ¶
PopularMovies powers the Discover panel's "popular" rail.
func (*Client) RelatedMovies ¶
RelatedMovies fetches one page of the movies TMDB relates to a movie: its recommendations or its similar list (see the Related* constants). The page goes through the page cache, so asking again soon costs nothing.
func (*Client) RelatedShows ¶
RelatedShows is RelatedMovies for shows.
func (*Client) SearchMovies ¶
SearchMovies queries TMDB's movie search endpoint.
func (*Client) SearchMulti ¶
SearchMulti searches movies and TV shows together, ranked by TMDB's own relevance. People results are dropped.
func (*Client) ShowGenres ¶
ShowGenres is the TV equivalent of MovieGenres.
func (*Client) SimilarMovies ¶
SimilarMovies powers Discover's "because you added X" recommendations ("similar to items in your library").
func (*Client) TVList ¶
TVList is MovieList for shows; "upcoming" means shows whose first episode has not aired yet.
func (*Client) TrendingMovies ¶
TrendingMovies powers the Discover panel's "trending" rail.
func (*Client) TrendingTV ¶
TrendingTV / PopularTV mirror the movie equivalents for Discover.
func (*Client) WithAPIKey ¶
WithAPIKey returns a separate client using another key against the same server, to test a key before saving it.
func (*Client) WrapTransport ¶
func (c *Client) WrapTransport(wrap func(http.RoundTripper) http.RoundTripper)
WrapTransport wraps the HTTP transport this client uses, e.g. to count requests. Call it before the client is shared between goroutines.
type CrewMember ¶
CrewMember is one credited crew member (only the fields the pages use).
type DiscoverQuery ¶
DiscoverQuery filters a browse of TMDB's catalogue. Zero values mean "any". Year is an exact year and wins over the YearFrom/YearTo range.
type EpisodeInfo ¶
type EpisodeInfo struct {
Season int `json:"season_number"`
Episode int `json:"episode_number"`
Name string `json:"name"`
Overview string `json:"overview"`
AirDate string `json:"air_date"`
}
EpisodeInfo is one episode from GET /tv/{id}/season/{n}.
type Movie ¶
type Movie struct {
TMDBID int `json:"id"`
Title string `json:"title"`
Overview string `json:"overview"`
ReleaseDate string `json:"release_date"`
PosterPath string `json:"poster_path"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
Popularity float64 `json:"popularity"`
GenreIDs []int `json:"genre_ids"`
Genres []Genre `json:"genres"` // only on the single-movie endpoint
}
Movie is the subset of TMDB's movie fields the rest of the app needs.
type MovieDetail ¶
type MovieDetail struct {
Movie
Runtime int `json:"runtime"`
Tagline string `json:"tagline"`
Status string `json:"status"`
OriginalLanguage string `json:"original_language"`
Homepage string `json:"homepage"`
IMDBID string `json:"imdb_id"`
Videos videosBlock `json:"videos"`
Credits creditsBlock `json:"credits"`
ReleaseDates struct {
Results []struct {
Country string `json:"iso_3166_1"`
ReleaseDates []struct {
Certification string `json:"certification"`
} `json:"release_dates"`
} `json:"results"`
} `json:"release_dates"`
}
MovieDetail is GET /movie/{id} with videos, release dates and credits appended in the same request.
func (*MovieDetail) Cast ¶
func (d *MovieDetail) Cast(n int) []CastMember
Cast is the top n billed actors.
func (*MovieDetail) Certification ¶
func (d *MovieDetail) Certification() string
Certification is the movie's age rating: the US one when there is one, otherwise the first non-empty certification any country lists.
func (*MovieDetail) Directors ¶
func (d *MovieDetail) Directors() []string
Directors are the people credited as director, at most three.
func (*MovieDetail) Trailers ¶
func (d *MovieDetail) Trailers() []Trailer
Trailers are the movie's YouTube videos, best trailer first.
type MoviePage ¶
MoviePage is one page of a movie browse or list. TotalPages is capped at the deepest page TMDB serves, and TotalResults at what those pages hold.
type MultiResult ¶
type MultiResult struct {
MediaType string `json:"media_type"` // "movie" or "tv"
ID int `json:"id"`
Title string `json:"title"` // movies
Name string `json:"name"` // shows
ReleaseDate string `json:"release_date"`
FirstAirDate string `json:"first_air_date"`
Overview string `json:"overview"`
PosterPath string `json:"poster_path"`
Popularity float64 `json:"popularity"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
GenreIDs []int `json:"genre_ids"`
}
MultiResult is one hit from TMDB's combined movie + TV search.
func (MultiResult) DisplayTitle ¶
func (m MultiResult) DisplayTitle() string
DisplayTitle is the movie title or show name.
func (MultiResult) Year ¶
func (m MultiResult) Year() int
Year is the release or first-air year, or 0.
type SeasonSummary ¶
type SeasonSummary struct {
SeasonNumber int `json:"season_number"`
EpisodeCount int `json:"episode_count"`
Name string `json:"name"`
AirDate string `json:"air_date"`
}
SeasonSummary is one entry of a show's season list (GET /tv/{id}).
type Show ¶
type Show struct {
TMDBID int `json:"id"`
Name string `json:"name"`
Overview string `json:"overview"`
FirstAirDate string `json:"first_air_date"`
PosterPath string `json:"poster_path"`
VoteAverage float64 `json:"vote_average"`
VoteCount int `json:"vote_count"`
Popularity float64 `json:"popularity"`
GenreIDs []int `json:"genre_ids"`
Genres []Genre `json:"genres"` // only on the single-show endpoint
}
Show is the subset of TMDB's TV-show fields the rest of the app needs (search results and trending/popular lists share this shape).
type ShowDetail ¶
type ShowDetail struct {
Show
Seasons []SeasonSummary `json:"seasons"`
}
ShowDetail is a Show plus its season list, from GET /tv/{id}.
type ShowFull ¶
type ShowFull struct {
ShowDetail
Tagline string `json:"tagline"`
Status string `json:"status"`
OriginalLanguage string `json:"original_language"`
Homepage string `json:"homepage"`
NumberOfSeasons int `json:"number_of_seasons"`
NumberOfEpisodes int `json:"number_of_episodes"`
Networks []struct {
Name string `json:"name"`
} `json:"networks"`
CreatedBy []struct {
Name string `json:"name"`
} `json:"created_by"`
ExternalIDs struct {
IMDBID string `json:"imdb_id"`
} `json:"external_ids"`
Videos videosBlock `json:"videos"`
Credits creditsBlock `json:"credits"`
ContentRatings struct {
Results []struct {
Country string `json:"iso_3166_1"`
Rating string `json:"rating"`
} `json:"results"`
} `json:"content_ratings"`
}
ShowFull is GET /tv/{id} with videos, content ratings and credits appended.
func (*ShowFull) Cast ¶
func (d *ShowFull) Cast(n int) []CastMember
Cast is the top n billed actors.
func (*ShowFull) ContentRating ¶
ContentRating is the show's age rating, preferring the US one.
func (*ShowFull) NetworkNames ¶
NetworkNames lists the broadcasting networks.
func (*ShowFull) SeasonCount ¶
SeasonCount is the number of real seasons (specials excluded), falling back to counting the season list when TMDB omits the total.
type StatusError ¶
StatusError is returned when TMDB answers a request with a status other than 200 (401 is ErrInvalidKey). Callers use Code to tell "TMDB does not have that" (404) from "try again later" (429, 5xx).
func (*StatusError) Error ¶
func (e *StatusError) Error() string