goim: github.com/BurntSushi/goim/imdb Index | Files | Directories

package imdb

import "github.com/BurntSushi/goim/imdb"

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

Package Files

attr.go db.go doc.go entity.go enums.go migrations.go sqlite.go

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.

type Actor Uses

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 Uses

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

func (*Actor) EntityYear Uses

func (e *Actor) EntityYear() int

func (*Actor) Ident Uses

func (e *Actor) Ident() Atom

func (*Actor) Name Uses

func (e *Actor) Name() string

func (*Actor) Scan Uses

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

func (*Actor) String Uses

func (e *Actor) String() string

func (*Actor) Type Uses

func (e *Actor) Type() EntityKind

type AkaTitle Uses

type AkaTitle struct {
    Title string
    Attrs string
}

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

func (AkaTitle) String Uses

func (at AkaTitle) String() string

type AkaTitles Uses

type AkaTitles []AkaTitle

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

func (*AkaTitles) ForEntity Uses

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 Uses

func (as *AkaTitles) Len() int

type AlternateVersion Uses

type AlternateVersion struct {
    About string
}

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

func (AlternateVersion) String Uses

func (av AlternateVersion) String() string

type AlternateVersions Uses

type AlternateVersions []AlternateVersion

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

func (*AlternateVersions) ForEntity Uses

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 Uses

func (as *AlternateVersions) Len() int

type Atom Uses

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 Uses

func (a Atom) String() string

type Attributer Uses

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 Uses

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 Uses

func (ci ColorInfo) String() string

type ColorInfos Uses

type ColorInfos []ColorInfo

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

func (*ColorInfos) ForEntity Uses

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 Uses

func (as *ColorInfos) Len() int

type Credit Uses

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 Uses

func (c Credit) String() string

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

func (Credit) Valid Uses

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 Uses

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 Uses

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 Uses

func (as *Credits) Len() int

func (Credits) Swap Uses

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

type DB Uses

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 Uses

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 Uses

func (db *DB) Close() error

Close closes the connection to the database.

func (*DB) CreateIndices Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

type EntityKind Uses

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 Uses

func (e EntityKind) String() string

type Episode Uses

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 Uses

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

func (*Episode) EntityYear Uses

func (e *Episode) EntityYear() int

func (*Episode) Ident Uses

func (e *Episode) Ident() Atom

func (*Episode) Name Uses

func (e *Episode) Name() string

func (*Episode) Scan Uses

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

func (*Episode) String Uses

func (e *Episode) String() string

func (*Episode) Tvshow Uses

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

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

func (*Episode) Type Uses

func (e *Episode) Type() EntityKind

type Genre Uses

type Genre struct {
    Name string
}

Genre represents a single genre tag for an entity.

func (Genre) String Uses

func (g Genre) String() string

type Genres Uses

type Genres []Genre

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

func (*Genres) ForEntity Uses

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 Uses

func (as *Genres) Len() int

type Goof Uses

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 Uses

func (g Goof) String() string

type Goofs Uses

type Goofs []Goof

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

func (*Goofs) ForEntity Uses

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

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

func (*Goofs) Len Uses

func (as *Goofs) Len() int

type Language Uses

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 Uses

func (lang Language) String() string

type Languages Uses

type Languages []Language

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

func (*Languages) ForEntity Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (as *Links) Len() int

func (Links) Less Uses

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

func (Links) Swap Uses

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

type Literature Uses

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 Uses

func (lit Literature) String() string

type Literatures Uses

type Literatures []Literature

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

func (*Literatures) ForEntity Uses

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 Uses

func (as *Literatures) Len() int

type Location Uses

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 Uses

func (loc Location) String() string

type Locations Uses

type Locations []Location

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

func (*Locations) ForEntity Uses

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

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

func (*Locations) Len Uses

func (as *Locations) Len() int

type Movie Uses

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 Uses

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

func (*Movie) EntityYear Uses

func (e *Movie) EntityYear() int

func (*Movie) Ident Uses

func (e *Movie) Ident() Atom

func (*Movie) Name Uses

func (e *Movie) Name() string

func (*Movie) Scan Uses

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

func (*Movie) String Uses

func (e *Movie) String() string

func (*Movie) Type Uses

func (e *Movie) Type() EntityKind

type Plot Uses

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 Uses

func (p Plot) String() string

type Plots Uses

type Plots []Plot

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

func (*Plots) ForEntity Uses

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

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

func (*Plots) Len Uses

func (as *Plots) Len() int

type Quote Uses

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 Uses

func (q Quote) String() string

type Quotes Uses

type Quotes []Quote

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

func (*Quotes) ForEntity Uses

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

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

func (*Quotes) Len Uses

func (as *Quotes) Len() int

type RatingReason Uses

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 Uses

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 Uses

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 Uses

func (mr RatingReason) String() string

func (RatingReason) Unrated Uses

func (mr RatingReason) Unrated() bool

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

type ReleaseDate Uses

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 Uses

func (r ReleaseDate) String() string

type ReleaseDates Uses

type ReleaseDates []ReleaseDate

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

func (*ReleaseDates) ForEntity Uses

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 Uses

func (as *ReleaseDates) Len() int

type RunningTime Uses

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 Uses

func (r RunningTime) String() string

type RunningTimes Uses

type RunningTimes []RunningTime

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

func (*RunningTimes) ForEntity Uses

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 Uses

func (as *RunningTimes) Len() int

type SoundMix Uses

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 Uses

func (sm SoundMix) String() string

type SoundMixes Uses

type SoundMixes []SoundMix

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

func (*SoundMixes) ForEntity Uses

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 Uses

func (as *SoundMixes) Len() int

type Tagline Uses

type Tagline struct {
    Tag string
}

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

func (Tagline) String Uses

func (t Tagline) String() string

type Taglines Uses

type Taglines []Tagline

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

func (*Taglines) ForEntity Uses

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

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

func (*Taglines) Len Uses

func (as *Taglines) Len() int

type Trivia Uses

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 Uses

func (t Trivia) String() string

type Trivias Uses

type Trivias []Trivia

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

func (*Trivias) ForEntity Uses

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

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

func (*Trivias) Len Uses

func (as *Trivias) Len() int

type Tvshow Uses

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 Uses

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

func (*Tvshow) EntityYear Uses

func (e *Tvshow) EntityYear() int

func (*Tvshow) Ident Uses

func (e *Tvshow) Ident() Atom

func (*Tvshow) Name Uses

func (e *Tvshow) Name() string

func (*Tvshow) Scan Uses

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

func (*Tvshow) String Uses

func (e *Tvshow) String() string

func (*Tvshow) Type Uses

func (e *Tvshow) Type() EntityKind

type UserRank Uses

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 Uses

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 Uses

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 Uses

func (r UserRank) String() string

func (UserRank) Unranked Uses

func (r UserRank) Unranked() bool

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

Directories

PathSynopsis
searchPackage search provides a convenient interface that can quickly search an IMDb database loaded with Goim.

Package imdb imports 12 packages (graph) and is imported by 3 packages. Updated 2018-11-16. Refresh now. Tools for package owners.