imdb

package
v0.1.1 Latest Latest
Warning

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

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

View Source
const Host = "www.imdb.com"

Host is the canonical hostname this package targets.

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 Domain added in v0.1.1

type Domain struct{}

Domain is the IMDB driver. It carries no state; the per-run client is built by the factory Register hands to kit.

func (Domain) Classify added in v0.1.1

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (uriType, id).

func (Domain) Info added in v0.1.1

func (Domain) Info() kit.DomainInfo

Info returns the domain scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate added in v0.1.1

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (uriType, id).

func (Domain) Register added in v0.1.1

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Title

type Title struct {
	Rank        int    `json:"rank"`
	ID          string `json:"id"          kit:"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"          table:"url,url"`
}

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

type TitleDetail

type TitleDetail struct {
	ID          string   `json:"id"          kit:"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" kit:"body"`
	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"          table:"url,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