Documentation ¶
Overview ¶
Package imdb provides easy access to publicly available data on IMDB. Items are accessed by their IMDB ID, and all getter methods called on them are lazy (an http request will be made only when data is needed, and this will happen only once). There is also a convenience AllData() method, which fetches all available data at once.
Index ¶
- type HttpGetPoster
- type HttpGetter
- type HttpPoster
- type Item
- func (s *Item) AllData() (*ItemData, error)
- func (s *Item) Duration() (time.Duration, error)
- func (s *Item) Free()
- func (s *Item) ID() int
- func (s *Item) Languages() ([]*Language, error)
- func (i *Item) MarshalJSON() ([]byte, error)
- func (s *Item) OtherTitles() (map[string]string, error)
- func (s *Item) Plot() (string, error)
- func (s *Item) PlotLong() (string, error)
- func (s *Item) PlotMedium() (string, error)
- func (s *Item) PosterURL() (string, error)
- func (s *Item) PreloadAll()
- func (s *Item) Rating() (float32, error)
- func (s *Item) ReleaseDate() (time.Time, error)
- func (s *Item) SeasonEpisode() (int, int, error)
- func (s *Item) Seasons() ([]*Season, error)
- func (s *Item) Series() (*Item, error)
- func (i *Item) Short() (*ShortItem, error)
- func (s *Item) Tagline() (string, error)
- func (s *Item) Title() (string, error)
- func (s *Item) Type() (ItemType, error)
- func (s *Item) Votes() (int, error)
- func (s *Item) Year() (int, error)
- type ItemData
- type ItemType
- type Language
- type SearchQuery
- type Season
- type ShortItem
Examples ¶
- Item.AllData (Episode)
- Item.AllData (Movie)
- Item.AllData (Series)
- Item.Duration
- Item.ID
- Item.Languages (Episode)
- Item.Languages (Movie)
- Item.Languages (Series)
- Item.MarshalJSON
- Item.OtherTitles
- Item.Plot
- Item.PlotLong
- Item.PlotMedium
- Item.PosterURL
- Item.Rating
- Item.ReleaseDate
- Item.ReleaseDate (Episode)
- Item.SeasonEpisode
- Item.Seasons (Episodes)
- Item.Seasons (Testnumbers)
- Item.Series
- Item.Short
- Item.Short (Episode)
- Item.Short (Series)
- Item.Tagline
- Item.Title
- Item.Title (Episode)
- Item.Title (Series)
- Item.Type
- Item.Votes
- Item.Year
- Item.Year (Episode)
- Item.Year (Series)
- Search
- Search (Exact)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpGetPoster ¶
type HttpGetPoster interface { HttpGetter HttpPoster }
type HttpPoster ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents a single item (either a movie or an episode)
func NewWithClient ¶
func NewWithClient(id int, client HttpGetter) *Item
NewWithClient creates a item from an IMDB ID which will use the given HTTP client to communicate with IMDBIMDB.
func Search ¶
func Search(query *SearchQuery) ([]*Item, error)
Search executes the query
Example ¶
query := &SearchQuery{ Query: "Star Wars", } items, err := Search(query) if err != nil { fmt.Printf("error: %s\n", err) return } for _, item := range items { title, err := item.Title() if err != nil { panic(err) } year, err := item.Year() if err != nil { panic(err) } fmt.Printf("%07d: %s (%d)\n", item.ID(), title, year) }
Output: 0076759: Star Wars (1977) 0295630: Star Wars (1987) 0251413: Star Wars (1983) 3748528: Rogue One (2016) 2527336: Star Wars: The Last Jedi (2017) 2488496: Star Wars: Episode VII - The Force Awakens (2015) 2930604: Star Wars Rebels (2014) 0120915: Star Wars: Episode I - The Phantom Menace (1999) 0458290: Star Wars: The Clone Wars (2008) 0458291: Star Wars: Underworld (2018)
Example (Exact) ¶
query := &SearchQuery{ Query: "Stalker", Year: 1979, Category: Movie, Exact: true, } items, err := Search(query) if err != nil { fmt.Printf("error: %s\n", err) return } for _, item := range items { title, err := item.Title() if err != nil { panic(err) } year, err := item.Year() if err != nil { panic(err) } fmt.Printf("%07d: %s (%d)\n", item.ID(), title, year) }
Output: 0079944: Stalker (1979)
func SearchWithClient ¶
func SearchWithClient(query *SearchQuery, client HttpGetter) ([]*Item, error)
SearchWithClient executes the query using the given HTTP client to communicate with IMDB.
func (*Item) AllData ¶
AllData fetches all possible fields and returns them
Example (Episode) ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() data, err := episode.AllData() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", data)
Output: id: 1577257 type: Episode title: The Beast Below year: 2010 other titles: duration: 42m0s short plot: The Doctor takes Amy to the future inside Starship UK, which contains in addition to British explorers, an intimidating race known as the Smilers. medium plot: The Doctor and Amy travel to a future time where all of the residents actually live in a orbiting spacecraft, Starship UK... long plot: Starship UK is floating through space and we can see the words 'Yorkshire', 'Kent' and 'Surrey' visible on some of the buildings... poster url: https://images-na.ssl-images-amazon.com/images/M/MV5BNjY3MDI5OTE3N15BMl5BanBnXkFtZTcwMzA0MDU1NA@@.jpg rating: 7.7 votes: 3k languages: en release date: 2010-04-10 season number: 5 episode number: 2 series id: 0436992
Example (Movie) ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() data, err := movie.AllData() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", data)
Output: id: 403358 type: Movie title: Nochnoy dozor year: 2004 other titles: > Argentina -> Guardianes de la noche > Brazil -> Guardiões da Noite > Bulgaria (Bulgarian title) -> Нощна стража > Denmark -> Mørkets vogtere > Estonia -> Öine patrull > Finland -> Night Watch - yövahti > Finland (DVD title) -> Yövahti > Finland (Swedish title) -> Nattens väktare - nochnoi dozor > Finland (alternative title) -> Yövartija > France -> Night Watch > Georgia -> Gamis gushagi > Germany -> Wächter der Nacht - Nochnoi Dozor > Greece (transliterated ISO-LATIN-1 title) -> Oi fylakes tis nyhtas > Hungary -> Éjszakai őrség > Italy -> I guardiani della notte > Italy (DVD title) -> Night watch - I guardiani della notte > Latvia -> Nakts Sardze > Panama -> Guardianes de la noche > Peru -> Guardianes de la noche > Poland -> Straz nocna > Portugal -> Guardiões da Noite > Russia -> Ночной дозор > Serbia -> Noćna straža > Spain -> Guardianes de la noche > Sweden -> Nattens väktare > Turkey (Turkish title) -> Gece nöbeti > UK -> Night Watch > World-wide (English title) -> Night Watch duration: 1h54m0s short plot: A fantasy-thriller set in present-day Moscow where the respective forces that control daytime and nighttime do battle. medium plot: Among normal humans live the "Others" possessing various supernatural powers... long plot: THE SETTING: In the world that is modern Moscow, there exists a parallel realm known as the Gloom (kind of like the Astral Plane)... poster url: https://images-na.ssl-images-amazon.com/images/M/MV5BMjE0Nzk0NDkyOV5BMl5BanBnXkFtZTcwMjkzOTkyMQ@@.jpg rating: 6.5 votes: 47k languages: ru, de release date: 2005-10-07 tagline: All That Stands Between Light And Darkness Is The Night Watch.
Example (Series) ¶
series := New(1286039) // Stargate Universe defer series.Free() data, err := series.AllData() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", data)
Output: id: 1286039 type: Series title: SGU Stargate Universe year: 2009 other titles: > France -> Stargate: Universe > Germany -> Stargate: Universe > Hungary -> Csillagkapu: Univerzum > Netherlands -> Stargate: Universe > Poland -> Gwiezdne Wrota: Wszechswiat > Russia -> Звёздные врата: Вселенная > Turkey (Turkish title) (new title) -> Yildiz Geçidi: Evren > USA (promotional title) -> SG.U Stargate Universe > World-wide (alternative title) (English title) -> Stargate: Universe duration: 43m0s short plot: Trapped on an Ancient spaceship billions of light-years from home, a group of soldiers and civilians struggle to survive and find their way back to Earth. medium plot: The previously unknown purpose of the "Ninth Chevron" is revealed, and ends up taking a team to an Ancient ship "Destiny", a ship built millions of years ago by the Ancients, used to seed distant galaxies with Stargates... long plot: An attack on a secret off-world base by a rebel organisation has stranded the remaining survivors on an Ancient ship "Destiny", a large unmanned ship launched millions of years ago... poster url: https://images-na.ssl-images-amazon.com/images/M/MV5BOTEzNTY5NDY5M15BMl5BanBnXkFtZTcwMTY4MDQ3Mg@@.jpg rating: 7.7 votes: 40k languages: en seasons: 1, 2
func (*Item) Duration ¶
Duration returns the item's duration (rounded to minutes). Probably only applicable to Movie and Episode
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() duration, err := movie.Duration() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("duration: %s\n", duration)
Output: duration: 1h54m0s
func (*Item) Free ¶
func (s *Item) Free()
Free frees all resources used by the parser. You must always call it after you finish reading the attributes
func (*Item) ID ¶
ID returns the item's IMDB ID
Example ¶
movie := New(403358) defer movie.Free() fmt.Printf("id: %d\n", movie.ID())
Output: id: 403358
func (*Item) Languages ¶
Languages returns a slice with the names of languages for the item
Example (Episode) ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() languages, err := episode.Languages() if err != nil { fmt.Printf("error: %s\n", err) return } languageNames := make([]string, len(languages)) for i, language := range languages { languageNames[i] = language.String() } fmt.Printf("languages: %s\n", strings.Join(languageNames, ", "))
Output: languages: en
Example (Movie) ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() languages, err := movie.Languages() if err != nil { fmt.Printf("error: %s\n", err) return } languageNames := make([]string, len(languages)) for i, language := range languages { languageNames[i] = language.String() } fmt.Printf("languages: %s\n", strings.Join(languageNames, ", "))
Output: languages: ru, de
Example (Series) ¶
series := New(436992) // Doctor Who defer series.Free() languages, err := series.Languages() if err != nil { fmt.Printf("error: %s\n", err) return } languageNames := make([]string, len(languages)) for i, language := range languages { languageNames[i] = language.String() } fmt.Printf("languages: %s\n", strings.Join(languageNames, ", "))
Output: languages: en
func (*Item) MarshalJSON ¶
MarshalJSON marshals the ShortItem constructed from this one. If you want to marshal more data, call AllData() first.
Example ¶
movie := New(403358) // Nochnoy Dozor defer movie.Free() data, err := json.Marshal(movie) if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", string(data))
Output: {"id":403358,"title":"Nochnoy dozor","type":2,"year":2004}
func (*Item) OtherTitles ¶
OtherTitles returns the item's alternative titles
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() otherTitles, err := movie.OtherTitles() if err != nil { fmt.Printf("error: %s\n", err) return } versions := []string{ "UK", "Russia", "World-wide (English title)", } for _, version := range versions { fmt.Printf("%s: %s\n", version, otherTitles[version]) }
Output: UK: Night Watch Russia: Ночной дозор World-wide (English title): Night Watch
func (*Item) Plot ¶
Plot returns the item's short plot summary
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() shortPlot, err := movie.Plot() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("short plot: %s\n", shortPlot)
Output: short plot: A fantasy-thriller set in present-day Moscow where the respective forces that control daytime and nighttime do battle.
func (*Item) PlotLong ¶
PlotLong returns the item's long synopsis of the plot
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() longPlot, err := movie.PlotLong() if err != nil { fmt.Printf("error: %s\n", err) return } sentences := strings.Split(longPlot, ". ") fmt.Printf("long plot sentence 3:\n%s\n", sentences[2])
Output: long plot sentence 3: They are known as the Others and have co-existed with humans for as long as humanity has existed
func (*Item) PlotMedium ¶
PlotMedium returns the item's medium-sized plot (summary)
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() mediumPlot, err := movie.PlotMedium() if err != nil { fmt.Printf("error: %s\n", err) return } sentences := strings.Split(mediumPlot, ". ") fmt.Printf("medium plot sentence 3:\n%s\n", sentences[2])
Output: medium plot sentence 3: Ever since, the forces of light govern the day while the night belongs to their dark opponents
func (*Item) PosterURL ¶
PosterURL returns.. the item's Poster URL (jpg image)
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() posterURL, err := movie.PosterURL() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("poster url: %s\n", posterURL)
Output: poster url: https://images-na.ssl-images-amazon.com/images/M/MV5BMjE0Nzk0NDkyOV5BMl5BanBnXkFtZTcwMjkzOTkyMQ@@.jpg
func (*Item) PreloadAll ¶
func (s *Item) PreloadAll()
PreloadAll loads all pages needed for this item by making parallel requests to IMDB. All subsequent calls to methods will be fast (won't generate a http request)
func (*Item) Rating ¶
Rating returns the item's rating
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() rating, err := movie.Rating() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("rating: %.2g\n", rating)
Output: rating: 6.5
func (*Item) ReleaseDate ¶
ReleaseDate returns the item's release date. Only applicable for Movie and Episode.
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() releaseDate, err := movie.ReleaseDate() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("release date: %s\n", releaseDate.Format("2006-01-02"))
Output: release date: 2005-10-07
Example (Episode) ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() releaseDate, err := episode.ReleaseDate() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("release date: %s\n", releaseDate.Format("2006-01-02"))
Output: release date: 2010-04-10
func (*Item) SeasonEpisode ¶
SeasonEpisode returns an episode's season and episode numbers
Example ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() seasonNumber, episodeNumber, err := episode.SeasonEpisode() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("s%02de%02d\n", seasonNumber, episodeNumber)
Output: s05e02
func (*Item) Seasons ¶
Seasons returns a slice of all seasons in this item (applicable for Series). Please note that the indices in the slice might have nothing to do with the respective season numbers. For that, call Number() on each season.
Example (Episodes) ¶
series := New(1286039) // Stargate Universe defer series.Free() seasons, err := series.Seasons() if err != nil { fmt.Printf("error: %s\n", err) return } if len(seasons) < 2 { fmt.Printf("season 2 is missing :(\n") } season2 := seasons[1] episodes, err := season2.Episodes() if err != nil { fmt.Printf("error: %s\n", err) return } for i := range episodes { title, err := episodes[i].Title() if err != nil { fmt.Printf("error: %s\n", err) return } // please note that i != episodeNumber, and possibly i+1 != episodeNumber seasonNumber, episodeNumber, err := episodes[i].SeasonEpisode() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("s%02de%02d: %s\n", seasonNumber, episodeNumber, title) }
Output: s02e01: Intervention s02e02: Aftermath s02e03: Awakening s02e04: Pathogen s02e05: Cloverdale s02e06: Trial and Error s02e07: The Greater Good s02e08: Malice s02e09: Visitation s02e10: Resurgence s02e11: Deliverance s02e12: Twin Destinies s02e13: Alliances s02e14: Hope s02e15: Seizure s02e16: The Hunt s02e17: Common Descent s02e18: Epilogue s02e19: Blockade s02e20: Gauntlet
Example (Testnumbers) ¶
series := New(1286039) // Stargate Universe defer series.Free() seasons, err := series.Seasons() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("seasons:\n") for i := range seasons { number, err := seasons[i].Number() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%d\n", number) }
Output: seasons: 1 2
func (*Item) Series ¶
Series returns the series this episode belongs to
Example ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() series, err := episode.Series() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("id: %07d\n", series.ID()) itemType, err := series.Type() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("type: %s\n", itemType) title, err := series.Title() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("title: %s\n", title)
Output: id: 0436992 type: Series title: Doctor Who
func (*Item) Short ¶
Short returns a ShortItem containing only the essential data for this item
Example ¶
movie := New(403358) // Nochnoy Dozor defer movie.Free() short, err := movie.Short() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", short)
Output: id: 403358 type: Movie title: Nochnoy dozor year: 2004
Example (Episode) ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() short, err := episode.Short() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", short)
Output: id: 1577257 type: Episode title: The Beast Below year: 2010
Example (Series) ¶
series := New(1286039) // Stargate Universe defer series.Free() short, err := series.Short() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("%s\n", short)
Output: id: 1286039 type: Series title: SGU Stargate Universe year: 2009
func (*Item) Tagline ¶
Tagline returns the slogan. Probably only applicable for Movie.
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() tagline, err := movie.Tagline() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("tagline: %s\n", tagline)
Output: tagline: All That Stands Between Light And Darkness Is The Night Watch.
func (*Item) Title ¶
Title returns the item's title
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() title, err := movie.Title() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("title: %s\n", title)
Output: title: Nochnoy dozor
Example (Episode) ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() title, err := episode.Title() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("title: %s\n", title)
Output: title: The Beast Below
Example (Series) ¶
series := New(436992) // Doctor Who defer series.Free() title, err := series.Title() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("title: %s\n", title)
Output: title: Doctor Who
func (*Item) Type ¶
Type tells whether the item a movie, series or episode
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() episode := New(1577257) // Doctor Who s05e02 defer episode.Free() series := New(436992) // Doctor Who defer series.Free() movieType, err := movie.Type() if err != nil { fmt.Printf("error: %s\n", err) return } episodeType, err := episode.Type() if err != nil { fmt.Printf("error: %s\n", err) return } seriesType, err := series.Type() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("Nochnoy Dozor's type is %s\n", movieType) fmt.Printf("Doctor Who s05e02's type is %s\n", episodeType) fmt.Printf("Doctor Who's type is %s\n", seriesType)
Output: Nochnoy Dozor's type is Movie Doctor Who s05e02's type is Episode Doctor Who's type is Series
func (*Item) Votes ¶
Votes returns the item's rating's number of votes
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() votes, err := movie.Votes() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("thousands of votes: %d\n", votes/1000)
Output: thousands of votes: 47
func (*Item) Year ¶
Year returns the item's airing year
Example ¶
movie := New(403358) // Nochnoy Dozor (2004) defer movie.Free() year, err := movie.Year() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("year: %d\n", year)
Output: year: 2004
Example (Episode) ¶
episode := New(1577257) // Doctor Who s05e02 defer episode.Free() year, err := episode.Year() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("year: %d\n", year)
Output: year: 2010
Example (Series) ¶
series := New(436992) // Doctor Who defer series.Free() year, err := series.Year() if err != nil { fmt.Printf("error: %s\n", err) return } fmt.Printf("year: %d\n", year)
Output: year: 2005
type ItemData ¶
type ItemData struct { ID int `json:"id"` Type ItemType `json:"type"` Title string `json:"title"` Year int `json:"year"` OtherTitles map[string]string `json:"other_titles"` Duration time.Duration `json:"duration"` Plot string `json:"plot"` PlotMedium string `json:"plot_medium"` PlotLong string `json:"plot_long"` PosterURL string `json:"poster_url"` Rating float32 `json:"rating"` Votes int `json:"votes"` Languages []*Language `json:"languages"` // Movie and Episode-only fields ReleaseDate time.Time `json:"release_date"` // Movie-only fields Tagline string `json:"tagline"` // Episode-only fields SeasonNumber int `json:"season_number"` EpisodeNumber int `json:"episode_number"` Series *Item `json:"series"` // Series-only fields Seasons []*Season `json:"seasons"` }
ItemData holds all fields for a item
type SearchQuery ¶
SearchQuery represents a query for items (shows, series or episodes)
type Season ¶
type Season struct {
// contains filtered or unexported fields
}
Season represents a single season from a series
func NewSeasonWithClient ¶
func NewSeasonWithClient(url string, client HttpGetter) *Season
NewSeasonWithClient creates a season from its url which will use the given HTTP client to communicate with IMDB.
func (*Season) Episodes ¶
Episodes returns an ordered slice of all episodes in this season. The returned items will have be of type Episode, and their Title and SeasonEpisode methods will return pre-cached results.
Please note that although the episodes will probably be in the order they've come out, you shouldn't count on the fact that episode numbers have anything to do with indices in the slice. If you need the episode number, call SeasonEpisode on the episode itself.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package jsonapi implements a http server which responds to simple requests, performs serches on IMDB and returns json objects.
|
Package jsonapi implements a http server which responds to simple requests, performs serches on IMDB and returns json objects. |