imdb

package
v0.0.0-...-6a1090a Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2017 License: Unlicense Imports: 12 Imported by: 0

Documentation

Overview

Package imdb provides types and functions for retrieving data from an IMDb database loaded by Goim. There are types for each entity and attribute, along with some convenience functions for loading them from the database. While there are a lot of types---since the database is large---this package is actually fairly minimal. It is likely that you'll find the 'search' sub-package more useful.

The database can be queried using the 'database/sql' package, but it is strongly recommended that you use the Open function in this package (which will give you access to a *sql.DB value). Namely, the Open function will perform a migration on the schema of your database to make sure it is up to date with the version of the 'imdb' package that you're using. (If the migration fails, it will be rolled back and your database will be left untouched.)

Also, many of the functions here require values with types in my csql package: https://github.com/BurntSushi/csql. Mostly, these types are interfaces that types in the 'database/sql' package already satisfy. For example, a csql.Queryer can be a *imdb.DB, *sql.DB, *sql.Stmt or a *sql.Tx, etc.

The central types of this package are DB, Entity, Movie, Tvshow, Episode and Actor. Most of the other types correspond to attributes of entities.

Beta

Please consider this package as beta material. I've already refactored it a few times, but it's possible it could still undergo another major refactoring. (In particular, I am still contemplating my use of the csql package.)

Index

Constants

This section is empty.

Variables

View Source
var Entities = map[string]EntityKind{
	"movie":   EntityMovie,
	"tvshow":  EntityTvshow,
	"episode": EntityEpisode,
	"actor":   EntityActor,
}

Entities is a map from a string representation of an entity type to a Goim entity type.

View Source
var EnumGenres = []string{
	"action",
	"adult",
	"adventure",
	"animation",
	"biography",
	"comedy",
	"commercial",
	"crime",
	"documentary",
	"drama",
	"experimental",
	"family",
	"fantasy",
	"film-noir",
	"game-show",
	"history",
	"horror",
	"lifestyle",
	"music",
	"musical",
	"mystery",
	"news",
	"reality-tv",
	"romance",
	"sci-fi",
	"short",
	"sport",
	"talk-show",
	"thriller",
	"war",
	"western",
}

EnumGenres lists all available genre attribute values.

View Source
var EnumMPAA = []string{"G", "PG", "PG-13", "R", "NC-17"}

EnumMPAA lists all available MPAA rating values.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	Id       Atom
	FullName string
	Sequence string // Non-data. Used by IMDb for unique entity strings.
}

Actor represents a single cast member that has appeared in the credits of at least one movie, TV show or episode in IMDb.

func (*Actor) Attrs

func (e *Actor) Attrs(db csql.Queryer, attrs Attributer) error

func (*Actor) EntityYear

func (e *Actor) EntityYear() int

func (*Actor) Ident

func (e *Actor) Ident() Atom

func (*Actor) Name

func (e *Actor) Name() string

func (*Actor) Scan

func (e *Actor) Scan(rs csql.RowScanner) error

func (*Actor) String

func (e *Actor) String() string

func (*Actor) Type

func (e *Actor) Type() EntityKind

type AkaTitle

type AkaTitle struct {
	Title string
	Attrs string
}

AkaTitle represents the alternative title of a media item with optional attributes.

func (AkaTitle) String

func (at AkaTitle) String() string

type AkaTitles

type AkaTitles []AkaTitle

AkaTitles corresponds to a list of AKA titles, usually for one particular entity. *AkaTitles satisfies the Attributer interface.

func (*AkaTitles) ForEntity

func (as *AkaTitles) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all AKA titles corresponding to the entity given. The list returned is sorted alphabetically in ascending order.

func (*AkaTitles) Len

func (as *AkaTitles) Len() int

type AlternateVersion

type AlternateVersion struct {
	About string
}

AlternateVersion represents a description of an alternative version of an entity.

func (AlternateVersion) String

func (av AlternateVersion) String() string

type AlternateVersions

type AlternateVersions []AlternateVersion

AlternativeVersions corresponds to a list of alternative versions, usually for one particular entity. *AlternateVersions satisfies the Attributer interface.

func (*AlternateVersions) ForEntity

func (as *AlternateVersions) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all alternative versions corresponding to the entity given.

func (*AlternateVersions) Len

func (as *AlternateVersions) Len() int

type Atom

type Atom int32

Atom corresponds to a unique identifier for an entity. If any two entities have different atoms, then they are considered logically distinct.

func (Atom) String

func (a Atom) String() string

type Attributer

type Attributer interface {
	ForEntity(csql.Queryer, Entity) error
	Len() int
}

Attributer describes types that correspond to one or more attribute values of an entity. Namely, values that satisfy this interface can load those attribute values from a database.

type ColorInfo

type ColorInfo struct {
	Color bool
	Attrs string
}

ColorInfo represents the color information of media. Generally this indicates whether the film is in black and white or not, along with some miscellaneous attributes.

func (ColorInfo) String

func (ci ColorInfo) String() string

type ColorInfos

type ColorInfos []ColorInfo

ColorInfos corresponds to a list of color information, usually for one particular entity. *ColorInfos satisfies the Attributer interface.

func (*ColorInfos) ForEntity

func (as *ColorInfos) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all color information corresponding to the entity given.

func (*ColorInfos) Len

func (as *ColorInfos) Len() int

type Credit

type Credit struct {
	Actor     *Actor
	Media     Entity
	Character string
	Position  int
	Attrs     string
}

Credit represents a movie and/or actor credit. It includes optional information like the character played and the billing position of the actor.

Note that Credit has no corresponding type that satisfies the Attributer interface. This may change in the future.

func (Credit) String

func (c Credit) String() string

String only shows the character/position/attrs of the credit.

func (Credit) Valid

func (c Credit) Valid() bool

Valid returns true if and only if this credit belong to a valid movie and a valid actor.

type Credits

type Credits []Credit

Credits corresponds to a list of credits, usually for one particular movie/episode or for one particular actor. *Credits satisfies the Attributer interface.

func (*Credits) ForEntity

func (r *Credits) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'r' with all credits for the given entity. If the entity is a movie or episode, then it returns all available cast sorted by billing position and then alphabetically by full name, both in ascending order. If the entity is a cast member, then it returns all movies and episodes that the cast member appeared in, sorted by year of release in descending order and then alphabetically in ascending order.

func (*Credits) Len

func (as *Credits) Len() int

func (Credits) Swap

func (as Credits) Swap(i, j int)

type DB

type DB struct {
	*sql.DB

	// Since this package attempts to support multiple databases, there are
	// areas where the type of driver being used is important.
	// For example, PostgreSQL supports simultaneous transactions updating the
	// database but SQLite does not.
	Driver string
}

DB represents a database containing information from the Internet Movie DataBase. The underlying database connection is exposed so that clients may run their own queries.

func Open

func Open(driver, dsn string) (*DB, error)

Open opens a connection to an IMDb relational database. The driver may either be "sqlite3" or "postgres". The dsn (data source name) is dependent upon the driver. For example, for the sqlite3 driver, the dsn is just a path to a file (that may not exist).

In general, the 'driver' and 'dsn' should be exactly the same as used in the 'database/sql' package.

Whenever an imdb database is opened, it is checked to make sure its schema is up to date with the current library. If it isn't, it will be updated.

func (*DB) Close

func (db *DB) Close() error

Close closes the connection to the database.

func (*DB) CreateIndices

func (db *DB) CreateIndices(tables ...string) error

CreateIndices creates indices for each of the tables specified. This is automatically done for you if you're using 'goim load'.

func (*DB) DropIndices

func (db *DB) DropIndices(tables ...string) error

DropIndices drops indices for each of the tables specified. It is safe to call this with tables that may or may not have indices already created. Dropping indices is useful when performing large updates on tables. This is automatically done for you if you're using 'goim load'.

func (*DB) IsFuzzyEnabled

func (db *DB) IsFuzzyEnabled() bool

IsFuzzyEnabled returns true if and only if the database is a Postgres database with the 'pg_trgm' extension enabled.

func (*DB) Tables

func (db *DB) Tables() (tables []string, err error)

Tables returns the names of all tables in the database sorted alphabetically in ascending order.

type Entity

type Entity interface {
	// Returns a unique atom identifier for this entity.
	Ident() Atom

	// The type of this entity.
	Type() EntityKind

	// A name representing this entity. It need not be unique among all
	// entities.
	Name() string

	// Returns the year associated with this entity. If no such year exists
	// or is not relevant, it may be 0.
	EntityYear() int

	// Attrs uses double dispatch to load all attribute values for the given
	// Attributer for this entity.
	Attrs(csql.Queryer, Attributer) error

	// Scan loads an entity from a row in the database.
	Scan(rs csql.RowScanner) error
}

Entity is an interface that all types claiming to be an entity must satisfy.

func FromAtom

func FromAtom(db csql.Queryer, ent EntityKind, id Atom) (Entity, error)

FromAtom returns an entity given its type and its unique identifier.

type EntityKind

type EntityKind int

EntityKind represents all possible types of entities supported by this package.

const (
	EntityMovie EntityKind = iota
	EntityTvshow
	EntityEpisode
	EntityActor
)

All possible entities.

func (EntityKind) String

func (e EntityKind) String() string

type Episode

type Episode struct {
	Id                 Atom
	TvshowId           Atom
	Title              string
	Year               int
	Season, EpisodeNum int // May be 0!
}

Episode represents a single episode for a single TV show in IMDb.

func (*Episode) Attrs

func (e *Episode) Attrs(db csql.Queryer, attrs Attributer) error

func (*Episode) EntityYear

func (e *Episode) EntityYear() int

func (*Episode) Ident

func (e *Episode) Ident() Atom

func (*Episode) Name

func (e *Episode) Name() string

func (*Episode) Scan

func (e *Episode) Scan(rs csql.RowScanner) error

func (*Episode) String

func (e *Episode) String() string

func (*Episode) Tvshow

func (e *Episode) Tvshow(db csql.Queryer) (*Tvshow, error)

Tvshow returns a TV show entity that corresponds to this episode.

func (*Episode) Type

func (e *Episode) Type() EntityKind

type Genre

type Genre struct {
	Name string
}

Genre represents a single genre tag for an entity.

func (Genre) String

func (g Genre) String() string

type Genres

type Genres []Genre

Genres corresponds to a list of genre tags, usually for one particular entity. *Genres satisfies the Attributer interface.

func (*Genres) ForEntity

func (as *Genres) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all genre tags correspondings to the entity given. Note that genres are sorted alphabetically in ascending order.

func (*Genres) Len

func (as *Genres) Len() int

type Goof

type Goof struct {
	Type  string `imdb_name:"goof_type"`
	Entry string
}

Goof represents a single goof for an entity. There are several types of goofs, and each goof is labeled with a single type.

func (Goof) String

func (g Goof) String() string

type Goofs

type Goofs []Goof

Goofs corresponds to a list of goofs, usually for one particular entity. *Goofs satisfies the Attributer interface.

func (*Goofs) ForEntity

func (as *Goofs) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all goofs corresponding to the entity given.

func (*Goofs) Len

func (as *Goofs) Len() int

type Language

type Language struct {
	Name  string
	Attrs string
}

Language represents the language for a particular entity. Each language label may have miscellaneous attributes.

func (Language) String

func (lang Language) String() string

type Languages

type Languages []Language

Languages corresponds to a list of languages, usually for one particular entity. *Languages satisfies the Attributer interface.

func (*Languages) ForEntity

func (as *Languages) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all language labels corresponding to the entity given.

func (*Languages) Len

func (as *Languages) Len() int
type Link struct {
	Type   string
	Entity Entity
}

Link represents a link between two entities of the same type. For example, they can describe movie prequels or sequels. Each link has a corresponding type (e.g., "followed by", "follows", ...) and the linked entity itself

func (Link) String

func (lk Link) String() string
type Links []Link

Links corresponds to a list of connections between entities, usually originating from one particular entity. Links satisfies the sort.Interface interface. *Links satisfies the Attributer interface.

func (*Links) ForEntity

func (as *Links) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all links corresponding to the entity given. The links returned are sorted by the year released, in ascending order.

func (*Links) Len

func (as *Links) Len() int

func (Links) Less

func (as Links) Less(i, j int) bool

func (Links) Swap

func (as Links) Swap(i, j int)

type Literature

type Literature struct {
	Type string `imdb_name:"lit_type"`
	Ref  string
}

Literature represents a single written reference to an entity. There are different types of references, and each reference is tagged with a single type.

func (Literature) String

func (lit Literature) String() string

type Literatures

type Literatures []Literature

Literatures corresponds to a list of literature references, usually for one particular entity. *Literatures satisfies the Attributer interface.

func (*Literatures) ForEntity

func (as *Literatures) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all literature references corresponding to the entity given.

func (*Literatures) Len

func (as *Literatures) Len() int

type Location

type Location struct {
	Place string
	Attrs string
}

Location represents a geographic location for a particular entity, usually corresponding to a filming location. Each location may have miscellaneous attributes.

func (Location) String

func (loc Location) String() string

type Locations

type Locations []Location

Locations corresponds to a list of locations, usually for one particular entity. *Locations satisfies the Attributer interface.

func (*Locations) ForEntity

func (as *Locations) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all locations corresponding to the entity given.

func (*Locations) Len

func (as *Locations) Len() int

type Movie

type Movie struct {
	Id       Atom
	Title    string
	Year     int    // Year released.
	Sequence string // Non-data. Used by IMDb for unique entity strings.
	Tv       bool
	Video    bool
}

Movie represents a single movie in IMDb. This includes "made for tv" and "made for video" movies.

func (*Movie) Attrs

func (e *Movie) Attrs(db csql.Queryer, attrs Attributer) error

func (*Movie) EntityYear

func (e *Movie) EntityYear() int

func (*Movie) Ident

func (e *Movie) Ident() Atom

func (*Movie) Name

func (e *Movie) Name() string

func (*Movie) Scan

func (e *Movie) Scan(rs csql.RowScanner) error

func (*Movie) String

func (e *Movie) String() string

func (*Movie) Type

func (e *Movie) Type() EntityKind

type Plot

type Plot struct {
	Entry string
	By    string
}

Plot represents the text of a plot summary---and it's author---for a movie, TV show or episode.

func (Plot) String

func (p Plot) String() string

type Plots

type Plots []Plot

Plots corresponds to a list of plots, usually for one particular entity. *Plots satisfies the Attributer interface.

func (*Plots) ForEntity

func (as *Plots) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all plots corresponding to the entity given.

func (*Plots) Len

func (as *Plots) Len() int

type Quote

type Quote struct {
	Entry string
}

Quote represents the text of a quotation from an entity. Quotes are mostly freeform text, although the general format seems to be:

Character 1: Says something.
	Which may continue to the next line, indented.
Character 2: Says something else.
...

func (Quote) String

func (q Quote) String() string

type Quotes

type Quotes []Quote

Quotes corresponds to a list of quotes, usually for one particular entity. *Quotes satisfies the Attributer interface.

func (*Quotes) ForEntity

func (as *Quotes) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all quotes corresponding to the entity given.

func (*Quotes) Len

func (as *Quotes) Len() int

type RatingReason

type RatingReason struct {
	Rating string
	Reason string
}

RatingReason represents an MPAA standard rating and the reason for which that rating was given. *RatingReason satisfies the Attributer interface.

func (*RatingReason) ForEntity

func (mr *RatingReason) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'mr' with an MPAA rating if it exists. Otherwise, it remains nil.

func (*RatingReason) Len

func (mr *RatingReason) Len() int

Len is 0 if there is no rating or if it is unrated. Otherwise, the Len is 1.

func (RatingReason) String

func (mr RatingReason) String() string

func (RatingReason) Unrated

func (mr RatingReason) Unrated() bool

Unrated returns true if and only if there is no MPAA rating.

type ReleaseDate

type ReleaseDate struct {
	Country  string
	Released time.Time
	Attrs    string
}

ReleaseDate represents the date that a media item was released, along with the region and miscellaneous attributes.

func (ReleaseDate) String

func (r ReleaseDate) String() string

type ReleaseDates

type ReleaseDates []ReleaseDate

ReleaseDates corresponds to a list of release dates, usually for one particular entity. *ReleaseDates satisfies the Attributer interface.

func (*ReleaseDates) ForEntity

func (as *ReleaseDates) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all release dates corresponding to the entity given. Note that the list returned is sorted by release date in ascending order.

func (*ReleaseDates) Len

func (as *ReleaseDates) Len() int

type RunningTime

type RunningTime struct {
	Country string
	Minutes int
	Attrs   string
}

RunningTime represents the running time of an entity in minutes. It may also include a country and some miscellaneous attributes. A given entity may have more than one running time because running times may differ depending upon the country they were released in. IMDb's data guides claim that more than one running time should only exist if there is a significant (> 5 minutes) difference, but in practice, this does not appear true.

func (RunningTime) String

func (r RunningTime) String() string

type RunningTimes

type RunningTimes []RunningTime

RunningTimes corresponds to a list of running times, usually for one particular entity. *RunningTimes satisfies the Attributer interface.

func (*RunningTimes) ForEntity

func (as *RunningTimes) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all running times corresponding to the entity given. Note that the list returned is ordered by country. As a result, the running time without a country comes first---which IMDb claims *should* be the default.

func (*RunningTimes) Len

func (as *RunningTimes) Len() int

type SoundMix

type SoundMix struct {
	Mix   string
	Attrs string
}

SoundMix represents the type of sound mix used for a particular entity, like "Stereo" or "Dolby Digital". A sound mix may also have miscellaneous attributes.

func (SoundMix) String

func (sm SoundMix) String() string

type SoundMixes

type SoundMixes []SoundMix

SoundMixes corresponds to a list of sound mixes, usually for one particular entity. *SoundMixes satisfies the Attributer interface.

func (*SoundMixes) ForEntity

func (as *SoundMixes) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all sound mixes corresponding to the entity given.

func (*SoundMixes) Len

func (as *SoundMixes) Len() int

type Tagline

type Tagline struct {
	Tag string
}

Tagline represents one tagline about an entity, which is usually a very short quip.

func (Tagline) String

func (t Tagline) String() string

type Taglines

type Taglines []Tagline

Taglines corresponds to a list of taglines, usually for one particular entity. *Taglines satisfies the Attributer interface.

func (*Taglines) ForEntity

func (as *Taglines) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all taglines corresponding to the entity given.

func (*Taglines) Len

func (as *Taglines) Len() int

type Trivia

type Trivia struct {
	Entry string
}

Trivia corresponds to a single piece of trivia about an entity. The text is guaranteed not to have any new lines.

func (Trivia) String

func (t Trivia) String() string

type Trivias

type Trivias []Trivia

Trivias corresponds to a list of trivia, usually for one particular entity. *Trivias satisfies the Attributer interface.

func (*Trivias) ForEntity

func (as *Trivias) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'as' with all trivia corresponding to the entity given.

func (*Trivias) Len

func (as *Trivias) Len() int

type Tvshow

type Tvshow struct {
	Id        Atom
	Title     string
	Year      int    // Year started.
	Sequence  string // Non-data. Used by IMDb for unique entity strings.
	YearStart int
	YearEnd   int // Year ended or 0 if still on air.
}

Tvshow represents a single TV show in IMDb. Typically TV shows lack attribute data in lieu of individual episodes containing the data, and are instead a way of connecting episodes together.

func (*Tvshow) Attrs

func (e *Tvshow) Attrs(db csql.Queryer, attrs Attributer) error

func (*Tvshow) EntityYear

func (e *Tvshow) EntityYear() int

func (*Tvshow) Ident

func (e *Tvshow) Ident() Atom

func (*Tvshow) Name

func (e *Tvshow) Name() string

func (*Tvshow) Scan

func (e *Tvshow) Scan(rs csql.RowScanner) error

func (*Tvshow) String

func (e *Tvshow) String() string

func (*Tvshow) Type

func (e *Tvshow) Type() EntityKind

type UserRank

type UserRank struct {
	Votes int
	Rank  int
}

UserRank represents the rank and number votes by users of IMDb for a particular entity. If there are no votes, then the entity is considered unrated. *UserRank satisfies the Attributer interface.

func (*UserRank) ForEntity

func (r *UserRank) ForEntity(db csql.Queryer, e Entity) error

ForEntity fills 'r' with a user rank if it exists. Otherwise, it remains nil.

func (*UserRank) Len

func (r *UserRank) Len() int

Len is 0 if there is no rank or if it is unrated. Otherwise, the Len is 1.

func (UserRank) String

func (r UserRank) String() string

func (UserRank) Unranked

func (r UserRank) Unranked() bool

Unranked returns true if and only if this rank has no votes.

Directories

Path Synopsis
Package search provides a convenient interface that can quickly search an IMDb database loaded with Goim.
Package search provides a convenient interface that can quickly search an IMDb database loaded with Goim.

Jump to

Keyboard shortcuts

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