imdb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package imdb is the library behind the imdb command line: the HTTP client, request shaping, and the typed data models for IMDB.

IMDB embeds JSON-LD structured data (<script type="application/ld+json">) on every public page. This package parses that data for chart lists, search results, and individual title pages. No API key required.

Index

Constants

View Source
const DefaultUserAgent = "imdb/dev (+https://github.com/tamnd/imdb-cli)"

DefaultUserAgent identifies the client to IMDB.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a title or resource is not found.

Functions

This section is empty.

Types

type Client

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

Client talks to IMDB over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) Chart

func (c *Client) Chart(ctx context.Context, name string, limit int) ([]Title, error)

Chart fetches a named chart and returns up to limit Title records. name must be one of "top", "toptv", or "popular".

func (*Client) Search

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

Search fetches the IMDB find page and returns up to limit Title records.

func (*Client) TitleByID

func (c *Client) TitleByID(ctx context.Context, idOrURL string) (TitleDetail, error)

TitleByID fetches a title detail page by IMDB id or full URL. Accepts either "tt0111161" or "https://www.imdb.com/title/tt0111161/".

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds constructor parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Title

type Title struct {
	Rank        int    `json:"rank"`
	ID          string `json:"id"`
	Name        string `json:"name"`
	Year        string `json:"year"`
	Rating      string `json:"rating"`
	Votes       string `json:"votes"`
	Genre       string `json:"genre"`
	Type        string `json:"type"`
	Description string `json:"description"`
	URL         string `json:"url"`
}

Title is the primary record emitted by top, toptv, popular, and search.

type TitleDetail

type TitleDetail struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Year        string   `json:"year"`
	Rating      string   `json:"rating"`
	Votes       string   `json:"votes"`
	Genre       string   `json:"genre"`
	Description string   `json:"description"`
	Directors   []string `json:"directors"`
	Actors      []string `json:"actors"`
	Keywords    []string `json:"keywords"`
	Duration    string   `json:"duration"`
	Language    string   `json:"language"`
	Country     string   `json:"country"`
	URL         string   `json:"url"`
}

TitleDetail carries the richer fields available on a single title page.

Jump to

Keyboard shortcuts

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