Categorygithub.com/cyruzin/golang-tmdb
modulepackage
1.6.8
Repository: https://github.com/cyruzin/golang-tmdb.git
Documentation: pkg.go.dev

# README

build Coverage Status Go Report Card GoDoc GitHub tag (latest SemVer) GitHub license

This is a Golang wrapper for working with TMDb API.

An API Key is required. To register for one, head over to themoviedb.org.

This product uses the TMDb API but is not endorsed or certified by TMDb.

Requirements

  • Go 1.13.x or higher. We aim to support the latest supported versions of go.

Installation

go get -u github.com/cyruzin/golang-tmdb

Usage

To get started, import the tmdb package and initiate the client:

import "github.com/cyruzin/golang-tmdb"

tmdbClient, err := tmdb.Init(os.Getenv("YOUR_APIKEY"))
if err != nil {
    fmt.Println(err)
}

// Using v4
tmdbClient, err := tmdb.InitV4(os.Getenv("YOUR_BEARER_TOKEN"))
if err != nil {
    fmt.Println(err)
}

// OPTIONAL (Recommended): Enabling auto retry functionality.
// This option will retry if the previous request fail (429 TOO MANY REQUESTS).
tmdbClient.SetClientAutoRetry()

// OPTIONAL: Set an alternate base URL if you have problems with the default one.
// Use https://api.tmdb.org/3 instead of https://api.themoviedb.org/3.
tmdbClient.SetAlternateBaseURL()

// OPTIONAL: For tests, set a custom base URL
tmdbClient.SetCustomBaseURL("http://localhost:3000")

// Get the current base URL
tmdbClient.GetBaseURL()

// OPTIONAL: Setting a custom config for the http.Client.
// The default timeout is 10 seconds. Here you can set other
// options like Timeout and Transport.
customClient := http.Client{
    Timeout: time.Second * 5,
    Transport: &http.Transport{
        MaxIdleConns: 10,
        IdleConnTimeout: 15 * time.Second,
    },
}

tmdbClient.SetClientConfig(customClient)

// OPTIONAL: Enable this option if you're going to use endpoints
// that needs session id.
//
// You can read more about how this works:
// https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id
tmdbClient.SetSessionID(os.Getenv("YOUR_SESSION_ID"))

movie, err := tmdbClient.GetMovieDetails(297802, nil)
if err != nil {
 fmt.Println(err)
}

fmt.Println(movie.Title)

With optional params:

import "github.com/cyruzin/golang-tmdb"

tmdbClient, err := tmdb.Init(os.Getenv("YOUR_APIKEY"))
if err != nil {
    fmt.Println(err)
}

// Using v4
tmdbClient, err := tmdb.InitV4(os.Getenv("YOUR_BEARER_TOKEN"))
if err != nil {
    fmt.Println(err)
}

options := map[string]string{
  "language": "pt-BR",
  "append_to_response": "credits,images",
}

movie, err := tmdbClient.GetMovieDetails(297802, options)
if err != nil {
 fmt.Println(err)
}

fmt.Println(movie.Title)

Helpers:

Generate image and video URLs:

import "github.com/cyruzin/golang-tmdb"

tmdbClient, err := tmdb.Init(os.Getenv("YOUR_APIKEY"))
if err != nil {
    fmt.Println(err)
}

options := map[string]string{
 "append_to_response": "videos",
}

movie, err := tmdbClient.GetMovieDetails(297802, options)
if err != nil {
 fmt.Println(err)
}

fmt.Println(tmdb.GetImageURL(movie.BackdropPath, tmdb.W500))
// Output: https://image.tmdb.org/t/p/w500/bOGkgRGdhrBYJSLpXaxhXVstddV.jpg
fmt.Println(tmdb.GetImageURL(movie.PosterPath, tmdb.Original))
// Ouput: https://image.tmdb.org/t/p/original/bOGkgRGdhrBYJSLpXaxhXVstddV.jpg

for _, video := range movie.MovieVideosAppend.Videos.MovieVideos.Results {
   if video.Key != "" {
	 fmt.Println(tmdb.GetVideoURL(video.Key))
     // Output: https://www.youtube.com/watch?v=6ZfuNTqbHE8
   }
}

For more examples, click here.

Performance

Getting Movie Details:

Iterationsns/opB/opallocs/op
196088664860632184

Multi Search:

Iterationsns/opB/opallocs/op
1666596963107109608

Contributing

To start contributing, please check CONTRIBUTING.

Tests

For local testing, just run:

 go test -v 

License

MIT

# Packages

No description provided by the author

# Functions

GetImageURL accepts two parameters, the key and the size and returns the complete URL of the image.
GetVideoURL accepts one parameter, the key and returns the complete URL of the video.
Init setups the Client with an apiKey.
InitV4 setups the Client with an bearer token.

# Constants

H632 size.
Original size.
W1280 size.
W154 size.
W185 size.
W300 size.
W342 size.
W45 size.
W500 size.
W780 size.
W92 size.

# Structs

AccessToken type is a struct for access token JSON request.
AccountCreatedLists type is a struct for created lists JSON response.
AccountCreatedListsResults Result Types.
AccountDetails type is a struct for details JSON response.
AccountFavorite type is a struct for movies or TV shows favorite JSON request.
AccountFavoriteMovies type is a struct for favorite movies JSON response.
AccountFavoriteMoviesResults Result Types.
AccountFavoriteTVShows type is a struct for favorite tv shows JSON response.
AccountFavoriteTVShowsResults Result Types.
AccountMovieWatchlist type is a struct for movie watchlist JSON response.
AccountRatedMovies type is a struct for rated movies JSON response.
AccountRatedTVEpisodes type is a struct for rated TV episodes JSON response.
AccountRatedTVEpisodesResults Result Types.
AccountRatedTVShows type is a struct for rated TV shows JSON response.
AccountTVShowsWatchlist type is a struct for tv shows watchlist JSON response.
AccountWatchlist type is a struct for movies or TV shows watchlist JSON request.
BelongsToCollection type is a struct for a collection the movie is a part of.
Certification type is a struct for a single certification JSON response.
CertificationMovie type is a struct for movie certifications JSON response.
CertificationTV type is a struct for tv certifications JSON response.
ChangesMovie type is a struct for movie changes JSON response.
ChangesMovieResults Result Types.
ChangesPerson type is a struct for person changes JSON response.
ChangesTV type is a struct for tv changes JSON response.
Client type is a struct to instantiate this pkg.
CollectionDetails type is a struct for details JSON response.
CollectionImage type is a struct for a single image.
CollectionImages type is a struct for images JSON response.
CollectionTranslations type is a struct for translations JSON response.
CompanyAlternativeNames type is a struct for alternative names JSON response.
CompanyAlternativeNamesResult Result Types.
CompanyDetails type is a struct for details JSON response.
CompanyImage type is a struct for a single image.
CompanyImages type is a struct for images JSON response.
ConfigurationAPI type is a struct for api configuration JSON response.
CreditsDetails type is a struct for credits JSON response.
DiscoverMovie type is a struct for movie JSON response.
DiscoverMovieResults Result Types.
DiscoverTV type is a struct for tv JSON response.
DiscoverTVResults Result Types.
Error type represents an error returned by the TMDB API.
FindByID type is a struct for find JSON response.
GenreMovieList type is a struct for genres movie list JSON response.
GuestSessionRatedMovies type is a struct for rated movies JSON response.
GuestSessionRatedTVEpisodes type is a struct for rated tv episodes JSON response.
GuestSessionRatedTVShows type is a struct for rated tv shows JSON response.
KeywordDetails type is a struct for keyword JSON response.
KeywordMovies type is a struct for movies that belong to a keyword JSON response.
ListCreate type is a struct for list creation JSON request.
ListDetails type is a struct for details JSON response.
ListItemStatus type is a struct for item status JSON response.
ListMedia type is a struct for list media JSON request.
ListResponse type is a struct for list creation JSON response.
MovieAccountStates type is a struct for account states JSON response.
MovieAlternativeTitles type is a struct for alternative titles JSON response.
MovieAlternativeTitlesAppend type is a struct for alternative titles in append to response.
MovieChanges type is a struct for changes JSON response.
MovieChangesAppend type is a struct for changes in append to response.
MovieCredits type is a struct for credits JSON response.
MovieCreditsAppend type is a struct for credits in append to response.
MovieDetails type is a struct for movie details JSON response.
MovieExternalIDs type is a struct for external ids JSON response.
MovieExternalIDsAppend type is a struct for external ids in append to response.
MovieImage type is a struct for a single image.
MovieImages type is a struct for images JSON response.
MovieImagesAppend type is a struct for images in append to response.
MovieKeywords type is a struct for keywords JSON response.
MovieKeywordsAppend type is a struct for keywords in append to response.
MovieLatest type is a struct for latest JSON response.
MovieLists type is a struct for lists JSON response.
MovieListsAppend type is a struct for lists in append to response.
MovieListsResults Result Types.
MovieNowPlaying type is a struct for now playing JSON response.
MovieNowPlayingResults Result Types.
MoviePopular type is a struct for popular JSON response.
MoviePopularResults Result Types.
MovieRecommendations type is a struct for recommendations JSON response.
MovieRecommendationsAppend type is a struct for recommendations in append to response.
MovieRecommendationsResults Result Types.
MovieReleaseDates type is a struct for release dates JSON response.
MovieReleaseDatesAppend type is a struct for release dates in append to response.
MovieReleaseDatesResults Result Types.
MovieReviews type is a struct for reviews JSON response.
MovieReviewsAppend type is a struct for reviews in append to response.
MovieReviewsResults Result Types.
MovieSimilar type is a struct for similar movies JSON response.
MovieSimilarAppend type is a struct for similar movies in append to response.
MovieTopRated type is a struct for top rated JSON response.
MovieTranslations type is a struct for translations JSON response.
MovieTranslationsAppend type is a struct for translations in append to response.
MovieUpcoming type is a struct for upcoming JSON response.
MovieVideos type is a struct for videos JSON response.
MovieVideosAppend type is a struct for videos in append to response.
MovieVideosResults Result Types.
MovieWatchProviders type is a struct for watch/providers JSON response.
MovieWatchProvidersAppend type is a struct for watch/providers in append to response.
MovieWatchProvidersResults Result Types.
NetworkAlternativeNames type is a struct for alternative names JSON response.
NetworkDetails type is a struct for details JSON response.
NetworkImage type is a struct for a single image.
NetworkImages type is a struct for images JSON response.
PersonChanges type is a struct for changes JSON response.
PersonChangesAppend type is a struct for changes JSON in append to response.
PersonCombinedCredits type is a struct for combined credits JSON response.
PersonCombinedCreditsAppend type is a struct for combined credits in append to response.
PersonDetails type is a struct for details JSON response.
PersonExternalIDs type is a struct for external ids JSON response.
PersonExternalIDsAppend type is a struct for external ids in append to response.
PersonImage type is a struct for a single image.
PersonImages type is a struct for images JSON response.
PersonImagesAppend type is a struct for images in append to response.
PersonLatest type is a struct for latest JSON response.
PersonMovieCredits type is a struct for movie credits JSON response.
PersonMovieCreditsAppend type is a struct for movie credits in append to response.
PersonPopular type is a struct for popular JSON response.
PersonTaggedImages type is a struct for tagged images JSON response.
PersonTaggedImagesAppend type is a struct for tagged images in append to response.
PersonTranslations type is a struct for translations JSON response.
PersonTranslationsAppend type is a struct for translations in append to response.
PersonTVCredits type is a struct for tv credits JSON response.
PersonTVCreditsAppend type is a struct for tv credits in append to response.
RequestToken type is a struct for request token JSON response.
Response type is a struct for http responses.
ReviewDetails type is a struct for details JSON response.
SearchCollections type is a strcut for collections JSON response.
SearchCollectionsResults Result Types.
SearchCompanies type is a struct for companies JSON response.
SearchCompaniesResults Result Types.
SearchKeywords type is a struct for keywords JSON response.
SearchKeywordsResults Result Types.
SearchMovies type is a struct for movies JSON response.
SearchMoviesResults Result Types.
SearchMulti type is a struct for multi JSON response.
SearchMultiResults Result Types.
SearchPeople type is a struct for people JSON response.
SearchPeopleResults Result Types.
SearchTVShows type is a struct for tv show JSON response.
SearchTVShowsResults Result Types.
Session type is a struct for session JSON response.
SessionWithLogin type is a struct for session with login JSON response.
Trending type is a struct for trending JSON response.
TrendingResults Result Types.
TVAccountStates type is a struct for account states JSON response.
TVAggregateCredits type is a struct for aggregate credits JSON response.
TVAggregateCreditsAppend type is a struct for aggregate credits in append to response.
TVAiringToday type is a struct for airing today JSON response.
TVAiringTodayResults Result Types.
TVAlternativeTitles type is a struct for alternative titles JSON response.
TVAlternativeTitlesAppend type is a struct for alternative titles in append to response.
TVAlternativeTitlesResults Result Types.
TVChanges type is a struct for changes JSON response.
TVChangesAppend type is a struct for changes in append to response.
TVContentRatings type is a struct for content ratings JSON response.
TVContentRatingsAppend type is a struct for content ratings in append to response.
TVContentRatingsResults Result Types.
TVCredits type is a struct for credits JSON response.
TVCreditsAppend type is a struct for credits in append to response.
TVDetails type is a struct for details JSON response.
TVEpisodeChanges type is a struct for changes JSON response.
TVEpisodeCredits type is a struct for credits JSON response.
TVEpisodeCreditsAppend type is a struct for credits in append to response.
TVEpisodeDetails type is a struct for details JSON response.
TVEpisodeExternalIDs type is a struct for external ids JSON response.
TVEpisodeExternalIDsAppend type is a struct for external ids in append to response.
TVEpisodeGroups type is a struct for episode groups JSON response.
TVEpisodeGroupsAppend type is a struct for episode groups in append to response.
TVEpisodeGroupsDetails type is a struct for details JSON response.
TVEpisodeGroupsResults Result Types.
TVEpisodeImage type is a struct for a single image.
TVEpisodeImages type is a struct for images JSON response.
TVEpisodeImagesAppend type is a struct for images in append to response.
TVEpisodeRate type is a struct for rate JSON response.
TVEpisodeTranslations type is a struct for translations JSON response.
TVEpisodeTranslationsAppend type is a struct for translations in append to response.
TVEpisodeVideos type is a struct for videos JSON response.
TVEpisodeVideosAppend type is a struct for videos in append to response.
TVExternalIDs type is a struct for external ids JSON response.
TVExternalIDsAppend type is a short for external ids in append to response.
TVImage type is a struct for a single image.
TVImages type is a struct for images JSON response.
TVImagesAppend type is a struct for images in append to response.
TVKeywords type is a struct for keywords JSON response.
TVKeywordsAppend type is a struct for keywords in append to response.
TVKeywordsResults Result Types.
TVLatest type is a struct for latest JSON response.
TVOnTheAir type is a struct for on the air JSON response.
TVPopular type is a struct for popular JSON response.
TVRecommendations type is a struct for recommendations JSON response.
TVRecommendationsAppend type is a struct for recommendations in append to response.
TVRecommendationsResults Result Types.
TVReviews type is a struct for reviews JSON response.
TVReviewsAppend type is a struct for reviews in append to response.
TVReviewsResults Result Types.
TVScreenedTheatrically type is a struct for screened theatrically JSON response.
TVScreenedTheatricallyAppend type is a struct for screened theatrically in append to response.
TVScreenedTheatricallyResults Result Types.
TVSeasonChanges is a struct for changes JSON response.
TVSeasonCredits type is a struct for credits JSON response.
TVSeasonCreditsAppend type is a struct for credits in append to response.
TVSeasonDetails is a struct for details JSON response.
TVSeasonExternalIDs type is a struct for external ids JSON response.
TVSeasonExternalIDsAppend type is a struct for external ids in append to response.
TVSeasonImage type is a struct for a single image.
TVSeasonImages type is a struct for images JSON response.
TVSeasonImagesAppend type is a struct for images in append to response.
TVSeasonTranslations type is a struct.
TVSeasonTranslationsAppend type is a struct for translations in append to response.
TVSeasonVideos type is a struct for videos JSON response.
TVSeasonVideosAppend type is a struct for videos in append to response.
TVSimilar type is a struct for similar tv shows JSON response.
TVSimilarAppend type is a struct for similar tv shows in append to response.
TVTopRated type is a struct for top rated JSON response.
TVTranslations type is a struct for translations JSON response.
TVTranslationsAppend type is a struct for translations in append to response.
TVVideos type is a struct for videos JSON response.
TVVideosAppend type is a struct for videos in append to response.
TVVideosResults Result Types.
TVWatchProviders type is a struct for watch/providers JSON response.
TVWatchProvidersAppend type is a struct for watch/providers in append to response.
TVWatchProvidersResults Result Types.
WatchProviderList type is a struct for watch provider list JSON response.
WatchRegionList type is a struct for watch region list JSON response.

# Type aliases

ConfigurationCountries type is a struct for countries configuration JSON response.
ConfigurationJobs type is a struct for jobs configuration JSON response.
ConfigurationLanguages type is a struct for languages configuration JSON response.
ConfigurationPrimaryTranslations type is a struct for primary translations configuration JSON response.
ConfigurationTimezones type is a struct for timezones configuration JSON response.