metadata

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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.

View Source
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

View Source
var ErrInvalidKey = fmt.Errorf("TMDB rejected this API key")

ErrInvalidKey is returned when TMDB rejects the API key.

View Source
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

func ClampPage(page int) int

ClampPage keeps a requested page number between 1 and the deepest page TMDB serves.

func PosterURL

func PosterURL(posterPath string) string

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

func ProfileURL(profilePath string) string

ProfileURL builds an actor photo URL (small size, these are thumbnails).

func RoundRating

func RoundRating(v float64) float64

RoundRating rounds a TMDB vote average to one decimal place.

func ValidList

func ValidList(list string) bool

ValidList reports whether list is one of the List* names.

func ValidSort

func ValidSort(sort string) bool

ValidSort reports whether sort is empty or one of the Sort* constants.

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

func New(apiKey string) *Client

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

func NewWithBaseURL(apiKey, base string) *Client

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

func (c *Client) DiscoverMovies(ctx context.Context, q DiscoverQuery) (*MoviePage, error)

DiscoverMovies browses TMDB's movies by genre, year and sort order.

func (*Client) DiscoverTV

func (c *Client) DiscoverTV(ctx context.Context, q DiscoverQuery) (*ShowPage, error)

DiscoverTV is DiscoverMovies for shows.

func (*Client) FindShowByTVDBID

func (c *Client) FindShowByTVDBID(ctx context.Context, tvdbID int) (Show, bool, error)

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

func (c *Client) GenreNames(ctx context.Context, kind string, ids []int) []string

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

func (c *Client) Genres(ctx context.Context, kind string) ([]Genre, error)

Genres lists TMDB's genres for kind ("movie" or "tv"), sorted by name, from the same once-per-process cache GenreNames uses.

func (*Client) GetMovie

func (c *Client) GetMovie(ctx context.Context, tmdbID int) (*Movie, error)

GetMovie fetches full details for a single TMDB movie ID.

func (*Client) GetMovieDetail

func (c *Client) GetMovieDetail(ctx context.Context, tmdbID int) (*MovieDetail, error)

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) GetSeason

func (c *Client) GetSeason(ctx context.Context, tmdbID, season int) ([]EpisodeInfo, error)

GetSeason fetches every episode of one season.

func (*Client) GetShow

func (c *Client) GetShow(ctx context.Context, tmdbID int) (*ShowDetail, error)

GetShow fetches a single show's details and season list.

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

func (c *Client) GetShowFull(ctx context.Context, tmdbID int) (*ShowFull, error)

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) HasAPIKey

func (c *Client) HasAPIKey() bool

func (*Client) MovieGenres

func (c *Client) MovieGenres(ctx context.Context, m Movie) []string

MovieGenres is the genre names for m, whether it came from a list (ids) or the single-movie endpoint (objects).

func (*Client) MovieList

func (c *Client) MovieList(ctx context.Context, list string, page int) (*MoviePage, error)

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

func (c *Client) PopularMovies(ctx context.Context) ([]Movie, error)

PopularMovies powers the Discover panel's "popular" rail.

func (*Client) PopularTV

func (c *Client) PopularTV(ctx context.Context) ([]Show, error)

func (*Client) RelatedMovies

func (c *Client) RelatedMovies(ctx context.Context, tmdbID int, related string) ([]Movie, error)

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

func (c *Client) RelatedShows(ctx context.Context, tmdbID int, related string) ([]Show, error)

RelatedShows is RelatedMovies for shows.

func (*Client) SearchMovies

func (c *Client) SearchMovies(ctx context.Context, query string) ([]Movie, error)

SearchMovies queries TMDB's movie search endpoint.

func (*Client) SearchMulti

func (c *Client) SearchMulti(ctx context.Context, query string) ([]MultiResult, error)

SearchMulti searches movies and TV shows together, ranked by TMDB's own relevance. People results are dropped.

func (*Client) SearchTV

func (c *Client) SearchTV(ctx context.Context, query string) ([]Show, error)

SearchTV queries TMDB's TV search endpoint.

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(key string)

func (*Client) ShowGenres

func (c *Client) ShowGenres(ctx context.Context, s Show) []string

ShowGenres is the TV equivalent of MovieGenres.

func (*Client) SimilarMovies

func (c *Client) SimilarMovies(ctx context.Context, tmdbID int) ([]Movie, error)

SimilarMovies powers Discover's "because you added X" recommendations ("similar to items in your library").

func (*Client) TVList

func (c *Client) TVList(ctx context.Context, list string, page int) (*ShowPage, error)

TVList is MovieList for shows; "upcoming" means shows whose first episode has not aired yet.

func (*Client) TrendingMovies

func (c *Client) TrendingMovies(ctx context.Context) ([]Movie, error)

TrendingMovies powers the Discover panel's "trending" rail.

func (*Client) TrendingTV

func (c *Client) TrendingTV(ctx context.Context) ([]Show, error)

TrendingTV / PopularTV mirror the movie equivalents for Discover.

func (*Client) WithAPIKey

func (c *Client) WithAPIKey(key string) *Client

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

type CrewMember struct {
	Name string `json:"name"`
	Job  string `json:"job"`
}

CrewMember is one credited crew member (only the fields the pages use).

type DiscoverQuery

type DiscoverQuery struct {
	Genre    int
	Year     int
	YearFrom int
	YearTo   int
	Sort     string
	Page     int
}

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 Genre

type Genre struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Genre is one entry of TMDB's genre tables.

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.

func (Movie) Year

func (m Movie) Year() int

Year extracts the 4-digit release year from ReleaseDate ("2024-03-01"), or 0 if unknown/unparsed.

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

type MoviePage struct {
	Page         int
	TotalPages   int
	TotalResults int
	Results      []Movie
}

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).

func (Show) Year

func (s Show) Year() int

Year extracts the 4-digit first-air year, or 0 if unknown.

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

func (d *ShowFull) ContentRating() string

ContentRating is the show's age rating, preferring the US one.

func (*ShowFull) Creators

func (d *ShowFull) Creators() []string

Creators are the people the show is created by.

func (*ShowFull) NetworkNames

func (d *ShowFull) NetworkNames() []string

NetworkNames lists the broadcasting networks.

func (*ShowFull) SeasonCount

func (d *ShowFull) SeasonCount() int

SeasonCount is the number of real seasons (specials excluded), falling back to counting the season list when TMDB omits the total.

func (*ShowFull) Trailers

func (d *ShowFull) Trailers() []Trailer

Trailers are the show's YouTube videos, best trailer first.

type ShowPage

type ShowPage struct {
	Page         int
	TotalPages   int
	TotalResults int
	Results      []Show
}

ShowPage is one page of a TV browse or list.

type StatusError

type StatusError struct {
	Path string
	Code int
}

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

type Trailer

type Trailer struct {
	Name     string `json:"name"`
	Site     string `json:"site"`
	Key      string `json:"key"`
	URL      string `json:"url"`
	Type     string `json:"type"`
	Official bool   `json:"official"`
}

Trailer is a YouTube video with a ready-to-open URL.

type Video

type Video struct {
	Name     string `json:"name"`
	Site     string `json:"site"`
	Key      string `json:"key"`
	Type     string `json:"type"`
	Official bool   `json:"official"`
}

Video is one entry of TMDB's videos list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL