moviedata

package module
v0.0.0-...-6826faa Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 15 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.

README

Go Reference Code Coverage License

What it is

A cache in front of The Movie Database, through its Go client go-api-libs/themoviedb. Each film, show, season and episode is fetched once and the fields of it that are read are kept in a SQLite database, each search is kept as its query and the ids it found, and each poster and still is downloaded once into the images directory beside the database. After that, the answer comes from there, offline and without a token.

A program uses this package, never themoviedb directly: Movie, Show and Episode are this package's own, and it takes no client options: responses the client cannot decode go to debug/themoviedb.json.

path, _ := moviedata.Path() // ~/.moviedata/data.db
c, err := moviedata.Open(ctx, path) // reads TMDB_API_TOKEN to fetch what is not kept
if err != nil {
	return err
}
defer c.Close()

m, ok, err := c.Find(ctx, "The Matrix", 1999)
poster, err := c.Poster(ctx, m.ID) // a file under ~/.moviedata/images

What does not exist, at The Movie Database or in what it answered, is an error that is fs.ErrNotExist.

Additional Information

Contributing

Contributions are welcome — please open an issue or a pull request on GitHub.

License

This project is licensed under the Apache 2.0 License.

Documentation

Overview

Package moviedata looks films and shows up at The Movie Database and keeps what it finds: the fields of them that are read, and searches, in a SQLite database, their images as files beside it. What is once fetched is answered from there ever after, so a program asks this package, never The Movie Database's client directly.

Index

Constants

View Source
const DebugFile = "debug/themoviedb.json"

DebugFile is where the responses the client cannot decode are added, for it to learn from, relative to the working directory.

Variables

This section is empty.

Functions

func Path

func Path() (string, error)

Path is where the database lives by default: data.db in ~/.moviedata. Its images are kept in the images directory beside it.

Types

type Client

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

Client answers from what it keeps, and fetches from The Movie Database what it does not keep yet.

Where something does not exist, at The Movie Database or among a season's episodes or a film's images, the error it returns is fs.ErrNotExist.

func Open

func Open(ctx context.Context, path string) (*Client, error)

Open opens the database at path, creating it where it does not exist, and keeps images in the directory beside it.

Without TMDB_API_TOKEN set it still opens: what is kept is answered, and fetching what is not fails.

func (*Client) Close

func (c *Client) Close() error

Close closes the database.

func (*Client) Episode

func (c *Client) Episode(ctx context.Context, id ShowID, n, e int32) (Episode, error)

Episode is episode e of season n of show id.

func (*Client) Find

func (c *Client) Find(ctx context.Context, title string, year int) (Movie, bool, error)

Find is the best match for a film's title and year (0 for unknown): the first result for both, else for the title alone.

func (*Client) FindShow

func (c *Client) FindShow(ctx context.Context, name string) (Show, bool, error)

FindShow is the best match for a show's name: the first result.

func (*Client) Movie

func (c *Client) Movie(ctx context.Context, id MovieID) (Movie, error)

Movie is film id.

func (*Client) Poster

func (c *Client) Poster(ctx context.Context, id MovieID) (string, error)

Poster is the file film id's poster is kept in.

func (*Client) Search

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

Search is the films for query, best first.

func (*Client) SearchShows

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

SearchShows is the shows for query, best first.

func (*Client) Show

func (c *Client) Show(ctx context.Context, id ShowID) (Show, error)

Show is show id.

func (*Client) ShowPoster

func (c *Client) ShowPoster(ctx context.Context, id ShowID, n int32) (string, error)

ShowPoster is the file the poster of season n of show id is kept in, else the show's, for n 0 or a season without one.

func (*Client) Still

func (c *Client) Still(ctx context.Context, id ShowID, n, e int32) (string, error)

Still is the file the still of episode e of season n of show id is kept in.

type Episode

type Episode struct {
	ShowID        ShowID
	SeasonNumber  int32
	EpisodeNumber int32
	Name          string
	Overview      string
	AirDate       civil.Date // zero where unknown
	Runtime       int        // minutes
	VoteAverage   float64
	StillPath     string // empty where it has none
}

Episode is an episode of a show, as The Movie Database has it.

type Movie

type Movie struct {
	ID               MovieID
	Title            string
	OriginalTitle    string
	OriginalLanguage string
	Overview         string
	ReleaseDate      civil.Date // zero where unknown
	Popularity       float64
	VoteAverage      float64
	VoteCount        int
	PosterPath       string // empty where it has none
}

Movie is a film, as The Movie Database has it.

type MovieID

type MovieID int32

MovieID is a film's id at The Movie Database.

type Show

type Show struct {
	ID               ShowID
	Name             string
	OriginalName     string
	OriginalLanguage string
	Overview         string
	FirstAirDate     civil.Date // zero where unknown
	Popularity       float64
	VoteAverage      float64
	VoteCount        int
	PosterPath       string // empty where it has none
}

Show is a show, as The Movie Database has it.

type ShowID

type ShowID int32

ShowID is a show's id at The Movie Database.

Directories

Path Synopsis
databases

Jump to

Keyboard shortcuts

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