tmdb

package
v0.77.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package tmdb is a minimal The Movie Database client + on-disk cache.

We do NOT pre-enrich search results (that would add 50-200ms to every search and is wasteful for queries the user won't click). Instead the frontend asks for a match lazily per visible card. The cache makes repeated lookups for the same title near-free.

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = errors.New("tmdb: api key not configured")

ErrDisabled means no API key is configured — handlers should fall through gracefully instead of returning a 500.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(apiKey, omdbKey string, pool *sql.DB) (*Client, error)

New returns a TMDB client. If apiKey is empty the client returns ErrDisabled from every call — handlers should surface that as "no enrichment available" (404) without exploding. omdbKey is optional: when set, matches are enriched with the real IMDb rating (via OMDb) on top of TMDB's own vote average.

func (*Client) Close

func (c *Client) Close() error

Close is a no-op: the shared pool's lifecycle is owned by main.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context, year, genre int) ([]Match, error)

Discover queries TMDB's /discover for movies AND tv with optional year/genre filters, merged and sorted by popularity (the Em Alta filters). Direction tags don't apply here (it's a filtered query, not the weekly ranking).

func (*Client) FetchEpisodeName

func (c *Client) FetchEpisodeName(ctx context.Context, seriesID int, season, episode int) string

FetchEpisodeName returns the localized episode title for a given TV show's TMDB ID, season, and episode. Falls back to empty string if not found or on error.

func (*Client) Genres

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

Genres returns the merged movie+tv genre list (deduped), cached for genresTTL.

func (*Client) Match

func (c *Client) Match(ctx context.Context, rawTitle string) (*Match, error)

Match looks up the best TMDB result for a raw torrent title, with caching. Returns (nil, nil) if no match was found — that's a normal "this isn't a known movie/show" case, not an error.

func (*Client) Recommendations

func (c *Client) Recommendations(ctx context.Context, kind string, tmdbID int) ([]Match, error)

Recommendations returns TMDB's "recommendations" list for a movie or tv id — the same set the site shows under a title's Recommendations tab. Single page (~20 items), best-effort. kind MUST be "movie" or "tv": TMDB ids are namespaced per type, so calling the wrong endpoint would return an unrelated title's recs.

func (*Client) Trending

func (c *Client) Trending(ctx context.Context) ([]Match, error)

func (*Client) Videos

func (c *Client) Videos(ctx context.Context, kind string, tmdbID int) ([]Video, error)

Videos returns the YouTube trailers/teasers for a movie or tv id, best first (official trailers → trailers → teasers). include_video_language widens the pt-BR query to English uploads — most titles only have EN trailers.

type Genre

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

Genre is a TMDB genre (movie or tv) for the Discover filter dropdown.

type Match

type Match struct {
	TmdbID        int     `json:"tmdbId"`
	ImdbID        string  `json:"imdbId,omitempty"` // resolved via external_ids; persisted so we never reprocess
	Title         string  `json:"title"`
	OriginalTitle string  `json:"originalTitle,omitempty"` // untranslated title — used to seed torrent search (releases use the original)
	Year          int     `json:"year"`
	PosterURL     string  `json:"posterUrl"`
	Overview      string  `json:"overview"`
	VoteAverage   float64 `json:"voteAverage"`          // TMDB community score (0-10)
	ImdbRating    float64 `json:"imdbRating,omitempty"` // real IMDb rating via OMDb (0-10), when available
	Kind          string  `json:"kind"`                 // "movie" | "tv"
	Popularity    float64 `json:"popularity,omitempty"` // TMDB popularity score
	// Trending direction vs last week's ranking: "up" | "down" | "new" | "same".
	Direction string `json:"direction,omitempty"`
	RankDelta int    `json:"rankDelta,omitempty"` // positions moved (absolute) vs last week
}

Match is the simplified view we expose to the frontend.

type Video

type Video struct {
	Key      string `json:"key"` // YouTube video id
	Name     string `json:"name"`
	Type     string `json:"type"` // "Trailer" | "Teaser"
	Official bool   `json:"official"`
}

Video is one YouTube trailer/teaser attached to a TMDB title.

Jump to

Keyboard shortcuts

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