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 ¶
- Variables
- type Actor
- type AkaTitle
- type AkaTitles
- type AlternateVersion
- type AlternateVersions
- type Atom
- type Attributer
- type ColorInfo
- type ColorInfos
- type Credit
- type Credits
- type DB
- type Entity
- type EntityKind
- type Episode
- func (e *Episode) Attrs(db csql.Queryer, attrs Attributer) error
- func (e *Episode) EntityYear() int
- func (e *Episode) Ident() Atom
- func (e *Episode) Name() string
- func (e *Episode) Scan(rs csql.RowScanner) error
- func (e *Episode) String() string
- func (e *Episode) Tvshow(db csql.Queryer) (*Tvshow, error)
- func (e *Episode) Type() EntityKind
- type Genre
- type Genres
- type Goof
- type Goofs
- type Language
- type Languages
- type Link
- type Links
- type Literature
- type Literatures
- type Location
- type Locations
- type Movie
- type Plot
- type Plots
- type Quote
- type Quotes
- type RatingReason
- type ReleaseDate
- type ReleaseDates
- type RunningTime
- type RunningTimes
- type SoundMix
- type SoundMixes
- type Tagline
- type Taglines
- type Trivia
- type Trivias
- type Tvshow
- type UserRank
Constants ¶
This section is empty.
Variables ¶
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.
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.
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) EntityYear ¶
func (*Actor) Type ¶
func (e *Actor) Type() EntityKind
type AkaTitles ¶
type AkaTitles []AkaTitle
AkaTitles corresponds to a list of AKA titles, usually for one particular entity. *AkaTitles satisfies the Attributer interface.
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.
type Attributer ¶
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 ¶
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.
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 ¶
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.
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 ¶
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.
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 ¶
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) CreateIndices ¶
CreateIndices creates indices for each of the tables specified. This is automatically done for you if you're using 'goim load'.
func (*DB) DropIndices ¶
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 ¶
IsFuzzyEnabled returns true if and only if the database is a Postgres database with the 'pg_trgm' extension enabled.
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.
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) EntityYear ¶
func (*Episode) Type ¶
func (e *Episode) Type() EntityKind
type Genres ¶
type Genres []Genre
Genres corresponds to a list of genre tags, usually for one particular entity. *Genres satisfies the Attributer interface.
type Goof ¶
Goof represents a single goof for an entity. There are several types of goofs, and each goof is labeled with a single type.
type Goofs ¶
type Goofs []Goof
Goofs corresponds to a list of goofs, usually for one particular entity. *Goofs satisfies the Attributer interface.
type Language ¶
Language represents the language for a particular entity. Each language label may have miscellaneous attributes.
type Languages ¶
type Languages []Language
Languages corresponds to a list of languages, usually for one particular entity. *Languages satisfies the Attributer interface.
type Link ¶
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
type Links ¶
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.
type Literature ¶
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 ¶
Location represents a geographic location for a particular entity, usually corresponding to a filming location. Each location may have miscellaneous attributes.
type Locations ¶
type Locations []Location
Locations corresponds to a list of locations, usually for one particular entity. *Locations satisfies the Attributer interface.
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) EntityYear ¶
func (*Movie) Type ¶
func (e *Movie) Type() EntityKind
type Plot ¶
Plot represents the text of a plot summary---and it's author---for a movie, TV show or episode.
type Plots ¶
type Plots []Plot
Plots corresponds to a list of plots, usually for one particular entity. *Plots satisfies the Attributer interface.
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. ...
type Quotes ¶
type Quotes []Quote
Quotes corresponds to a list of quotes, usually for one particular entity. *Quotes satisfies the Attributer interface.
type RatingReason ¶
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 ¶
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 ¶
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 ¶
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.
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.
type Taglines ¶
type Taglines []Tagline
Taglines corresponds to a list of taglines, usually for one particular entity. *Taglines satisfies the Attributer interface.
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.
type Trivias ¶
type Trivias []Trivia
Trivias corresponds to a list of trivia, usually for one particular entity. *Trivias satisfies the Attributer interface.
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) EntityYear ¶
func (*Tvshow) Type ¶
func (e *Tvshow) Type() EntityKind
type UserRank ¶
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 ¶
ForEntity fills 'r' with a user rank if it exists. Otherwise, it remains nil.