omdb

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT 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 omdb 从 OMDb(omdbapi.com)按 IMDb 编号取评分与分级:IMDb 评分与人数、烂番茄、Metacritic。

要用户自己的 API Key(免费的每天 1000 次)。Key 在地址里,错误里不带地址。结果缓存一周。

Index

Constants

View Source
const (
	DefaultBaseURL = "https://www.omdbapi.com/"
)

默认的接口地址与缓存时间。

Variables

View Source
var (
	ErrNoKey        = errors.New("没有填写 OMDb API Key")
	ErrUnauthorized = errors.New("OMDb API Key 无效")
	ErrRateLimited  = errors.New("OMDb 今天的请求次数用完了")
	// ErrUnavailable 表示连不上 OMDb,或它回了别的错误
	ErrUnavailable = errors.New("OMDb 暂时不能访问")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) ([]byte, bool)
	Set(key string, value []byte, ttl time.Duration)
}

Cache 是响应缓存(和 TMDB 共用 media_cache 表)。

type Client

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

Client 是 OMDb 客户端。

func New

func New(o Options) (*Client, error)

New 建一个客户端;没有 API Key 时返回 ErrNoKey。

func (*Client) ByIMDb

func (c *Client) ByIMDb(ctx context.Context, imdbID string) (*Title, error)

ByIMDb 按 IMDb 编号取。OMDb 上没有时返回 nil、nil。

func (*Client) Validate

func (c *Client) Validate(ctx context.Context) error

Validate 用一部固定的电影(tt0137523,搏击俱乐部)检查 Key 能不能用。

type Options

type Options struct {
	APIKey  string
	BaseURL string
	HTTP    *http.Client
	Cache   Cache
}

Options 是客户端的选项。

type Title

type Title struct {
	IMDbID string `json:"imdb_id"`
	Title  string `json:"title"`
	// Rated 是分级(例如 PG-13、TV-MA),N/A、Not Rated、Unrated 记成空
	Rated      string  `json:"rated,omitempty"`
	IMDbRating float64 `json:"imdb_rating,omitempty"`
	IMDbVotes  int     `json:"imdb_votes,omitempty"`
	// RottenTomatoes 是烂番茄的新鲜度(百分比)
	RottenTomatoes int `json:"rotten_tomatoes,omitempty"`
	// Metacritic 是 Metacritic 的评分(百分制)
	Metacritic int `json:"metacritic,omitempty"`
}

Title 是一部电影或剧集的评分与分级。没有的项为零值。

Jump to

Keyboard shortcuts

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