omdb

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 9 Imported by: 1

README

Omdb

The omdb package is an api wrapper for omdbapi.com. Generated Docs

Table Of Content

Guide

Here's a short guide of the available methods and it's usage. All options are passed in the optional field of each function.

Setup

Let's start by importing the omdb package

import "github.com/Jisin0/filmigo/omdb"

Now let's create a new omdb client with your api key. Get you api key here.

client := omdb.NewClient("your_api_key")

Options

  • DisableCaching : Indicates wether data should not be cached.
  • CacheExpiration : Duration for which cache is valid. Defaults to 5 hours.

You can search for titles i.e Movies and Shows using the Search method.

client.Search("inception")

Options

  • Type : Type of result to return either "movie", "series" or "episode".
  • Year : Year of release of the movie.
  • Page : Results page to return.
GetMovie

You can fetch a movie by it's imdb id or it's exact title. Either ID or Title field must be set in request options.

opts := omdb.GetMovieOpts{
    Title: "inception",
}
client.GetMovie(&opts)

Options

  • ID : Imdb id of the title.
  • Title : Exact title of the movie.
  • Type : Type of result to return either "movie", "series" or "episode".
  • Year : Year of release of the movie.
  • Plot : Length of plot to return, "short" for a short plot or "full" for the full plot.

Documentation

Overview

Package omdb is an api wrapper of the single rout Open Movie DataBase (omdapi.com). The package offers user friendly interfaces to send queries and helper methods to make working with results easier.

Index

Constants

View Source
const (
	ResultTrue  = "True"  // results were returned
	ResultFalse = "False" // results weren't returned

	ResultTypeMovie   = "movie"   // movie result type
	ResultTypeSeries  = "series"  // series result type
	ResultTypeEpisode = "episode" // episode result type

	PlotShort = "short" // return short plot
	PlotFull  = "full"  // return full plot
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GetMovieOpts

type GetMovieOpts struct {
	// Imdb id of the movie for ex: tt1285016.
	ID string `url:"i"`
	// Exact title of the movie to fetch.
	Title string `url:"t"`
	// Type of result to return for ex: series.
	// See omdb.ResultTypeXX values for all possible values.
	Type string `url:"type"`
	// Year of realease of the movie.
	Year string `url:"y"`
	// Length of plot to return, "short" for a short plot or "full" for the full plot.
	// Use omdb.PlotShort or omdb.PlotFull.
	Plot string `url:"plot"`
}

Get movie query values.

type Movie

type Movie struct {
	// Title of the movie.
	Title string `json:"title"`

	// Year the movie was released.
	Year string `json:"year"`

	// Parental guidline rating for ex: R, PG etc.
	Rated string `json:"rated"`

	// Date on which the movie was released in the format 01 January 1950.
	Released string `json:"released"`

	// Runtime/Duration of the movie in minutes for ex. 120 min.
	Runtime string `json:"runtime"`

	// Genres of the movie ina string separated by commas for ex: Action, Comedy, Romance.
	Genres string `json:"genre"`

	// Name of the Director of the movie.
	Director string `json:"director"`

	// Writers of the movie separated by commas.
	Writers string `json:"writer"`

	// Actors/Stars of the movie separated by commas.
	Actors string `json:"actors"`

	// Plot of the movie.
	Plot string `json:"plot"`

	// List of languages separated by commas for ex: English, Spanish, Italian.
	Languages string `json:"language"`

	// Country of origin of the movie.
	Country string `json:"country"`

	// Awards won by the movie.
	Awards string `json:"awards"`

	// Poster image url of the movie.
	Poster string `json:"poster"`

	// Ratings of the movie from various sources.
	Ratings []Rating `json:"ratings"`

	// Metascore of the movie.
	Metascore string `json:"metascore"`

	// Rating of the movie from imdb, returned value is out of 10.
	ImdbRating string `json:"imdbrating"`

	// Number of votes the movie received on imdb.
	ImdbVotes string `json:"imdbvotes"`

	// Imdb id of the movie.
	ImdbID string `json:"imdbid"`

	// Type of title for ex: movie, series or episode.
	// Use omdb.ResultTypeXX values for reliablility.
	Type string `json:"type"`

	// DVD release date of the movie.
	DVD string `json:"dvd"`

	// Boxoffice income generated by the movie with it's currency.
	BoxOffice string `json:"boxoffice"`

	// Production company associated with the movie.
	Production string `json:"production"`

	// Any official website of the movie.
	Website string `json:"website"`

	// This value indicates wether a result was returned.
	// Value is True on success and False on failure (case sensitive).
	Response string `json:"response"`

	// Error message returned for failed queries.
	// This value should be checked to determine wether the reason for a failed call.
	Error string `json:"error"`
}

Result from the omc.log.Debug("using cached data")db.GetMovie function containing full data on a movie.

func (*Movie) PrettyPrint

func (t *Movie) PrettyPrint()

PrettyPrint prints out movie data in a neat interface.

type MoviePreview

type MoviePreview struct {
	// Title of the movie.
	Title string `json:"title"`

	// Year of release of the movie.
	Year string `json:"year"`

	//	Imdb id of the movie for ex: tt1285016.
	ImdbID string `json:"imdbid"`

	// Type of result either "movie", "series" or "episode".
	// use omdb.ResultTypeXX values for reliability when checking.
	Type string `json:"type"`

	// Poster image url for the movie.
	Poster string `json:"poster"`
}

Minimal data about a movie returned from a search query.

func (*MoviePreview) GetFull

func (m *MoviePreview) GetFull(client *OmdbClient) (*Movie, error)

GetFull Fetches the full data about the movie using the api.

- client : Omdb client to use for the request.

type OmdbClient

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

OmdbClient type provides all omdb related operations. Use omdb.NewClient to create one.

func NewClient

func NewClient(apiKey string, o ...OmdbClientOpts) *OmdbClient

NewClient returns a new client with given configs.

func (*OmdbClient) GetMovie

func (c *OmdbClient) GetMovie(opts *GetMovieOpts) (*Movie, error)

GetMovie gets the full data of a movie using it's imdb id or the full name.

func (*OmdbClient) Search

func (c *OmdbClient) Search(query string, opts ...*SearchOpts) (*SearchResult, error)

GetMovie gets the full data of a movie using it's imdb id or the full name:

- query : The query or keyword to search for. - opts : Extra options for the request

func (*OmdbClient) SetCacheTimeout

func (c *OmdbClient) SetCacheTimeout(t time.Duration)

Modify the cache duration of imdb data.

- timeout (time.Duration) - Duration after which cached data must expire.

func (*OmdbClient) SetDisableCaching

func (c *OmdbClient) SetDisableCaching(b bool)

Set DisableCaching to true only if you need to. It's highly unrecommended as data provided by imdb is pretty persistent.

type OmdbClientOpts

type OmdbClientOpts struct {
	// Set this to true to disable caching results.
	DisableCaching bool
	// This field is the duration for which cached data is considered valid.
	// Defaluts to 5 * time.Hour.
	CacheExpiration time.Duration
}

Options to configure the imdb client's behaviour.

type Rating

type Rating struct {
	// Source of the rating for ex: Internet Movie Database.
	Source string `json:"source"`
	// Value of the rating either as a frcation or percentage.
	Value string `json:"value"`
}

Rating of the movie with data about the source.

type SearchOpts

type SearchOpts struct {
	// Type of result to return either "movie", "series" or "episode".
	// Use omdb.ResultTypeXX values for reliablility.
	Type string `url:"type"`

	// Year of release of the movie .
	Year string `url:"y"`

	// Results page to return.
	// Use value from a previous result or use the NextPage helper method.
	Page int `url:"page"`
}

Extra Options for an omdbapi search query.

type SearchResult

type SearchResult struct {
	// List of results .
	Results []*MoviePreview `json:"search"`

	// This value indicates wether a result was returned.
	// Value is True on success and False on failure (case sensitive).
	Response string `json:"response"`

	// Error returned only when query fails or no results were found.
	Error string `json:"error"`

	StrTotalResults string `json:"totalresults"`

	// total results available for a movie.
	TotalResults int

	// Current returned results page.
	Page int

	// Query or keyword that was searched.
	Query string
}

Search results returned from omdb.Search.

func (*SearchResult) NextPage

func (s *SearchResult) NextPage(client *OmdbClient) (*SearchResult, error)

Returns the next page of results or returns an error if nothing was found.

Jump to

Keyboard shortcuts

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