Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultClientOpts = ClientOptions{ BaseURL: "https://v3-cinemeta.strem.io", Timeout: 2 * time.Second, TTL: 30 * 24 * time.Hour, }
DefaultClientOpts is an options object with sensible defaults.
var ErrNoMeta = errors.New("no meta in context")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Set(key string, movie Meta) error Get(key string) (Meta, time.Time, bool, error) }
Cache is the interface that the cinemeta client uses for caching meta. A package user must pass an implementation of this interface. Usually you create a simple wrapper around an existing cache package. An example implementation is the InMemoryCache in this package.
type CacheItem ¶
CacheItem combines a meta object and a creation time in a single struct. This can be useful for implementing the Cache interface, but is not necessarily required. See the InMemoryCache example implementation of the Cache interface for its usage.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Cinemeta client.
func NewClient ¶
func NewClient(opts ClientOptions, cache Cache, logger *zap.Logger) *Client
NewClient creates a new Cinemeta client.
func (*Client) GetMovie ¶
GetMovie returns the meta object either from the cache or from Cinemeta. It automatically fills the cache with new Cinemeta responses. The context can control the lifetime of the request, and if for example the timeout is shorter than the HTTP client's configured timeout then it takes precedence. If no timeout is set in the context, the HTTP client's timeout takes effect.
func (*Client) GetTVShow ¶
func (c *Client) GetTVShow(ctx context.Context, imdbID string, season int, episode int) (Meta, error)
GetTVShow returns the meta object either from the cache or from Cinemeta. It automatically fills the cache with new Cinemeta responses. The context can control the lifetime of the request, and if for example the timeout is shorter than the HTTP client's configured timeout then it takes precedence. If no timeout is set in the context, the HTTP client's timeout takes effect.
type ClientOptions ¶
type ClientOptions struct { // The base URL for Cinemeta. // Default "https://v3-cinemeta.strem.io". BaseURL string // Timeout for requests. // A more customizable cancellation can be achieved with the context, // but it can never be *longer* than this timeout. // Default 2 seconds. Timeout time.Duration // Max age of items in the cache. // Default 30 days. TTL time.Duration }
ClientOptions are the options for the Cinemeta client.
type InMemoryCache ¶
type InMemoryCache struct {
// contains filtered or unexported fields
}
InMemoryCache is an example implementation of the Cache interface. It doesn't persist its data, so it's not suited for production use of the cinemeta package.
func NewInMemoryCache ¶
func NewInMemoryCache() *InMemoryCache
NewInMemoryCache creates a new InMemoryCache.
type Meta ¶
type Meta struct { ID string `json:"id"` Type string `json:"type"` Name string `json:"name"` // Optional Genres []string `json:"genres,omitempty"` Director []string `json:"director,omitempty"` Cast []string `json:"cast,omitempty"` Poster string `json:"poster,omitempty"` PosterShape string `json:"posterShape,omitempty"` Background string `json:"background,omitempty"` Logo string `json:"logo,omitempty"` Description string `json:"description,omitempty"` ReleaseInfo string `json:"releaseInfo,omitempty"` // A.k.a. *year*. E.g. "2000" for movies and "2000-2014" or "2000-" for TV shows IMDbRating string `json:"imdbRating,omitempty"` Released string `json:"released,omitempty"` // ISO 8601, e.g. "2010-12-06T05:00:00.000Z" Runtime string `json:"runtime,omitempty"` Language string `json:"language,omitempty"` Country string `json:"country,omitempty"` Awards string `json:"awards,omitempty"` Website string `json:"website,omitempty"` }
Meta represents a movie or TV show.
func GetMetaFromContext ¶
GetMetaFromContext returns the Meta object that's stored in the context. It returns an error if no meta was found in the context or the value found isn't of type Meta. The former one is ErrNoMeta which acts as sentinel error so you can check for it.