diff --git a/account.go b/account.go index 0a85ced..7992582 100644 --- a/account.go +++ b/account.go @@ -5,27 +5,9 @@ import ( "net/http" ) -// AccountDetails type is a struct for details JSON response. -type AccountDetails struct { - Avatar struct { - Gravatar struct { - Hash string `json:"hash"` - } `json:"gravatar"` - TMDB struct { - AvatarPath string `json:"avatar_path"` - } `json:"tmdb"` - } `json:"avatar"` - ID int64 `json:"id"` - Iso639_1 string `json:"iso_639_1"` - Iso3166_1 string `json:"iso_3166_1"` - Name string `json:"name"` - IncludeAdult bool `json:"include_adult"` - Username string `json:"username"` -} - // GetAccountDetails get your account details. // -// https://developers.themoviedb.org/3/account/get-account-details +// https://developer.themoviedb.org/reference/account-details func (c *Client) GetAccountDetails() (*AccountDetails, error) { tmdbURL := fmt.Sprintf( "%s/account?api_key=%s&session_id=%s", @@ -40,50 +22,68 @@ func (c *Client) GetAccountDetails() (*AccountDetails, error) { return &details, nil } -// AccountCreatedLists type is a struct for created lists JSON response. -type AccountCreatedLists struct { - *AccountCreatedListsResults - PaginatedResultsMeta -} - -// GetCreatedLists get all of the lists created by an account. -// Will invlude private lists if you are the owner. +// MarkAsFavorite this method allows you to mark a movie +// or TV show as a favorite item. // -// https://developers.themoviedb.org/3/account/get-created-lists -func (c *Client) GetCreatedLists( +// https://developer.themoviedb.org/reference/account-add-favorite +func (c *Client) MarkAsFavorite( id int, - urlOptions map[string]string, -) (*AccountCreatedLists, error) { - options := c.fmtOptions(urlOptions) + body AccountFavorite, +) (*Response, error) { tmdbURL := fmt.Sprintf( - "%s%s%d/lists?api_key=%s&session_id=%s%s", + "%s%s%d/favorite?api_key=%s&session_id=%s", baseURL, accountURL, id, c.apiKey, c.sessionID, - options, ) - createdLists := AccountCreatedLists{} - if err := c.get(tmdbURL, &createdLists); err != nil { + markAsFavorite := Response{} + if err := c.request( + tmdbURL, + body, + http.MethodPost, + &markAsFavorite, + ); err != nil { return nil, err } - return &createdLists, nil + return &markAsFavorite, nil } -// AccountFavoriteMovies type is a struct for favorite movies JSON response. -type AccountFavoriteMovies struct { - *AccountFavoriteMoviesResults - PaginatedResultsMeta +// AddToWatchlist add a movie or TV show to your watchlist. +// +// https://developer.themoviedb.org/reference/account-add-to-watchlist +func (c *Client) AddToWatchlist( + id int, + body AccountWatchlist, +) (*Response, error) { + tmdbURL := fmt.Sprintf( + "%s%s%d/watchlist?api_key=%s&session_id=%s", + baseURL, + accountURL, + id, + c.apiKey, + c.sessionID, + ) + addToWatchlist := Response{} + if err := c.request( + tmdbURL, + body, + http.MethodPost, + &addToWatchlist, + ); err != nil { + return nil, err + } + return &addToWatchlist, nil } // GetFavoriteMovies get the list of your favorite movies. // -// https://developers.themoviedb.org/3/account/get-favorite-movies +// https://developer.themoviedb.org/reference/account-get-favorites func (c *Client) GetFavoriteMovies( id int, urlOptions map[string]string, -) (*AccountFavoriteMovies, error) { +) (*PaginatedMovieResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/favorite/movies?api_key=%s&session_id=%s%s", @@ -94,26 +94,20 @@ func (c *Client) GetFavoriteMovies( c.sessionID, options, ) - favoriteMovies := AccountFavoriteMovies{} + favoriteMovies := PaginatedMovieResults{} if err := c.get(tmdbURL, &favoriteMovies); err != nil { return nil, err } return &favoriteMovies, nil } -// AccountFavoriteTVShows type is a struct for favorite tv shows JSON response. -type AccountFavoriteTVShows struct { - *AccountFavoriteTVShowsResults - PaginatedResultsMeta -} - // GetFavoriteTVShows get the list of your favorite TV shows. // -// https://developers.themoviedb.org/3/account/get-favorite-tv-shows +// https://developer.themoviedb.org/reference/account-favorite-tv func (c *Client) GetFavoriteTVShows( id int, urlOptions map[string]string, -) (*AccountFavoriteTVShows, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/favorite/tv?api_key=%s&session_id=%s%s", @@ -124,61 +118,45 @@ func (c *Client) GetFavoriteTVShows( c.sessionID, options, ) - favoriteTVShows := AccountFavoriteTVShows{} + favoriteTVShows := PaginatedTVShowResults{} if err := c.get(tmdbURL, &favoriteTVShows); err != nil { return nil, err } return &favoriteTVShows, nil } -// AccountFavorite type is a struct for movies or TV shows -// favorite JSON request. -type AccountFavorite struct { - MediaType string `json:"media_type"` - MediaID int64 `json:"media_id"` - Favorite bool `json:"favorite"` -} - -// MarkAsFavorite this method allows you to mark a movie -// or TV show as a favorite item. +// GetCreatedLists get all of the lists created by an account. +// Will invlude private lists if you are the owner. // -// https://developers.themoviedb.org/3/account/mark-as-favorite -func (c *Client) MarkAsFavorite( +// https://developer.themoviedb.org/reference/account-lists +func (c *Client) GetCreatedLists( id int, - title *AccountFavorite, -) (*Response, error) { + urlOptions map[string]string, +) (*PaginatedListResults, error) { + options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( - "%s%s%d/favorite?api_key=%s&session_id=%s", + "%s%s%d/lists?api_key=%s&session_id=%s%s", baseURL, accountURL, id, c.apiKey, c.sessionID, + options, ) - markAsFavorite := Response{} - if err := c.request( - tmdbURL, - title, - http.MethodPost, - &markAsFavorite, - ); err != nil { + createdLists := PaginatedListResults{} + if err := c.get(tmdbURL, &createdLists); err != nil { return nil, err } - return &markAsFavorite, nil -} - -// AccountRatedMovies type is a struct for rated movies JSON response. -type AccountRatedMovies struct { - *AccountFavoriteMovies + return &createdLists, nil } // GetRatedMovies get a list of all the movies you have rated. // -// https://developers.themoviedb.org/3/account/get-rated-movies +// https://developer.themoviedb.org/reference/account-rated-movies func (c *Client) GetRatedMovies( id int, urlOptions map[string]string, -) (*AccountRatedMovies, error) { +) (*PaginatedMovieRatingResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/rated/movies?api_key=%s&session_id=%s%s", @@ -189,25 +167,20 @@ func (c *Client) GetRatedMovies( c.sessionID, options, ) - ratedMovies := AccountRatedMovies{} + ratedMovies := PaginatedMovieRatingResults{} if err := c.get(tmdbURL, &ratedMovies); err != nil { return nil, err } return &ratedMovies, nil } -// AccountRatedTVShows type is a struct for rated TV shows JSON response. -type AccountRatedTVShows struct { - *AccountFavoriteTVShows -} - // GetRatedTVShows get a list of all the TV shows you have rated. // -// https://developers.themoviedb.org/3/account/get-rated-tv-shows +// https://developer.themoviedb.org/reference/account-rated-tv func (c *Client) GetRatedTVShows( id int, urlOptions map[string]string, -) (*AccountRatedTVShows, error) { +) (*PaginatedTVShowRatingResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/rated/tv?api_key=%s&session_id=%s%s", @@ -218,26 +191,20 @@ func (c *Client) GetRatedTVShows( c.sessionID, options, ) - ratedTVShows := AccountRatedTVShows{} + ratedTVShows := PaginatedTVShowRatingResults{} if err := c.get(tmdbURL, &ratedTVShows); err != nil { return nil, err } return &ratedTVShows, nil } -// AccountRatedTVEpisodes type is a struct for rated TV episodes JSON response. -type AccountRatedTVEpisodes struct { - *AccountRatedTVEpisodesResults - PaginatedResultsMeta -} - // GetRatedTVEpisodes get a list of all the TV episodes you have rated. // -// https://developers.themoviedb.org/3/account/get-rated-tv-episodes +// https://developer.themoviedb.org/reference/account-rated-tv-episodes func (c *Client) GetRatedTVEpisodes( id int, urlOptions map[string]string, -) (*AccountRatedTVEpisodes, error) { +) (*PaginatedTVEpisodeRatingResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/rated/tv/episodes?api_key=%s&session_id=%s%s", @@ -248,25 +215,20 @@ func (c *Client) GetRatedTVEpisodes( c.sessionID, options, ) - ratedTVEpisodes := AccountRatedTVEpisodes{} + ratedTVEpisodes := PaginatedTVEpisodeRatingResults{} if err := c.get(tmdbURL, &ratedTVEpisodes); err != nil { return nil, err } return &ratedTVEpisodes, nil } -// AccountMovieWatchlist type is a struct for movie watchlist JSON response. -type AccountMovieWatchlist struct { - *AccountFavoriteMovies -} - // GetMovieWatchlist get a list of all the movies you have added to your watchlist. // -// https://developers.themoviedb.org/3/account/get-movie-watchlist +// https://developer.themoviedb.org/reference/account-watchlist-movies func (c *Client) GetMovieWatchlist( id int, urlOptions map[string]string, -) (*AccountMovieWatchlist, error) { +) (*PaginatedMovieResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/watchlist/movies?api_key=%s&session_id=%s%s", @@ -277,25 +239,20 @@ func (c *Client) GetMovieWatchlist( c.sessionID, options, ) - movieWatchlist := AccountMovieWatchlist{} + movieWatchlist := PaginatedMovieResults{} if err := c.get(tmdbURL, &movieWatchlist); err != nil { return nil, err } return &movieWatchlist, nil } -// AccountTVShowsWatchlist type is a struct for tv shows watchlist JSON response. -type AccountTVShowsWatchlist struct { - *AccountFavoriteTVShows -} - // GetTVShowsWatchlist get a list of all the TV shows you have added to your watchlist. // -// https://developers.themoviedb.org/3/account/get-tv-show-watchlist +// https://developer.themoviedb.org/reference/account-watchlist-tv func (c *Client) GetTVShowsWatchlist( id int, urlOptions map[string]string, -) (*AccountTVShowsWatchlist, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/watchlist/tv?api_key=%s&session_id=%s%s", @@ -306,44 +263,9 @@ func (c *Client) GetTVShowsWatchlist( c.sessionID, options, ) - tvShowsWatchlist := AccountTVShowsWatchlist{} + tvShowsWatchlist := PaginatedTVShowResults{} if err := c.get(tmdbURL, &tvShowsWatchlist); err != nil { return nil, err } return &tvShowsWatchlist, nil } - -// AccountWatchlist type is a struct for movies or TV shows -// watchlist JSON request. -type AccountWatchlist struct { - MediaType string `json:"media_type"` - MediaID int64 `json:"media_id"` - Watchlist bool `json:"watchlist"` -} - -// AddToWatchlist add a movie or TV show to your watchlist. -// -// https://developers.themoviedb.org/3/account/add-to-watchlist -func (c *Client) AddToWatchlist( - id int, - title *AccountWatchlist, -) (*Response, error) { - tmdbURL := fmt.Sprintf( - "%s%s%d/watchlist?api_key=%s&session_id=%s", - baseURL, - accountURL, - id, - c.apiKey, - c.sessionID, - ) - addToWatchlist := Response{} - if err := c.request( - tmdbURL, - title, - http.MethodPost, - &addToWatchlist, - ); err != nil { - return nil, err - } - return &addToWatchlist, nil -} diff --git a/account_struct.go b/account_struct.go new file mode 100644 index 0000000..61d6aac --- /dev/null +++ b/account_struct.go @@ -0,0 +1,40 @@ +package tmdb + +type Gravatar struct { + Hash string `json:"hash"` +} +type TMDB struct { + AvatarPath *string `json:"avatar_path"` +} + +type Avatar struct { + Gravatar `json:"gravatar"` + TMDB `json:"tmdb"` +} + +// AccountDetails type is a struct for details JSON response. +type AccountDetails struct { + Avatar Avatar `json:"avatar"` + ID int64 `json:"id"` + Iso639_1 string `json:"iso_639_1"` + Iso3166_1 string `json:"iso_3166_1"` + Name string `json:"name"` + IncludeAdult bool `json:"include_adult"` + Username string `json:"username"` +} + +// AccountFavorite type is a struct for movies or TV shows +// favorite JSON request. +type AccountFavorite struct { + MediaType MediaType `json:"media_type"` + MediaID int64 `json:"media_id"` + Favorite bool `json:"favorite"` +} + +// AccountWatchlist type is a struct for movies or TV shows +// watchlist JSON request. +type AccountWatchlist struct { + MediaType MediaType `json:"media_type"` + MediaID int64 `json:"media_id"` + Watchlist bool `json:"watchlist"` +} diff --git a/account_test.go b/account_test.go index 65a54ed..e4b2fbb 100644 --- a/account_test.go +++ b/account_test.go @@ -97,7 +97,7 @@ func (suite *TMBDTestSuite) TestMarkAsFavorite() { MediaID: 500, Favorite: true, } - response, err := suite.client.MarkAsFavorite(0, &markAsFavorite) + response, err := suite.client.MarkAsFavorite(0, markAsFavorite) suite.Nil(err) suite.NotNil(response.StatusMessage) } @@ -109,7 +109,7 @@ func (suite *TMBDTestSuite) TestMarkAsFavoriteFail() { MediaID: 500, Favorite: true, } - _, err := suite.client.MarkAsFavorite(0, &markAsFavorite) + _, err := suite.client.MarkAsFavorite(0, markAsFavorite) suite.NotNil(err) } @@ -246,7 +246,7 @@ func (suite *TMBDTestSuite) TestAddToWatchlist() { MediaID: 82856, Watchlist: true, } - response, err := suite.client.AddToWatchlist(0, &addToWatchlist) + response, err := suite.client.AddToWatchlist(0, addToWatchlist) suite.Nil(err) suite.NotNil(response.StatusMessage) } @@ -258,6 +258,6 @@ func (suite *TMBDTestSuite) TestAddToWatchlistFail() { MediaID: 82856, Watchlist: true, } - _, err := suite.client.AddToWatchlist(0, &addToWatchlist) + _, err := suite.client.AddToWatchlist(0, addToWatchlist) suite.NotNil(err) } diff --git a/certifications.go b/certifications.go index c20c7a6..918b9dd 100644 --- a/certifications.go +++ b/certifications.go @@ -2,18 +2,6 @@ package tmdb import "fmt" -// Certification type is a struct for a single certification JSON response. -type Certification struct { - Certification string `json:"certification"` - Meaning string `json:"meaning"` - Order int `json:"order"` -} - -// Certifications type is a struct for movie and tv certifications JSON response. -type Certifications struct { - Certifications map[string][]Certification `json:"certifications"` -} - // GetCertificationMovie get an up to date list of the // officially supported movie certifications on TMDb. // diff --git a/certifications_struct.go b/certifications_struct.go new file mode 100644 index 0000000..9af0af7 --- /dev/null +++ b/certifications_struct.go @@ -0,0 +1,13 @@ +package tmdb + +// Certification type is a struct for a single certification JSON response. +type Certification struct { + Certification string `json:"certification"` + Meaning string `json:"meaning"` + Order int `json:"order"` +} + +// Certifications type is a struct for movie and tv certifications JSON response. +type Certifications struct { + Certifications map[string][]Certification `json:"certifications"` +} diff --git a/changes.go b/changes.go index d1b17c0..dedee89 100644 --- a/changes.go +++ b/changes.go @@ -2,12 +2,6 @@ package tmdb import "fmt" -// ChangesMovie type is a struct for movie changes JSON response. -type ChangesMovie struct { - *ChangesMovieResults - PaginatedResultsMeta -} - // GetChangesMovie get a list of all of the movie ids // that have been changed in the past 24 hours. // @@ -15,10 +9,10 @@ type ChangesMovie struct { // at a time with the start_date and end_date query parameters. // 100 items are returned per page. // -// https://developers.themoviedb.org/3/changes/get-movie-change-list +// https://developer.themoviedb.org/reference/changes-movie-list func (c *Client) GetChangesMovie( urlOptions map[string]string, -) (*ChangesMovie, error) { +) (*PaginatedChangesMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%schanges?api_key=%s%s", @@ -27,71 +21,61 @@ func (c *Client) GetChangesMovie( c.apiKey, options, ) - changesMovies := ChangesMovie{} + changesMovies := PaginatedChangesMediaResults{} if err := c.get(tmdbURL, &changesMovies); err != nil { return nil, err } return &changesMovies, nil } -// ChangesTV type is a struct for tv changes JSON response. -type ChangesTV struct { - *ChangesMovie -} - -// GetChangesTV get a list of all of the TV show ids +// GetChangesPerson get a list of all of the person ids // that have been changed in the past 24 hours. // // You can query it for up to 14 days worth of changed IDs // at a time with the start_date and end_date query parameters. // 100 items are returned per page. // -// https://developers.themoviedb.org/3/changes/get-tv-change-list -func (c *Client) GetChangesTV( +// https://developer.themoviedb.org/reference/changes-people-list +func (c *Client) GetChangesPerson( urlOptions map[string]string, -) (*ChangesTV, error) { +) (*PaginatedChangesMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%schanges?api_key=%s%s", baseURL, - tvURL, + personURL, c.apiKey, options, ) - changesTV := ChangesTV{} - if err := c.get(tmdbURL, &changesTV); err != nil { + changesPerson := PaginatedChangesMediaResults{} + if err := c.get(tmdbURL, &changesPerson); err != nil { return nil, err } - return &changesTV, nil -} - -// ChangesPerson type is a struct for person changes JSON response. -type ChangesPerson struct { - *ChangesMovie + return &changesPerson, nil } -// GetChangesPerson get a list of all of the person ids +// GetChangesTV get a list of all of the TV show ids // that have been changed in the past 24 hours. // // You can query it for up to 14 days worth of changed IDs // at a time with the start_date and end_date query parameters. // 100 items are returned per page. // -// https://developers.themoviedb.org/3/changes/get-person-change-list -func (c *Client) GetChangesPerson( +// https://developer.themoviedb.org/reference/changes-tv-list +func (c *Client) GetChangesTV( urlOptions map[string]string, -) (*ChangesPerson, error) { +) (*PaginatedChangesMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%schanges?api_key=%s%s", baseURL, - personURL, + tvURL, c.apiKey, options, ) - changesPerson := ChangesPerson{} - if err := c.get(tmdbURL, &changesPerson); err != nil { + changesTV := PaginatedChangesMediaResults{} + if err := c.get(tmdbURL, &changesTV); err != nil { return nil, err } - return &changesPerson, nil + return &changesTV, nil } diff --git a/collections.go b/collections.go index 4b6f180..7e932e7 100644 --- a/collections.go +++ b/collections.go @@ -2,34 +2,9 @@ package tmdb import "fmt" -// CollectionDetails type is a struct for details JSON response. -type CollectionDetails struct { - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - BackdropPath string `json:"backdrop_path"` - Parts []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - MediaType string `json:"media_type"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date"` - Title string `json:"title"` - Video bool `json:"video"` - Popularity float32 `json:"popularity"` - VoteMetrics - } `json:"parts"` -} - // GetCollectionDetails get collection details by id. // -// https://developers.themoviedb.org/3/collections/get-collection-details +// https://developer.themoviedb.org/reference/collection-details func (c *Client) GetCollectionDetails( id int, urlOptions map[string]string, @@ -46,22 +21,9 @@ func (c *Client) GetCollectionDetails( return &collectionDetails, nil } -// CollectionImage type is a struct for a single image. -type CollectionImage struct { - ImageBase - Iso639_1 string `json:"iso_639_1"` -} - -// CollectionImages type is a struct for images JSON response. -type CollectionImages struct { - ID int64 `json:"id"` - Backdrops []CollectionImage `json:"backdrops"` - Posters []CollectionImage `json:"posters"` -} - // GetCollectionImages get the images for a collection by id. // -// https://developers.themoviedb.org/3/collections/get-collection-images +// https://developer.themoviedb.org/reference/collection-images func (c *Client) GetCollectionImages( id int, urlOptions map[string]string, @@ -78,15 +40,9 @@ func (c *Client) GetCollectionImages( return &collectionImages, nil } -// CollectionTranslations type is a struct for translations JSON response. -type CollectionTranslations struct { - ID int64 `json:"id"` - Translations []Translation `json:"translations"` -} - // GetCollectionTranslations get the list translations for a collection by id. // -// https://developers.themoviedb.org/3/collections/get-collection-translations +// https://developer.themoviedb.org/reference/collection-translations func (c *Client) GetCollectionTranslations( id int, urlOptions map[string]string, diff --git a/collections_struct.go b/collections_struct.go new file mode 100644 index 0000000..6877f13 --- /dev/null +++ b/collections_struct.go @@ -0,0 +1,24 @@ +package tmdb + +// CollectionDetails type is a struct for details JSON response. +type CollectionDetails struct { + ID int64 `json:"id"` + Name string `json:"name"` + Overview string `json:"overview"` + PosterPath string `json:"poster_path"` + BackdropPath string `json:"backdrop_path"` + Parts []MovieMedia `json:"parts"` +} + +// CollectionImages type is a struct for images JSON response. +type CollectionImages struct { + ID int64 `json:"id"` + Backdrops []ImageIso `json:"backdrops"` + Posters []ImageIso `json:"posters"` +} + +// CollectionTranslations type is a struct for translations JSON response. +type CollectionTranslations struct { + ID int64 `json:"id"` + Translations []CollectionTranslation `json:"translations"` +} diff --git a/companies.go b/companies.go index c530f78..b6e832b 100644 --- a/companies.go +++ b/companies.go @@ -6,18 +6,11 @@ import ( // CompanyDetails type is a struct for details JSON response. type CompanyDetails struct { - Description string `json:"description"` - Headquarters string `json:"headquarters"` - Homepage string `json:"homepage"` - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - Name string `json:"name"` - OriginCountry string `json:"origin_country"` - ParentCompany struct { - Name string `json:"name"` - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - } `json:"parent_company"` + CompanyInfo + Description string `json:"description"` + Headquarters string `json:"headquarters"` + Homepage string `json:"homepage"` + ParentCompany *CompanyInfo `json:"parent_company"` } // GetCompanyDetails get a companies details by id. @@ -40,19 +33,12 @@ func (c *Client) GetCompanyDetails( return &companyDetails, nil } -// CompanyAlternativeNames type is a struct for alternative -// names JSON response. -type CompanyAlternativeNames struct { - ID int64 `json:"id"` - *CompanyAlternativeNamesResult -} - // GetCompanyAlternativeNames get the alternative names of a company. // -// https://developers.themoviedb.org/3/companies/get-company-alternative-names +// https://developer.themoviedb.org/reference/company-alternative-names func (c *Client) GetCompanyAlternativeNames( id int, -) (*CompanyAlternativeNames, error) { +) (*IDAlternativeNameResults, error) { tmdbURL := fmt.Sprintf( "%s%s%d/alternative_names?api_key=%s", baseURL, @@ -60,7 +46,7 @@ func (c *Client) GetCompanyAlternativeNames( id, c.apiKey, ) - companyAlternativeNames := CompanyAlternativeNames{} + companyAlternativeNames := IDAlternativeNameResults{} if err := c.get(tmdbURL, &companyAlternativeNames); err != nil { return nil, err } diff --git a/configuration.go b/configuration.go index 84af178..e55346d 100644 --- a/configuration.go +++ b/configuration.go @@ -2,20 +2,44 @@ package tmdb import "fmt" +type ImagesConfiguration struct { + BaseURL string `json:"base_url"` + SecureBaseURL string `json:"secure_base_url"` + BackdropSizes []string `json:"backdrop_sizes"` + LogoSizes []string `json:"logo_sizes"` + PosterSizes []string `json:"poster_sizes"` + ProfileSizes []string `json:"profile_sizes"` + StillSizes []string `json:"still_sizes"` +} + // ConfigurationAPI type is a struct for api configuration JSON response. type ConfigurationAPI struct { - Images struct { - BaseURL string `json:"base_url"` - SecureBaseURL string `json:"secure_base_url"` - BackdropSizes []string `json:"backdrop_sizes"` - LogoSizes []string `json:"logo_sizes"` - PosterSizes []string `json:"poster_sizes"` - ProfileSizes []string `json:"profile_sizes"` - StillSizes []string `json:"still_sizes"` - } `json:"images"` - ChangeKeys []string `json:"change_keys"` + Images ImagesConfiguration `json:"images"` + ChangeKeys []string `json:"change_keys"` } +// ConfigurationCountries type is a struct for countries configuration JSON response. +type ConfigurationCountries []Country + +// ConfigurationJobs type is a struct for jobs configuration JSON response. +type ConfigurationJobs []Jobs + +// ConfigurationLanguages type is a struct for languages configuration JSON response. +type ConfigurationLanguages []SpokenLanguage + +// ConfigurationPrimaryTranslations type is a struct for +// primary translations configuration JSON response. +type ConfigurationPrimaryTranslations []string + +type Timezones struct { + Iso3166_1 string `json:"iso_3166_1"` + Zones []string `json:"zones"` +} + +// ConfigurationTimezones type is a struct for timezones +// configuration JSON response. +type ConfigurationTimezones []Timezones + // GetConfigurationAPI get the system wide configuration information. // // Some elements of the API require some knowledge of @@ -37,7 +61,7 @@ type ConfigurationAPI struct { // can be useful if you are building an app that consumes data from the // change feed. // -// https://developers.themoviedb.org/3/configuration/get-api-configuration +// https://developer.themoviedb.org/reference/configuration-details func (c *Client) GetConfigurationAPI() (*ConfigurationAPI, error) { tmdbURL := fmt.Sprintf( "%s/configuration?api_key=%s", @@ -51,17 +75,10 @@ func (c *Client) GetConfigurationAPI() (*ConfigurationAPI, error) { return &configurationAPI, nil } -// ConfigurationCountries type is a struct for countries configuration JSON response. -type ConfigurationCountries []struct { - Iso3166_1 string `json:"iso_3166_1"` - EnglishName string `json:"english_name"` - NativeName string `json:"native_name"` -} - // GetConfigurationCountries get the list of countries // (ISO 3166-1 tags) used throughout TMDb. // -// https://developers.themoviedb.org/3/configuration/get-countries +// https://developer.themoviedb.org/reference/configuration-countries func (c *Client) GetConfigurationCountries() ( *ConfigurationCountries, error, @@ -79,15 +96,9 @@ func (c *Client) GetConfigurationCountries() ( return &configurationCountries, nil } -// ConfigurationJobs type is a struct for jobs configuration JSON response. -type ConfigurationJobs []struct { - Department string `json:"department"` - Jobs []string `json:"jobs"` -} - // GetConfigurationJobs get a list of the jobs and departments we use on TMDb. // -// https://developers.themoviedb.org/3/configuration/get-jobs +// https://developer.themoviedb.org/reference/configuration-jobs func (c *Client) GetConfigurationJobs() (*ConfigurationJobs, error) { tmdbURL := fmt.Sprintf( "%s%sjobs?api_key=%s", @@ -102,17 +113,10 @@ func (c *Client) GetConfigurationJobs() (*ConfigurationJobs, error) { return &configurationJobs, nil } -// ConfigurationLanguages type is a struct for languages configuration JSON response. -type ConfigurationLanguages []struct { - Iso639_1 string `json:"iso_639_1"` - EnglishName string `json:"english_name"` - Name string `json:"name"` -} - // GetConfigurationLanguages get the list of languages // (ISO 639-1 tags) used throughout TMDb. // -// https://developers.themoviedb.org/3/configuration/get-languages +// https://developer.themoviedb.org/reference/configuration-languages func (c *Client) GetConfigurationLanguages() ( *ConfigurationLanguages, error, @@ -130,10 +134,6 @@ func (c *Client) GetConfigurationLanguages() ( return &configurationLanguages, nil } -// ConfigurationPrimaryTranslations type is a struct for -// primary translations configuration JSON response. -type ConfigurationPrimaryTranslations []string - // GetConfigurationPrimaryTranslations get a list of the officially // supported translations on TMDb. // @@ -155,7 +155,7 @@ type ConfigurationPrimaryTranslations []string // One more thing to mention, these are the translations that map to // our website translation project. // -// https://developers.themoviedb.org/3/configuration/get-primary-translations +// https://developer.themoviedb.org/reference/configuration-primary-translations func (c *Client) GetConfigurationPrimaryTranslations() ( *ConfigurationPrimaryTranslations, error, @@ -171,17 +171,10 @@ func (c *Client) GetConfigurationPrimaryTranslations() ( return &configurationPrimaryTranslations, nil } -// ConfigurationTimezones type is a struct for timezones -// configuration JSON response. -type ConfigurationTimezones []struct { - Iso3166_1 string `json:"iso_3166_1"` - Zones []string `json:"zones"` -} - // GetConfigurationTimezones get the list of timezones // used throughout TMDb. // -// https://developers.themoviedb.org/3/configuration/get-timezones +// https://developer.themoviedb.org/reference/configuration-timezones func (c *Client) GetConfigurationTimezones() ( *ConfigurationTimezones, error, diff --git a/credits.go b/credits.go index 273555c..32b9e85 100644 --- a/credits.go +++ b/credits.go @@ -6,74 +6,18 @@ import ( // CreditsDetails type is a struct for credits JSON response. type CreditsDetails struct { - CreditType string `json:"credit_type"` - Department string `json:"department"` - Job string `json:"job"` - Media struct { - Adult bool `json:"adult,omitempty"` // Movie - OriginalName string `json:"original_name,omitempty"` // TV - OriginalTitle string `json:"original_title,omitempty"` // Movie - ID int64 `json:"id"` - Name string `json:"name,omitempty"` // TV - FirstAirDate string `json:"first_air_date,omitempty"` // TV - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date,omitempty"` // Movie - Title string `json:"title,omitempty"` // Movie - Video bool `json:"video,omitempty"` // Movie - GenreIDs []int64 `json:"genre_ids"` - OriginalLanguage string `json:"original_language"` - BackdropPath string `json:"backdrop_path"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country,omitempty"` // TV - Popularity float32 `json:"popularity"` - Character string `json:"character"` - Episodes []struct { - AirDate string `json:"air_date"` - EpisodeNumber int64 `json:"episode_number"` - Name string `json:"name"` - Overview string `json:"overview"` - SeasonNumber int `json:"season_number"` - StillPath string `json:"still_path"` - } `json:"episodes,omitempty"` // TV - Seasons []Season `json:"seasons,omitempty"` // TV - VoteMetrics - } `json:"media"` - MediaType string `json:"media_type"` - ID string `json:"id"` - Person struct { - Adult bool `json:"adult"` - Gender int `json:"gender"` - Name string `json:"name"` - ID int64 `json:"id"` - KnownFor []struct { - Adult bool `json:"adult,omitempty"` - BackdropPath string `json:"backdrop_path"` - // GenreIDs []int64 `json:"genre_ids"` // FIXME: -> []float32 - // ID int64 `json:"id"` // FIXME: -> float32 - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title,omitempty"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date,omitempty"` - Title string `json:"title,omitempty"` - Video bool `json:"video,omitempty"` - Popularity float32 `json:"popularity"` - MediaType string `json:"media_type"` - OriginalName string `json:"original_name,omitempty"` - Name string `json:"name,omitempty"` - FirstAirDate string `json:"first_air_date,omitempty"` - OriginCountry []string `json:"origin_country,omitempty"` - VoteMetrics - } `json:"known_for"` - KnownForDepartment string `json:"known_for_department"` - ProfilePath string `json:"profile_path"` - Popularity float32 `json:"popularity"` - } `json:"person"` + CreditType string `json:"credit_type"` + Department string `json:"department"` + Job string `json:"job"` + Media CreditMedia `json:"media"` + MediaType MediaType `json:"media_type"` + ID string `json:"id"` + Person PersonMediaBase `json:"person"` } // GetCreditDetails get a movie or TV credit details by id. // -// https://developers.themoviedb.org/3/credits/get-credit-details +// https://developer.themoviedb.org/reference/credit-details func (c *Client) GetCreditDetails( id string, ) (*CreditsDetails, error) { diff --git a/discover.go b/discover.go index dfca864..2f4842d 100644 --- a/discover.go +++ b/discover.go @@ -2,12 +2,6 @@ package tmdb import "fmt" -// DiscoverMovie type is a struct for movie JSON response. -type DiscoverMovie struct { - PaginatedResultsMeta - *DiscoverMovieResults -} - // GetDiscoverMovie discover movies by different types of data like // average rating, number of votes, genres and certifications. You can // get a valid list of certifications from the method. @@ -34,7 +28,7 @@ type DiscoverMovie struct { // https://developers.themoviedb.org/3/discover/movie-discover func (c *Client) GetDiscoverMovie( urlOptions map[string]string, -) (*DiscoverMovie, error) { +) (*PaginatedMovieMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%smovie?api_key=%s%s", @@ -43,19 +37,13 @@ func (c *Client) GetDiscoverMovie( c.apiKey, options, ) - discoverMovie := DiscoverMovie{} + discoverMovie := PaginatedMovieMediaResults{} if err := c.get(tmdbURL, &discoverMovie); err != nil { return nil, err } return &discoverMovie, nil } -// DiscoverTV type is a struct for tv JSON response. -type DiscoverTV struct { - PaginatedResultsMeta - *DiscoverTVResults -} - // GetDiscoverTV Discover TV shows by different types of data like average // rating, number of votes, genres, the network they aired on and air dates. // @@ -68,7 +56,7 @@ type DiscoverTV struct { // https://developers.themoviedb.org/3/discover/tv-discover func (c *Client) GetDiscoverTV( urlOptions map[string]string, -) (*DiscoverTV, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%stv?api_key=%s%s", @@ -77,7 +65,7 @@ func (c *Client) GetDiscoverTV( c.apiKey, options, ) - discoverTV := DiscoverTV{} + discoverTV := PaginatedTVShowResults{} if err := c.get(tmdbURL, &discoverTV); err != nil { return nil, err } diff --git a/examples/search/main.go b/examples/search/main.go index 20c8a20..fadfa21 100644 --- a/examples/search/main.go +++ b/examples/search/main.go @@ -25,14 +25,14 @@ func main() { } // Iterate - for _, v := range search.Results { - switch v.MediaType { - case "movie": - fmt.Println("Movie Title: ", v.Title) - case "tv": - fmt.Println("TV Show: ", v.Name) - case "person": - fmt.Println("Person: ", v.Name) + for _, result := range search.Results { + switch media := result.(type) { + case tmdb.MovieMedia: + fmt.Println("Movie Title: ", media.Title) + case tmdb.TVShowMedia: + fmt.Println("TV Show: ", media.Name) + case tmdb.PersonMedia: + fmt.Println("Person: ", media.Name) } } } diff --git a/examples/trending/main.go b/examples/trending/main.go index 78750bf..5163aa4 100644 --- a/examples/trending/main.go +++ b/examples/trending/main.go @@ -21,7 +21,12 @@ func main() { } for _, result := range trending.Results { - fmt.Println(result.Title) + switch media := result.(type) { + case tmdb.MovieMedia: + fmt.Println(media.Title) + case tmdb.TVShowMedia: + fmt.Println(media.OriginalName) + } } fmt.Println("------") @@ -38,6 +43,11 @@ func main() { } for _, result := range trending.Results { - fmt.Println(result.Name) + switch media := result.(type) { + case tmdb.MovieMedia: + fmt.Println(media.Title) + case tmdb.TVShowMedia: + fmt.Println(media.OriginalName) + } } } diff --git a/find.go b/find.go index 81d41d9..7e8a618 100644 --- a/find.go +++ b/find.go @@ -4,83 +4,11 @@ import "fmt" // FindByID type is a struct for find JSON response. type FindByID struct { - MovieResults []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date"` - Title string `json:"title"` - Video bool `json:"video"` - Popularity float32 `json:"popularity"` - VoteMetrics - } `json:"movie_results,omitempty"` - PersonResults []struct { - Adult bool `json:"adult"` - Gender int `json:"gender"` - Name string `json:"name"` - ID int64 `json:"id"` - KnownFor []struct { - Adult bool `json:"adult,omitempty"` // Movie - BackdropPath string `json:"backdrop_path"` - FirstAirDate string `json:"first_air_date,omitempty"` // TV - // GenreIDs []int64 `json:"genre_ids"` // FIXME: -> []float32 - // ID int64 `json:"id"` // FIXME: -> float32 - MediaType string `json:"media_type"` - Name string `json:"name,omitempty"` // TV - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name,omitempty"` // TV - OriginalTitle string `json:"original_title,omitempty"` // Movie - OriginCountry []string `json:"origin_country,omitempty"` // TV - Overview string `json:"overview"` - Popularity float32 `json:"popularity"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date,omitempty"` // Movie - Title string `json:"title,omitempty"` // Movie - Video bool `json:"video,omitempty"` // Movie - VoteMetrics - } `json:"known_for"` - KnownForDepartment string `json:"known_for_department"` - ProfilePath string `json:"profile_path"` - Popularity float32 `json:"popularity"` - } `json:"person_results,omitempty"` - TvResults []struct { - OriginalName string `json:"original_name"` - ID int64 `json:"id"` - Name string `json:"name"` - FirstAirDate string `json:"first_air_date"` - PosterPath string `json:"poster_path"` - GenreIDs []int64 `json:"genre_ids"` - OriginalLanguage string `json:"original_language"` - BackdropPath string `json:"backdrop_path"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country"` - Popularity float32 `json:"popularity"` - VoteMetrics - } `json:"tv_results,omitempty"` - TvEpisodeResults []struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode string `json:"production_code"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - VoteMetrics - } `json:"tv_episode_results,omitempty"` - TvSeasonResults []struct { - AirDate string `json:"air_date"` - Name string `json:"name"` - ID int64 `json:"id"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - } `json:"tv_season_results,omitempty"` + MovieResults []MovieMedia `json:"movie_results"` + PersonResults []PersonMedia `json:"person_results"` + TvResults []TVShowMedia `json:"tv_results"` + TvEpisodeResults []TVEpisodeMedia `json:"tv_episode_results"` + TvSeasonResults []TVSeasonMedia `json:"tv_season_results"` } // GetFindByID the find method makes it easy to search for objects in our diff --git a/guest_sessions.go b/guest_sessions.go index 5471ba3..2962d8c 100644 --- a/guest_sessions.go +++ b/guest_sessions.go @@ -2,34 +2,13 @@ package tmdb import "fmt" -// GuestSessionRatedMovies type is a struct for rated movies JSON response. -type GuestSessionRatedMovies struct { - Results []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - PosterPath string `json:"poster_path"` - Popularity float32 `json:"popularity"` - Title string `json:"title"` - Video bool `json:"video"` - Rating float32 `json:"rating"` - VoteMetrics - } `json:"results"` - PaginatedResultsMeta -} - // GetGuestSessionRatedMovies get the rated movies for a guest session. // // https://developers.themoviedb.org/3/guest-sessions/get-guest-session-rated-movies func (c *Client) GetGuestSessionRatedMovies( id string, urlOptions map[string]string, -) (*GuestSessionRatedMovies, error) { +) (*PaginatedMovieRatingResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%s/rated/movies?api_key=%s%s", @@ -39,40 +18,20 @@ func (c *Client) GetGuestSessionRatedMovies( c.apiKey, options, ) - guestSessionRatedMovies := GuestSessionRatedMovies{} + guestSessionRatedMovies := PaginatedMovieRatingResults{} if err := c.get(tmdbURL, &guestSessionRatedMovies); err != nil { return nil, err } return &guestSessionRatedMovies, nil } -// GuestSessionRatedTVShows type is a struct for rated tv shows JSON response. -type GuestSessionRatedTVShows struct { - Results []struct { - BackdropPath string `json:"backdrop_path"` - FirstAirDate string `json:"first_air_date"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country"` - PosterPath string `json:"poster_path"` - Popularity float32 `json:"popularity"` - Name string `json:"name"` - Rating float32 `json:"rating"` - VoteMetrics - } `json:"results"` - PaginatedResultsMeta -} - // GetGuestSessionRatedTVShows get the rated TV shows for a guest session. // // https://developers.themoviedb.org/3/guest-sessions/get-guest-session-rated-tv-shows func (c *Client) GetGuestSessionRatedTVShows( id string, urlOptions map[string]string, -) (*GuestSessionRatedTVShows, error) { +) (*PaginatedTVShowRatingResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%s/rated/tv?api_key=%s%s", @@ -82,38 +41,20 @@ func (c *Client) GetGuestSessionRatedTVShows( c.apiKey, options, ) - guestSessionRatedTVShows := GuestSessionRatedTVShows{} + guestSessionRatedTVShows := PaginatedTVShowRatingResults{} if err := c.get(tmdbURL, &guestSessionRatedTVShows); err != nil { return nil, err } return &guestSessionRatedTVShows, nil } -// GuestSessionRatedTVEpisodes type is a struct for rated tv episodes JSON response. -type GuestSessionRatedTVEpisodes struct { - Results []struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode string `json:"production_code"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - Rating float32 `json:"rating"` - VoteMetrics - } `json:"results"` - PaginatedResultsMeta -} - // GetGuestSessionRatedTVEpisodes get the rated TV episodes for a guest session. // // https://developers.themoviedb.org/3/guest-sessions/get-gest-session-rated-tv-episodes func (c *Client) GetGuestSessionRatedTVEpisodes( id string, urlOptions map[string]string, -) (*GuestSessionRatedTVEpisodes, error) { +) (*PaginatedTVEpisodeRatingResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%s/rated/tv/episodes?api_key=%s%s", @@ -123,7 +64,7 @@ func (c *Client) GetGuestSessionRatedTVEpisodes( c.apiKey, options, ) - guestSessionRatedTVEpisodes := GuestSessionRatedTVEpisodes{} + guestSessionRatedTVEpisodes := PaginatedTVEpisodeRatingResults{} if err := c.get(tmdbURL, &guestSessionRatedTVEpisodes); err != nil { return nil, err } diff --git a/keywords.go b/keywords.go index a545ed5..8f2d50f 100644 --- a/keywords.go +++ b/keywords.go @@ -2,18 +2,12 @@ package tmdb import "fmt" -// KeywordDetails type is a struct for keyword JSON response. -type KeywordDetails struct { - ID int64 `json:"id"` - Name string `json:"name"` -} - // GetKeywordDetails get keyword details by id. // -// https://developers.themoviedb.org/3/keywords/get-keyword-details +// https://developer.themoviedb.org/reference/keyword-details func (c *Client) GetKeywordDetails( id int, -) (*KeywordDetails, error) { +) (*Keyword, error) { tmdbURL := fmt.Sprintf( "%s%s%d?api_key=%s", baseURL, @@ -21,44 +15,27 @@ func (c *Client) GetKeywordDetails( id, c.apiKey, ) - keywordDetails := KeywordDetails{} + keywordDetails := Keyword{} if err := c.get(tmdbURL, &keywordDetails); err != nil { return nil, err } return &keywordDetails, nil } -// KeywordMovies type is a struct for movies that belong to a keyword JSON response. -type KeywordMovies struct { - ID int64 `json:"id"` - Results []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date"` - Title string `json:"title"` - Video bool `json:"video"` - Popularity float32 `json:"popularity"` - VoteMetrics - } `json:"results"` - PaginatedResultsMeta -} - +// Deprecated: Use GetDiscoverMovie instead. +// // GetKeywordMovies get the movies that belong to a keyword. // // We highly recommend using movie discover instead of this // method as it is much more flexible. // -// https://developers.themoviedb.org/3/keywords/get-movies-by-keyword +// This endpoint is deprecated in the TMDB API. +// +// https://developer.themoviedb.org/reference/keyword-movies func (c *Client) GetKeywordMovies( id int, urlOptions map[string]string, -) (*KeywordMovies, error) { +) (*IDPaginatedMovieResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/movies?api_key=%s%s", @@ -68,7 +45,7 @@ func (c *Client) GetKeywordMovies( c.apiKey, options, ) - keywordMovies := KeywordMovies{} + keywordMovies := IDPaginatedMovieResults{} if err := c.get(tmdbURL, &keywordMovies); err != nil { return nil, err } diff --git a/list.go b/list.go index b74f716..25181e1 100644 --- a/list.go +++ b/list.go @@ -7,34 +7,28 @@ import ( // ListDetails type is a struct for details JSON response. type ListDetails struct { - CreatedBy string `json:"created_by"` - Description string `json:"description"` - FavoriteCount int64 `json:"favorite_count"` - ID int64 `json:"id"` - Items []struct { - Adult bool `json:"adult,omitempty"` // Movie - BackdropPath string `json:"backdrop_path"` - FirstAirDate string `json:"first_air_date,omitempty"` // TV - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - MediaType string `json:"media_type"` - Name string `json:"name,omitempty"` // TV - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name,omitempty"` // TV - OriginalTitle string `json:"original_title,omitempty"` // Movie - OriginCountry []string `json:"origin_country,omitempty"` // TV - Overview string `json:"overview"` - Popularity float32 `json:"popularity"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date,omitempty"` // Movie - Title string `json:"title,omitempty"` // Movie - Video bool `json:"video,omitempty"` // Movie + List + CreatedBy string `json:"created_by"` + Items []struct { + Adult bool `json:"adult,omitempty"` // Movie + BackdropPath string `json:"backdrop_path"` + FirstAirDate string `json:"first_air_date,omitempty"` // TV + GenreIDs []int64 `json:"genre_ids"` + ID int64 `json:"id"` + MediaType MediaType `json:"media_type"` + Name string `json:"name,omitempty"` // TV + OriginalLanguage string `json:"original_language"` + OriginalName string `json:"original_name,omitempty"` // TV + OriginalTitle string `json:"original_title,omitempty"` // Movie + OriginCountry []string `json:"origin_country,omitempty"` // TV + Overview string `json:"overview"` + Popularity float32 `json:"popularity"` + PosterPath string `json:"poster_path"` + ReleaseDate string `json:"release_date,omitempty"` // Movie + Title string `json:"title,omitempty"` // Movie + Video bool `json:"video,omitempty"` // Movie VoteMetrics } `json:"items"` - ItemCount int64 `json:"item_count"` - Iso639_1 string `json:"iso_639_1"` - Name string `json:"name"` - PosterPath string `json:"poster_path"` } // GetListDetails get the details of a list. diff --git a/movie_list_test.go b/movie_list_test.go new file mode 100644 index 0000000..06b0416 --- /dev/null +++ b/movie_list_test.go @@ -0,0 +1,81 @@ +package tmdb + +func (suite *TMBDTestSuite) TestGetMovieNowPlaying() { + movies, err := suite.client.GetMovieNowPlaying(nil) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMovieNowPlayingFail() { + suite.client.apiKey = "" + _, err := suite.client.GetMovieNowPlaying(nil) + suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) +} + +func (suite *TMBDTestSuite) TestGetMovieNowPlayingWithOptions() { + options := make(map[string]string) + options["language"] = "en-US" + movies, err := suite.client.GetMovieNowPlaying(options) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMoviePopular() { + movies, err := suite.client.GetMoviePopular(nil) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMoviePopularFail() { + suite.client.apiKey = "" + _, err := suite.client.GetMoviePopular(nil) + suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) +} + +func (suite *TMBDTestSuite) TestGetMoviePopularWithOptions() { + options := make(map[string]string) + options["language"] = "en-US" + movies, err := suite.client.GetMoviePopular(options) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMovieTopRated() { + movies, err := suite.client.GetMovieTopRated(nil) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMovieTopRatedFail() { + suite.client.apiKey = "" + _, err := suite.client.GetMovieTopRated(nil) + suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) +} + +func (suite *TMBDTestSuite) TestGetMovieTopRatedWithOptions() { + options := make(map[string]string) + options["language"] = "en-US" + movies, err := suite.client.GetMovieTopRated(options) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMovieUpcoming() { + movies, err := suite.client.GetMovieUpcoming(nil) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} + +func (suite *TMBDTestSuite) TestGetMovieUpcomingFail() { + suite.client.apiKey = "" + _, err := suite.client.GetMovieUpcoming(nil) + suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) +} + +func (suite *TMBDTestSuite) TestGetMovieUpcomingWithOptions() { + options := make(map[string]string) + options["language"] = "en-US" + movies, err := suite.client.GetMovieUpcoming(options) + suite.Nil(err) + suite.Equal(int64(1), movies.Page) +} diff --git a/movie_lists.go b/movie_lists.go new file mode 100644 index 0000000..a42698b --- /dev/null +++ b/movie_lists.go @@ -0,0 +1,103 @@ +package tmdb + +import "fmt" + +// GetMovieNowPlaying get a list of movies in theatres. +// +// This is a release type query that looks for all movies that +// have a release type of 2 or 3 within the specified date range. +// +// You can optionally specify a region prameter which will narrow +// the search to only look for theatrical release dates within the +// specified country. +// +// https://developer.themoviedb.org/reference/movie-now-playing-list +func (c *Client) GetMovieNowPlaying( + urlOptions map[string]string, +) (*MovieListsDateResult, error) { + options := c.fmtOptions(urlOptions) + tmdbURL := fmt.Sprintf( + "%s%snow_playing?api_key=%s%s", + baseURL, + movieURL, + c.apiKey, + options, + ) + movieNowPlaying := MovieListsDateResult{} + if err := c.get(tmdbURL, &movieNowPlaying); err != nil { + return nil, err + } + return &movieNowPlaying, nil +} + +// GetMoviePopular get a list of the current popular movies on TMDb. +// +// This list updates daily. +// +// https://developer.themoviedb.org/reference/movie-popular-list +func (c *Client) GetMoviePopular( + urlOptions map[string]string, +) (*PaginatedMovieResults, error) { + options := c.fmtOptions(urlOptions) + tmdbURL := fmt.Sprintf( + "%s%spopular?api_key=%s%s", + baseURL, + movieURL, + c.apiKey, + options, + ) + moviePopular := PaginatedMovieResults{} + if err := c.get(tmdbURL, &moviePopular); err != nil { + return nil, err + } + return &moviePopular, nil +} + +// GetMovieTopRated get the top rated movies on TMDb. +// +// https://developer.themoviedb.org/reference/movie-top-rated-list +func (c *Client) GetMovieTopRated( + urlOptions map[string]string, +) (*PaginatedMovieResults, error) { + options := c.fmtOptions(urlOptions) + tmdbURL := fmt.Sprintf( + "%s%stop_rated?api_key=%s%s", + baseURL, + movieURL, + c.apiKey, + options, + ) + movieTopRated := PaginatedMovieResults{} + if err := c.get(tmdbURL, &movieTopRated); err != nil { + return nil, err + } + return &movieTopRated, nil +} + +// GetMovieUpcoming get a list of upcoming movies in theatres. +// +// This is a release type query that looks for all movies that +// have a release type of 2 or 3 within the specified date range. +// +// You can optionally specify a region prameter which will narrow +// the search to only look for theatrical release dates within +// the specified country. +// +// https://developer.themoviedb.org/reference/movie-upcoming-list +func (c *Client) GetMovieUpcoming( + urlOptions map[string]string, +) (*MovieListsDateResult, error) { + options := c.fmtOptions(urlOptions) + tmdbURL := fmt.Sprintf( + "%s%supcoming?api_key=%s%s", + baseURL, + movieURL, + c.apiKey, + options, + ) + movieUpcoming := MovieListsDateResult{} + if err := c.get(tmdbURL, &movieUpcoming); err != nil { + return nil, err + } + return &movieUpcoming, nil +} diff --git a/movie_lists_struct.go b/movie_lists_struct.go new file mode 100644 index 0000000..fe22eae --- /dev/null +++ b/movie_lists_struct.go @@ -0,0 +1,11 @@ +package tmdb + +type Dates struct { + Maximum string `json:"maximum"` + Minimum string `json:"minimum"` +} + +type MovieListsDateResult struct { + Dates Dates `json:"dates"` + PaginatedMovieResults +} diff --git a/movies.go b/movies.go index 56cb61e..4a118bc 100644 --- a/movies.go +++ b/movies.go @@ -3,135 +3,11 @@ package tmdb import ( "fmt" "net/http" - - json "github.com/goccy/go-json" ) -// MovieDetails type is a struct for movie details JSON response. -type MovieDetails struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - BelongsToCollection BelongsToCollection `json:"belongs_to_collection"` - Budget int64 `json:"budget"` - Genres []Genre `json:"genres"` - Homepage string `json:"homepage"` - ID int64 `json:"id"` - IMDbID string `json:"imdb_id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - Popularity float32 `json:"popularity"` - PosterPath string `json:"poster_path"` - OriginCountry []string `json:"origin_country"` - ProductionCompanies []ProductionCompany `json:"production_companies"` - ProductionCountries []ProductionCountry `json:"production_countries"` - ReleaseDate string `json:"release_date"` - Revenue int64 `json:"revenue"` - Runtime int `json:"runtime"` - SpokenLanguages []SpokenLanguage `json:"spoken_languages"` - Status string `json:"status"` - Tagline string `json:"tagline"` - Title string `json:"title"` - Video bool `json:"video"` - VoteMetrics - *MovieAlternativeTitlesAppend - *MovieChangesAppend - *MovieCreditsAppend - *MovieExternalIDsAppend - *MovieImagesAppend - *MovieKeywordsAppend - *MovieReleaseDatesAppend - *MovieVideosAppend - *MovieTranslationsAppend - *MovieRecommendationsAppend - *MovieSimilarAppend - *MovieReviewsAppend - *MovieListsAppend - *MovieWatchProvidersAppend -} - -// MovieAlternativeTitlesAppend type is a struct for alternative -// titles in append to response. -type MovieAlternativeTitlesAppend struct { - AlternativeTitles *MovieAlternativeTitles `json:"alternative_titles,omitempty"` -} - -// MovieChangesAppend type is a struct for changes in append to response. -type MovieChangesAppend struct { - Changes *MovieChanges `json:"changes,omitempty"` -} - -// MovieCreditsAppend type is a struct for credits in append to response. -type MovieCreditsAppend struct { - Credits struct { - *MovieCredits - } `json:"credits,omitempty"` -} - -// MovieExternalIDsAppend type is a struct for external ids in append to response. -type MovieExternalIDsAppend struct { - *MovieExternalIDs `json:"external_ids,omitempty"` -} - -// MovieImagesAppend type is a struct for images in append to response. -type MovieImagesAppend struct { - Images *MovieImages `json:"images,omitempty"` -} - -// MovieReleaseDatesAppend type is a struct for release dates in append to response. -type MovieReleaseDatesAppend struct { - ReleaseDates *MovieReleaseDates `json:"release_dates,omitempty"` -} - -// MovieVideosAppend type is a struct for videos in append to response. -type MovieVideosAppend struct { - Videos *VideoResults `json:"videos"` -} - -// MovieTranslationsAppend type is a struct for translations in append to response. -type MovieTranslationsAppend struct { - Translations *MovieTranslations `json:"translations,omitempty"` -} - -// MovieRecommendationsAppend type is a struct for -// recommendations in append to response. -type MovieRecommendationsAppend struct { - Recommendations *MovieRecommendations `json:"recommendations,omitempty"` -} - -// MovieSimilarAppend type is a struct for similar movies in append to response. -type MovieSimilarAppend struct { - Similar *MovieSimilar `json:"similar,omitempty"` -} - -// MovieReviewsAppend type is a struct for reviews in append to response. -type MovieReviewsAppend struct { - Reviews struct { - *MovieReviews - } `json:"reviews,omitempty"` -} - -// MovieListsAppend type is a struct for lists in append to response. -type MovieListsAppend struct { - Lists *MovieLists `json:"lists,omitempty"` -} - -// MovieKeywordsAppend type is a struct for keywords in append to response. -type MovieKeywordsAppend struct { - Keywords struct { - *MovieKeywords - } `json:"keywords,omitempty"` -} - -// MovieWatchProvidersAppend type is a struct for -// watch/providers in append to response. -type MovieWatchProvidersAppend struct { - WatchProviders *WatchProviderResults `json:"watch/providers"` -} - // GetMovieDetails get the primary information about a movie. // -// https://developers.themoviedb.org/3/movies +// https://developer.themoviedb.org/reference/movie-details func (c *Client) GetMovieDetails( id int, urlOptions map[string]string, @@ -152,14 +28,6 @@ func (c *Client) GetMovieDetails( return &movieDetails, nil } -// MovieAccountStates type is a struct for account states JSON response. -type MovieAccountStates struct { - ID int64 `json:"id"` - Favorite bool `json:"favorite"` - Rated json.RawMessage `json:"rated"` - Watchlist bool `json:"watchlist"` -} - // GetMovieAccountStates grab the following account states for a session: // // Movie rating. @@ -168,7 +36,7 @@ type MovieAccountStates struct { // // If it belongs to your favourite list. // -// https://developers.themoviedb.org/3/movies/get-movie-account-states +// https://developer.themoviedb.org/reference/movie-account-states func (c *Client) GetMovieAccountStates( id int, urlOptions map[string]string, @@ -189,15 +57,9 @@ func (c *Client) GetMovieAccountStates( return &movieAccountStates, nil } -// MovieAlternativeTitles type is a struct for alternative titles JSON response. -type MovieAlternativeTitles struct { - ID int `json:"id"` - Titles []AlternativeTitle `json:"titles"` -} - // GetMovieAlternativeTitles get all of the alternative titles for a movie. // -// https://developers.themoviedb.org/3/movies/get-movie-alternative-titles +// https://developer.themoviedb.org/reference/movie-alternative-titles func (c *Client) GetMovieAlternativeTitles( id int, urlOptions map[string]string, @@ -218,32 +80,17 @@ func (c *Client) GetMovieAlternativeTitles( return &movieAlternativeTitles, nil } -// MovieChanges type is a struct for changes JSON response. -type MovieChanges struct { - Changes []struct { - Key string `json:"key"` - Items []struct { - ID json.RawMessage `json:"id"` - Action json.RawMessage `json:"action"` - Time json.RawMessage `json:"time"` - Iso639_1 json.RawMessage `json:"iso_639_1"` - Value json.RawMessage `json:"value"` - OriginalValue json.RawMessage `json:"original_value"` - } `json:"items"` - } `json:"changes"` -} - // GetMovieChanges get the changes for a movie. // // By default only the last 24 hours are returned. // You can query up to 14 days in a single query by using // the start_date and end_date query parameters. // -// https://developers.themoviedb.org/3/movies/get-movie-changes +// https://developer.themoviedb.org/reference/movie-changes func (c *Client) GetMovieChanges( id int, urlOptions map[string]string, -) (*MovieChanges, error) { +) (*Changes, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/changes?api_key=%s%s", @@ -253,45 +100,13 @@ func (c *Client) GetMovieChanges( c.apiKey, options, ) - movieChanges := MovieChanges{} + movieChanges := Changes{} if err := c.get(tmdbURL, &movieChanges); err != nil { return nil, err } return &movieChanges, nil } -// MovieCredits type is a struct for credits JSON response. -type MovieCredits struct { - ID int64 `json:"id,omitempty"` - Cast []struct { - Adult bool `json:"adult"` - CastID int64 `json:"cast_id"` - Character string `json:"character"` - CreditID string `json:"credit_id"` - Gender int `json:"gender"` - ID int64 `json:"id"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - Order int `json:"order"` - OriginalName string `json:"original_name"` - Popularity float32 `json:"popularity"` - ProfilePath string `json:"profile_path"` - } `json:"cast"` - Crew []struct { - Adult bool `json:"adult"` - CreditID string `json:"credit_id"` - Department string `json:"department"` - Gender int `json:"gender"` - ID int64 `json:"id"` - Job string `json:"job"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - OriginalName string `json:"original_name"` - Popularity float32 `json:"popularity"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` -} - // GetMovieCredits get the cast and crew for a movie. // // https://developers.themoviedb.org/3/movies/get-movie-credits @@ -314,16 +129,6 @@ func (c *Client) GetMovieCredits( return &movieCredits, nil } -// MovieExternalIDs type is a struct for external ids JSON response. -type MovieExternalIDs struct { - IMDbID string `json:"imdb_id"` - FacebookID string `json:"facebook_id"` - InstagramID string `json:"instagram_id"` - TwitterID string `json:"twitter_id"` - WikiDataID string `json:"wikidata_id,omitempty"` - ID int64 `json:"id,omitempty"` -} - // GetMovieExternalIDs get the external ids for a movie. // // We currently support the following external sources. @@ -353,20 +158,6 @@ func (c *Client) GetMovieExternalIDs( return &movieExternalIDs, nil } -// MovieImage type is a struct for a single image. -type MovieImage struct { - ImageBase - Iso639_1 string `json:"iso_639_1"` -} - -// MovieImages type is a struct for images JSON response. -type MovieImages struct { - ID int64 `json:"id,omitempty"` - Backdrops []MovieImage `json:"backdrops"` - Logos []MovieImage `json:"logos"` - Posters []MovieImage `json:"posters"` -} - // GetMovieImages get the images that belong to a movie. // // Querying images with a language parameter will filter the results. @@ -395,19 +186,10 @@ func (c *Client) GetMovieImages( return &movieImages, nil } -// MovieKeywords type is a struct for keywords JSON response. -type MovieKeywords struct { - ID int64 `json:"id,omitempty"` - Keywords []struct { - ID int64 `json:"id"` - Name string `json:"name"` - } `json:"keywords"` -} - // GetMovieKeywords get the keywords that have been added to a movie. // -// https://developers.themoviedb.org/3/movies/get-movie-keywords -func (c *Client) GetMovieKeywords(id int) (*MovieKeywords, error) { +// https://developer.themoviedb.org/reference/movie-keywords +func (c *Client) GetMovieKeywords(id int) (*IDKeywordsList, error) { tmdbURL := fmt.Sprintf( "%s%s%d/keywords?api_key=%s", baseURL, @@ -415,25 +197,19 @@ func (c *Client) GetMovieKeywords(id int) (*MovieKeywords, error) { id, c.apiKey, ) - movieKeywords := MovieKeywords{} + movieKeywords := IDKeywordsList{} if err := c.get(tmdbURL, &movieKeywords); err != nil { return nil, err } return &movieKeywords, nil } -// MovieReleaseDates type is a struct for release dates JSON response. -type MovieReleaseDates struct { - ID int64 `json:"id,omitempty"` - *MovieReleaseDatesResults -} - // GetMovieReleaseDates get the release date along with the certification for a movie. // // https://developers.themoviedb.org/3/movies/get-movie-release-dates func (c *Client) GetMovieReleaseDates( id int, -) (*MovieReleaseDates, error) { +) (*IDMovieReleaseDateResults, error) { tmdbURL := fmt.Sprintf( "%s%s%d/release_dates?api_key=%s", baseURL, @@ -441,7 +217,7 @@ func (c *Client) GetMovieReleaseDates( id, c.apiKey, ) - movieReleaseDates := MovieReleaseDates{} + movieReleaseDates := IDMovieReleaseDateResults{} if err := c.get(tmdbURL, &movieReleaseDates); err != nil { return nil, err } @@ -477,7 +253,7 @@ func (c *Client) GetMovieVideos( func (c *Client) GetMovieWatchProviders( id int, urlOptions map[string]string, -) (*WatchProviderResults, error) { +) (*IDWatchProviderResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/watch/providers?api_key=%s%s", @@ -487,19 +263,13 @@ func (c *Client) GetMovieWatchProviders( c.apiKey, options, ) - movieWatchProviders := WatchProviderResults{} + movieWatchProviders := IDWatchProviderResults{} if err := c.get(tmdbURL, &movieWatchProviders); err != nil { return nil, err } return &movieWatchProviders, nil } -// MovieTranslations type is a struct for translations JSON response. -type MovieTranslations struct { - ID int64 `json:"id,omitempty"` - Translations []Translation `json:"translations"` -} - // GetMovieTranslations get a list of translations that have been created for a movie. // // https://developers.themoviedb.org/3/movies/get-movie-translations @@ -523,19 +293,13 @@ func (c *Client) GetMovieTranslations( return &movieTranslations, nil } -// MovieRecommendations type is a struct for recommendations JSON response. -type MovieRecommendations struct { - *MovieRecommendationsResults - PaginatedResultsMeta -} - // GetMovieRecommendations get a list of recommended movies for a movie. // -// https://developers.themoviedb.org/3/movies/get-movie-recommendations +// https://developer.themoviedb.org/reference/movie-recommendations func (c *Client) GetMovieRecommendations( id int, urlOptions map[string]string, -) (*MovieRecommendations, error) { +) (*PaginatedMovieMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/recommendations?api_key=%s%s", @@ -545,18 +309,13 @@ func (c *Client) GetMovieRecommendations( c.apiKey, options, ) - movieRecommendations := MovieRecommendations{} + movieRecommendations := PaginatedMovieMediaResults{} if err := c.get(tmdbURL, &movieRecommendations); err != nil { return nil, err } return &movieRecommendations, nil } -// MovieSimilar type is a struct for similar movies JSON response. -type MovieSimilar struct { - *MovieRecommendations -} - // GetMovieSimilar get a list of similar movies. // // This is not the same as the "Recommendation" system you see on the website. @@ -566,7 +325,7 @@ type MovieSimilar struct { func (c *Client) GetMovieSimilar( id int, urlOptions map[string]string, -) (*MovieSimilar, error) { +) (*PaginatedMovieResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/similar?api_key=%s%s", @@ -576,27 +335,20 @@ func (c *Client) GetMovieSimilar( c.apiKey, options, ) - movieSimilar := MovieSimilar{} + movieSimilar := PaginatedMovieResults{} if err := c.get(tmdbURL, &movieSimilar); err != nil { return nil, err } return &movieSimilar, nil } -// MovieReviews type is a struct for reviews JSON response. -type MovieReviews struct { - ID int64 `json:"id,omitempty"` - *MovieReviewsResults - PaginatedResultsMeta -} - // GetMovieReviews get the user reviews for a movie. // -// https://developers.themoviedb.org/3/movies/get-movie-reviews +// https://developer.themoviedb.org/reference/movie-reviews func (c *Client) GetMovieReviews( id int, urlOptions map[string]string, -) (*MovieReviews, error) { +) (*IDPaginatedReviewsResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/reviews?api_key=%s%s", @@ -606,27 +358,20 @@ func (c *Client) GetMovieReviews( c.apiKey, options, ) - movieReviews := MovieReviews{} + movieReviews := IDPaginatedReviewsResults{} if err := c.get(tmdbURL, &movieReviews); err != nil { return nil, err } return &movieReviews, nil } -// MovieLists type is a struct for lists JSON response. -type MovieLists struct { - ID int64 `json:"id"` - *MovieListsResults - PaginatedResultsMeta -} - // GetMovieLists get a list of lists that this movie belongs to. // -// https://developers.themoviedb.org/3/movies/get-movie-lists +// https://developer.themoviedb.org/reference/movie-lists func (c *Client) GetMovieLists( id int, urlOptions map[string]string, -) (*MovieLists, error) { +) (*IDPaginatedMovieListResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/lists?api_key=%s%s", @@ -636,18 +381,13 @@ func (c *Client) GetMovieLists( c.apiKey, options, ) - movieLists := MovieLists{} + movieLists := IDPaginatedMovieListResults{} if err := c.get(tmdbURL, &movieLists); err != nil { return nil, err } return &movieLists, nil } -// MovieLatest type is a struct for latest JSON response. -type MovieLatest struct { - *MovieDetails -} - // GetMovieLatest get the most newly created movie. // // This is a live response and will continuously change. @@ -671,132 +411,6 @@ func (c *Client) GetMovieLatest( return &movieLastest, nil } -// MovieNowPlaying type is a struct for now playing JSON response. -type MovieNowPlaying struct { - *MovieNowPlayingResults - Dates struct { - Maximum string `json:"maximum"` - Minimum string `json:"minimum"` - } `json:"dates"` - PaginatedResultsMeta -} - -// GetMovieNowPlaying get a list of movies in theatres. -// -// This is a release type query that looks for all movies that -// have a release type of 2 or 3 within the specified date range. -// -// You can optionally specify a region prameter which will narrow -// the search to only look for theatrical release dates within the -// specified country. -// -// https://developers.themoviedb.org/3/movies/get-now-playing -func (c *Client) GetMovieNowPlaying( - urlOptions map[string]string, -) (*MovieNowPlaying, error) { - options := c.fmtOptions(urlOptions) - tmdbURL := fmt.Sprintf( - "%s%snow_playing?api_key=%s%s", - baseURL, - movieURL, - c.apiKey, - options, - ) - movieNowPlaying := MovieNowPlaying{} - if err := c.get(tmdbURL, &movieNowPlaying); err != nil { - return nil, err - } - return &movieNowPlaying, nil -} - -// MoviePopular type is a struct for popular JSON response. -type MoviePopular struct { - *MoviePopularResults - PaginatedResultsMeta -} - -// GetMoviePopular get a list of the current popular movies on TMDb. -// -// This list updates daily. -// -// https://developers.themoviedb.org/3/movies/get-popular-movies -func (c *Client) GetMoviePopular( - urlOptions map[string]string, -) (*MoviePopular, error) { - options := c.fmtOptions(urlOptions) - tmdbURL := fmt.Sprintf( - "%s%spopular?api_key=%s%s", - baseURL, - movieURL, - c.apiKey, - options, - ) - moviePopular := MoviePopular{} - if err := c.get(tmdbURL, &moviePopular); err != nil { - return nil, err - } - return &moviePopular, nil -} - -// MovieTopRated type is a struct for top rated JSON response. -type MovieTopRated struct { - *MoviePopular -} - -// GetMovieTopRated get the top rated movies on TMDb. -// -// https://developers.themoviedb.org/3/movies/get-top-rated-movies -func (c *Client) GetMovieTopRated( - urlOptions map[string]string, -) (*MovieTopRated, error) { - options := c.fmtOptions(urlOptions) - tmdbURL := fmt.Sprintf( - "%s%stop_rated?api_key=%s%s", - baseURL, - movieURL, - c.apiKey, - options, - ) - movieTopRated := MovieTopRated{} - if err := c.get(tmdbURL, &movieTopRated); err != nil { - return nil, err - } - return &movieTopRated, nil -} - -// MovieUpcoming type is a struct for upcoming JSON response. -type MovieUpcoming struct { - *MovieNowPlaying -} - -// GetMovieUpcoming get a list of upcoming movies in theatres. -// -// This is a release type query that looks for all movies that -// have a release type of 2 or 3 within the specified date range. -// -// You can optionally specify a region prameter which will narrow -// the search to only look for theatrical release dates within -// the specified country. -// -// https://developers.themoviedb.org/3/movies/get-upcoming -func (c *Client) GetMovieUpcoming( - urlOptions map[string]string, -) (*MovieUpcoming, error) { - options := c.fmtOptions(urlOptions) - tmdbURL := fmt.Sprintf( - "%s%supcoming?api_key=%s%s", - baseURL, - movieURL, - c.apiKey, - options, - ) - movieUpcoming := MovieUpcoming{} - if err := c.get(tmdbURL, &movieUpcoming); err != nil { - return nil, err - } - return &movieUpcoming, nil -} - // PostMovieRating rate a movie. // // A valid session or guest session ID is required. diff --git a/movies_struct.go b/movies_struct.go new file mode 100644 index 0000000..5d837b0 --- /dev/null +++ b/movies_struct.go @@ -0,0 +1,153 @@ +package tmdb + +// MovieDetails type is a struct for movie details JSON response. +type MovieDetails struct { + VideoDetails + MovieMeta + OriginCountry []string `json:"origin_country"` + BelongsToCollection *BelongsToCollection `json:"belongs_to_collection"` + Budget int64 `json:"budget"` + IMDbID string `json:"imdb_id"` + Revenue int64 `json:"revenue"` + Runtime int `json:"runtime"` + *MovieAlternativeTitlesAppend + *MovieChangesAppend + *MovieCreditsAppend + *MovieExternalIDsAppend + *MovieImagesAppend + *MovieKeywordsAppend + *MovieReleaseDatesAppend + *MovieVideosAppend + *MovieTranslationsAppend + *MovieRecommendationsAppend + *MovieSimilarAppend + *MovieReviewsAppend + *MovieListsAppend + *MovieWatchProvidersAppend +} + +// MovieAlternativeTitlesAppend type is a struct for alternative +// titles in append to response. +type MovieAlternativeTitlesAppend struct { + AlternativeTitles MovieAlternativeTitles `json:"alternative_titles"` +} + +// MovieChangesAppend type is a struct for changes in append to response. +type MovieChangesAppend struct { + Changes Changes `json:"changes"` +} + +// MovieCreditsAppend type is a struct for credits in append to response. +type MovieCreditsAppend struct { + Credits MovieCredits `json:"credits"` +} + +// MovieExternalIDsAppend type is a struct for external ids in append to response. +type MovieExternalIDsAppend struct { + ExternalIDs MovieExternalIDs `json:"external_ids"` +} + +// MovieImagesAppend type is a struct for images in append to response. +type MovieImagesAppend struct { + Images MovieImages `json:"images"` +} + +// MovieReleaseDatesAppend type is a struct for release dates in append to response. +type MovieReleaseDatesAppend struct { + ReleaseDates MovieReleaseDateResults `json:"release_dates"` +} + +// MovieVideosAppend type is a struct for videos in append to response. +type MovieVideosAppend struct { + Videos VideoResults `json:"videos"` +} + +// MovieTranslationsAppend type is a struct for translations in append to response. +type MovieTranslationsAppend struct { + Translations MovieTranslations `json:"translations"` +} + +// MovieRecommendationsAppend type is a struct for +// recommendations in append to response. +type MovieRecommendationsAppend struct { + Recommendations PaginatedMovieResults `json:"recommendations"` +} + +// MovieSimilarAppend type is a struct for similar movies in append to response. +type MovieSimilarAppend struct { + Similar PaginatedMovieResults `json:"similar"` +} + +// MovieReviewsAppend type is a struct for reviews in append to response. +type MovieReviewsAppend struct { + Reviews PaginatedReviewsResults `json:"reviews"` +} + +// MovieListsAppend type is a struct for lists in append to response. +type MovieListsAppend struct { + Lists PaginatedMovieListResults `json:"lists"` +} + +// MovieKeywordsAppend type is a struct for keywords in append to response. +type MovieKeywordsAppend struct { + Keywords KeywordsList `json:"keywords"` +} + +// MovieWatchProvidersAppend type is a struct for +// watch/providers in append to response. +type MovieWatchProvidersAppend struct { + WatchProviders IDWatchProviderResults `json:"watch/providers"` +} + +// MovieAccountStates type is a struct for account states JSON response. +type MovieAccountStates struct { + AccountStates +} + +// MovieAlternativeTitles type is a struct for alternative titles JSON response. +type MovieAlternativeTitles struct { + ID int `json:"id"` + Titles []AlternativeTitle `json:"titles"` +} + +// MovieExternalIDs type is a struct for external ids JSON response. +type MovieExternalIDs struct { + IMDbID string `json:"imdb_id"` + FacebookID string `json:"facebook_id"` + InstagramID string `json:"instagram_id"` + TwitterID string `json:"twitter_id"` + WikiDataID string `json:"wikidata_id"` + ID int64 `json:"id"` +} + +// MovieImages type is a struct for images JSON response. +type MovieImages struct { + ID int64 `json:"id"` + Backdrops []ImageIso `json:"backdrops"` + Logos []ImageIso `json:"logos"` + Posters []ImageIso `json:"posters"` +} + +// MovieTranslations type is a struct for translations JSON response. +type MovieTranslations struct { + ID int64 `json:"id"` + Translations []MovieTranslation `json:"translations"` +} + +type MovieTranslation struct { + TranslationBase + Data MovieTranslationData `json:"data"` +} + +type MovieTranslationData struct { + Homepage string `json:"homepage"` + Overview string `json:"overview"` + Runtime int `json:"runtime"` + Tagline string `json:"tagline"` + Title string `json:"title"` +} + +// MovieLatest type is a struct for latest JSON response. +type MovieLatest struct { + MovieDetails +} diff --git a/movies_test.go b/movies_test.go index fb92315..edd8c78 100644 --- a/movies_test.go +++ b/movies_test.go @@ -305,86 +305,6 @@ func (suite *TMBDTestSuite) TestGetMovieLatestWithOptions() { suite.NotNil(movie.VoteCount) } -func (suite *TMBDTestSuite) TestGetMovieNowPlaying() { - movies, err := suite.client.GetMovieNowPlaying(nil) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMovieNowPlayingFail() { - suite.client.apiKey = "" - _, err := suite.client.GetMovieNowPlaying(nil) - suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) -} - -func (suite *TMBDTestSuite) TestGetMovieNowPlayingWithOptions() { - options := make(map[string]string) - options["language"] = "en-US" - movies, err := suite.client.GetMovieNowPlaying(options) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMoviePopular() { - movies, err := suite.client.GetMoviePopular(nil) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMoviePopularFail() { - suite.client.apiKey = "" - _, err := suite.client.GetMoviePopular(nil) - suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) -} - -func (suite *TMBDTestSuite) TestGetMoviePopularWithOptions() { - options := make(map[string]string) - options["language"] = "en-US" - movies, err := suite.client.GetMoviePopular(options) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMovieTopRated() { - movies, err := suite.client.GetMovieTopRated(nil) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMovieTopRatedFail() { - suite.client.apiKey = "" - _, err := suite.client.GetMovieTopRated(nil) - suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) -} - -func (suite *TMBDTestSuite) TestGetMovieTopRatedWithOptions() { - options := make(map[string]string) - options["language"] = "en-US" - movies, err := suite.client.GetMovieTopRated(options) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMovieUpcoming() { - movies, err := suite.client.GetMovieUpcoming(nil) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - -func (suite *TMBDTestSuite) TestGetMovieUpcomingFail() { - suite.client.apiKey = "" - _, err := suite.client.GetMovieUpcoming(nil) - suite.Equal("code: 7 | success: false | message: Invalid API key: You must be granted a valid key.", err.Error()) -} - -func (suite *TMBDTestSuite) TestGetMovieUpcomingWithOptions() { - options := make(map[string]string) - options["language"] = "en-US" - movies, err := suite.client.GetMovieUpcoming(options) - suite.Nil(err) - suite.Equal(int64(1), movies.Page) -} - func (suite *TMBDTestSuite) TestPostMovieRating() { err := suite.client.SetSessionID(sessionID) suite.Nil(err) diff --git a/networks.go b/networks.go index 1fdef41..d4e6540 100644 --- a/networks.go +++ b/networks.go @@ -4,17 +4,27 @@ import "fmt" // NetworkDetails type is a struct for details JSON response. type NetworkDetails struct { - Headquarters string `json:"headquarters"` - Homepage string `json:"homepage"` - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - Name string `json:"name"` - OriginCountry string `json:"origin_country"` + Network + Headquarters string `json:"headquarters"` + Homepage string `json:"homepage"` +} + +// NetworkImage type is a struct for a single image. +type NetworkImage struct { + ImageBase + ID string `json:"id"` + FileType string `json:"file_type"` +} + +// NetworkImages type is a struct for images JSON response. +type NetworkImages struct { + ID int64 `json:"id"` + Logos []NetworkImage `json:"logos"` } // GetNetworkDetails get the details of a network. // -// https://developers.themoviedb.org/3/networks/get-network-details +// https://developer.themoviedb.org/reference/network-details func (c *Client) GetNetworkDetails( id int, ) (*NetworkDetails, error) { @@ -32,21 +42,12 @@ func (c *Client) GetNetworkDetails( return &networkDetails, nil } -// NetworkAlternativeNames type is a struct for alternative names JSON response. -type NetworkAlternativeNames struct { - ID int64 `json:"id"` - Results []struct { - Name string `json:"name"` - Type string `json:"type"` - } `json:"results"` -} - // GetNetworkAlternativeNames get the alternative names of a network. // -// https://developers.themoviedb.org/3/networks/get-network-alternative-names +// https://developer.themoviedb.org/reference/details-copy func (c *Client) GetNetworkAlternativeNames( id int, -) (*NetworkAlternativeNames, error) { +) (*IDAlternativeNameResults, error) { tmdbURL := fmt.Sprintf( "%s%s%d/alternative_names?api_key=%s", baseURL, @@ -54,26 +55,13 @@ func (c *Client) GetNetworkAlternativeNames( id, c.apiKey, ) - networkAltenativeNames := NetworkAlternativeNames{} + networkAltenativeNames := IDAlternativeNameResults{} if err := c.get(tmdbURL, &networkAltenativeNames); err != nil { return nil, err } return &networkAltenativeNames, nil } -// NetworkImage type is a struct for a single image. -type NetworkImage struct { - ImageBase - ID string `json:"id"` - FileType string `json:"file_type"` -} - -// NetworkImages type is a struct for images JSON response. -type NetworkImages struct { - ID int64 `json:"id"` - Logos []NetworkImage `json:"logos"` -} - // GetNetworkImages get the TV network logos by id. // // There are two image formats that are supported for networks, @@ -84,7 +72,7 @@ type NetworkImages struct { // An SVG can be scaled properly beyond those dimensions if you // call them as a PNG. // -// https://developers.themoviedb.org/3/networks/get-network-images +// https://developer.themoviedb.org/reference/alternative-names-copy func (c *Client) GetNetworkImages( id int, ) (*NetworkImages, error) { diff --git a/people.go b/people.go index a69cec9..4d6ec0f 100644 --- a/people.go +++ b/people.go @@ -67,7 +67,7 @@ type PersonImagesAppend struct { // PersonTaggedImagesAppend type is a struct // for tagged images in append to response. type PersonTaggedImagesAppend struct { - TaggedImages *PersonTaggedImages `json:"tagged_images,omitempty"` + TaggedImages *PaginatedPersonTaggedImagesResults `json:"tagged_images"` } // PersonTranslationsAppend type is a struct @@ -76,6 +76,11 @@ type PersonTranslationsAppend struct { Translations *PersonTranslations `json:"translations,omitempty"` } +type IDPaginatedPersonTaggedImagesResults struct { + ID int64 `json:"id"` + PaginatedPersonTaggedImagesResults +} + // GetPersonDetails get the primary person details by id. // // Supports append_to_response. @@ -146,43 +151,9 @@ func (c *Client) GetPersonChanges( // PersonMovieCredits type is a struct for movie credits JSON response. type PersonMovieCredits struct { - Cast []struct { - Character string `json:"character"` - CreditID string `json:"credit_id"` - PosterPath string `json:"poster_path"` - ID int64 `json:"id"` - Order int `json:"order"` - Video bool `json:"video"` - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIDs []int64 `json:"genre_ids"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Popularity float32 `json:"popularity"` - Title string `json:"title"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - VoteMetrics - } `json:"cast"` - Crew []struct { - ID int64 `json:"id"` - Department string `json:"department"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Job string `json:"job"` - Overview string `json:"overview"` - Video bool `json:"video"` - ReleaseDate string `json:"release_date"` - Title string `json:"title"` - Popularity float32 `json:"popularity"` - GenreIDs []int64 `json:"genre_ids"` - BackdropPath string `json:"backdrop_path"` - Adult bool `json:"adult"` - PosterPath string `json:"poster_path"` - CreditID string `json:"credit_id"` - VoteMetrics - } `json:"crew"` - ID int64 `json:"id,omitempty"` + Cast []PeopleMovieCreditCast `json:"cast"` + Crew []PeopleMovieCreditCrew `json:"crew"` + ID int64 `json:"id"` } // GetPersonMovieCredits get the movie credits for a person. @@ -210,42 +181,9 @@ func (c *Client) GetPersonMovieCredits( // PersonTVCredits type is a struct for tv credits JSON response. type PersonTVCredits struct { - Cast []struct { - CreditID string `json:"credit_id"` - OriginalName string `json:"original_name"` - ID int64 `json:"id"` - GenreIDs []int64 `json:"genre_ids"` - Character string `json:"character"` - Name string `json:"name"` - PosterPath string `json:"poster_path"` - Popularity float32 `json:"popularity"` - EpisodeCount int `json:"episode_count"` - OriginalLanguage string `json:"original_language"` - FirstAirDate string `json:"first_air_date"` - BackdropPath string `json:"backdrop_path"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country"` - VoteMetrics - } `json:"cast"` - Crew []struct { - ID int64 `json:"id"` - Department string `json:"department"` - OriginalLanguage string `json:"original_language"` - EpisodeCount int `json:"episode_count"` - Job string `json:"job"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country"` - OriginalName string `json:"original_name"` - GenreIDs []int64 `json:"genre_ids"` - Name string `json:"name"` - FirstAirDate string `json:"first_air_date"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - PosterPath string `json:"poster_path"` - CreditID string `json:"credit_id"` - VoteMetrics - } `json:"crew"` - ID int64 `json:"id,omitempty"` + Cast []PeopleTVCreditCast `json:"cast"` + Crew []PeopleTVCreditCrew `json:"crew"` + ID int64 `json:"id,omitempty"` } // GetPersonTVCredits get the TV show credits for a person. @@ -274,45 +212,45 @@ func (c *Client) GetPersonTVCredits( // PersonCombinedCredits type is a struct for combined credits JSON response. type PersonCombinedCredits struct { Cast []struct { - ID int64 `json:"id"` - Character string `json:"character"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - Video bool `json:"video"` - MediaType string `json:"media_type"` - ReleaseDate string `json:"release_date"` - Title string `json:"title"` - Popularity float32 `json:"popularity"` - OriginalLanguage string `json:"original_language"` - GenreIDs []int64 `json:"genre_ids"` - BackdropPath string `json:"backdrop_path"` - Adult bool `json:"adult"` - PosterPath string `json:"poster_path"` - CreditID string `json:"credit_id"` - EpisodeCount int `json:"episode_count"` - OriginCountry []string `json:"origin_country"` - OriginalName string `json:"original_name"` - Name string `json:"name"` - FirstAirDate string `json:"first_air_date"` + ID int64 `json:"id"` + Character string `json:"character"` + OriginalTitle string `json:"original_title"` + Overview string `json:"overview"` + Video bool `json:"video"` + MediaType MediaType `json:"media_type"` + ReleaseDate string `json:"release_date"` + Title string `json:"title"` + Popularity float32 `json:"popularity"` + OriginalLanguage string `json:"original_language"` + GenreIDs []int64 `json:"genre_ids"` + BackdropPath string `json:"backdrop_path"` + Adult bool `json:"adult"` + PosterPath string `json:"poster_path"` + CreditID string `json:"credit_id"` + EpisodeCount int `json:"episode_count"` + OriginCountry []string `json:"origin_country"` + OriginalName string `json:"original_name"` + Name string `json:"name"` + FirstAirDate string `json:"first_air_date"` VoteMetrics } `json:"cast"` Crew []struct { - ID int64 `json:"id"` - Department string `json:"department"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Job string `json:"job"` - Overview string `json:"overview"` - Video bool `json:"video"` - MediaType string `json:"media_type"` - PosterPath string `json:"poster_path"` - BackdropPath string `json:"backdrop_path"` - Title string `json:"title"` - Popularity float32 `json:"popularity"` - GenreIDs []int64 `json:"genre_ids"` - Adult bool `json:"adult"` - ReleaseDate string `json:"release_date"` - CreditID string `json:"credit_id"` + ID int64 `json:"id"` + Department string `json:"department"` + OriginalLanguage string `json:"original_language"` + OriginalTitle string `json:"original_title"` + Job string `json:"job"` + Overview string `json:"overview"` + Video bool `json:"video"` + MediaType MediaType `json:"media_type"` + PosterPath string `json:"poster_path"` + BackdropPath string `json:"backdrop_path"` + Title string `json:"title"` + Popularity float32 `json:"popularity"` + GenreIDs []int64 `json:"genre_ids"` + Adult bool `json:"adult"` + ReleaseDate string `json:"release_date"` + CreditID string `json:"credit_id"` VoteMetrics } `json:"crew"` ID int64 `json:"id,omitempty"` @@ -380,21 +318,15 @@ func (c *Client) GetPersonExternalIDs( return &personExternalIDS, nil } -// PersonImage type is a struct for a single image. -type PersonImage struct { - ImageBase - Iso639_1 string `json:"iso_639_1"` -} - // PersonImages type is a struct for images JSON response. type PersonImages struct { - Profiles []PersonImage `json:"profiles"` - ID int `json:"id,omitempty"` + Profiles []ImageIso `json:"profiles"` + ID int `json:"id"` } // GetPersonImages get the images for a person. // -// https://developers.themoviedb.org/3/people/get-person-images +// https://developer.themoviedb.org/reference/person-images func (c *Client) GetPersonImages( id int, ) (*PersonImages, error) { @@ -412,39 +344,17 @@ func (c *Client) GetPersonImages( return &personImages, nil } -// PersonTaggedImages type is a struct for tagged images JSON response. -type PersonTaggedImages struct { - ID int64 `json:"id"` - PaginatedResultsMeta - Results []struct { - ImageBase - Iso639_1 string `json:"iso_639_1"` - MediaType string `json:"media_type"` - Media struct { - Popularity float32 `json:"popularity"` - Video bool `json:"video"` - PosterPath string `json:"poster_path"` - ID int64 `json:"id"` - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - GenreIDs []int64 `json:"genre_ids"` - Title string `json:"title"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - VoteMetrics - } `json:"media"` - } `json:"results"` -} - +// Deprecated: Use GetPersonImages instead. +// // GetPersonTaggedImages get the images that this person has been tagged in. // -// https://developers.themoviedb.org/3/people/get-tagged-images +// This endpoint is deprecated in the TMDB API. +// +// https://developer.themoviedb.org/reference/person-tagged-images func (c *Client) GetPersonTaggedImages( id int, urlOptions map[string]string, -) (*PersonTaggedImages, error) { +) (*IDPaginatedPersonTaggedImagesResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/tagged_images?api_key=%s%s", @@ -454,7 +364,7 @@ func (c *Client) GetPersonTaggedImages( c.apiKey, options, ) - personTaggedImages := PersonTaggedImages{} + personTaggedImages := IDPaginatedPersonTaggedImagesResults{} if err := c.get(tmdbURL, &personTaggedImages); err != nil { return nil, err } @@ -463,13 +373,24 @@ func (c *Client) GetPersonTaggedImages( // PersonTranslations type is a struct for translations JSON response. type PersonTranslations struct { - Translations []Translation `json:"translations"` - ID int64 `json:"id,omitempty"` + ID int64 `json:"id"` + Translations []PersonTranslation `json:"translations"` +} + +type PersonTranslation struct { + TranslationBase + Data PersonDataTranslation `json:"data"` +} + +type PersonDataTranslation struct { + Biography string `json:"biography"` + Name string `json:"name"` + Primary bool `json:"primary"` } // GetPersonTranslations get a list of translations that have been created for a person. // -// https://developers.themoviedb.org/3/people/get-person-translations +// https://developer.themoviedb.org/reference/translations func (c *Client) GetPersonTranslations( id int, urlOptions map[string]string, @@ -529,43 +450,13 @@ func (c *Client) GetPersonLatest( return &personLatest, nil } -// PersonPopular type is a struct for popular JSON response. -type PersonPopular struct { - PaginatedResultsMeta - Results []struct { - Popularity float32 `json:"popularity"` - ID int64 `json:"id"` - ProfilePath string `json:"profile_path"` - Name string `json:"name"` - KnownFor []struct { - OriginalTitle string `json:"original_title,omitempty"` - OriginalName string `json:"original_name,omitempty"` - ID int64 `json:"id"` - MediaType string `json:"media_type"` - Name string `json:"name,omitempty"` - Title string `json:"title,omitempty"` - PosterPath string `json:"poster_path"` - FirstAirDate string `json:"first_air_date,omitempty"` - ReleaseDate string `json:"release_date,omitempty"` - Popularity float32 `json:"popularity"` - GenreIDs []int64 `json:"genre_ids"` - OriginalLanguage string `json:"original_language"` - BackdropPath string `json:"backdrop_path"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country,omitempty"` - VoteMetrics - } `json:"known_for"` - Adult bool `json:"adult"` - } `json:"results"` -} - // GetPersonPopular get the list of popular people on TMDb. // This list updates daily. // // https://developers.themoviedb.org/3/people/get-popular-people func (c *Client) GetPersonPopular( urlOptions map[string]string, -) (*PersonPopular, error) { +) (*PaginatedPersonMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%spopular?api_key=%s%s", @@ -574,7 +465,7 @@ func (c *Client) GetPersonPopular( c.apiKey, options, ) - personPopular := PersonPopular{} + personPopular := PaginatedPersonMediaResults{} if err := c.get(tmdbURL, &personPopular); err != nil { return nil, err } diff --git a/results.go b/results.go index 698a055..24fc399 100644 --- a/results.go +++ b/results.go @@ -1,535 +1,102 @@ package tmdb -// AccountCreatedListsResults Result Types -type AccountCreatedListsResults struct { - Results []struct { - Description string `json:"description"` - FavoriteCount int64 `json:"favorite_count"` - ID int64 `json:"id"` - ItemCount int64 `json:"item_count"` - Iso639_1 string `json:"iso_639_1"` - ListType string `json:"list_type"` - Name string `json:"name"` - PosterPath string `json:"poster_path"` - } `json:"results"` -} - -// MovieResult represents the details of a movie as returned by the TMDB API. -// It includes information such as the movie's ID, titles, language, overview, -// release date, poster and backdrop paths, popularity metrics, genre IDs, and flags -// indicating whether the movie is for adults or contains video content. -type MovieResult struct { - ID int64 `json:"id"` - Title string `json:"title"` - OriginalTitle string `json:"original_title"` - OriginalLanguage string `json:"original_language"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - PosterPath string `json:"poster_path"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - GenreIDs []int64 `json:"genre_ids"` - Adult bool `json:"adult"` - Video bool `json:"video"` - VoteMetrics -} - -// AccountFavoriteMoviesResults Result Types -type AccountFavoriteMoviesResults struct { - Results []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIDs []int `json:"genre_ids"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - PosterPath string `json:"poster_path"` - Popularity float64 `json:"popularity"` - Title string `json:"title"` - Video bool `json:"video"` - VoteMetrics - } `json:"results"` -} - -// TVShowResult represents the details of a TV show as returned by the TMDB API. -// It includes information such as the show's ID, name, original name and language, -// overview, first air date, poster and backdrop paths, popularity score, vote count -// and average, associated genre IDs, and the countries of origin. -type TVShowResult struct { - ID int64 `json:"id"` - Name string `json:"name"` - OriginalName string `json:"original_name"` - OriginalLanguage string `json:"original_language"` - Overview string `json:"overview"` - FirstAirDate string `json:"first_air_date"` - PosterPath string `json:"poster_path"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - GenreIDs []int64 `json:"genre_ids"` - OriginCountry []string `json:"origin_country"` - VoteMetrics -} - -// AccountFavoriteTVShowsResults Result Types -type AccountFavoriteTVShowsResults struct { - Results []struct { - BackdropPath string `json:"backdrop_path"` - FirstAirDate string `json:"first_air_date"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name"` - Overview string `json:"overview"` - OriginCountry []string `json:"origin_country"` - PosterPath string `json:"poster_path"` - Popularity float64 `json:"popularity"` - Name string `json:"name"` - VoteMetrics - } `json:"results"` -} - -// AccountRatedTVEpisodesResults Result Types -type AccountRatedTVEpisodesResults struct { - Results []struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode string `json:"production_code"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - Rating float32 `json:"rating"` - VoteMetrics - } `json:"results"` -} - -// ChangesMovieResults Result Types -type ChangesMovieResults struct { - Results []struct { - ID int64 `json:"id"` - Adult bool `json:"adult"` - } `json:"results"` -} - -// CompanyAlternativeNamesResult Result Types -type CompanyAlternativeNamesResult struct { - Results []struct { - Name string `json:"name"` - Type string `json:"type"` - } `json:"results"` -} - -// DiscoverMovieResults Result Types -type DiscoverMovieResults struct { - Results []MovieResult `json:"results"` -} - -// DiscoverTVResults Result Types -type DiscoverTVResults struct { - Results []TVShowResult `json:"results"` -} - -// SearchCompaniesResults Result Types -type SearchCompaniesResults struct { - Results []struct { - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - Name string `json:"name"` - OriginCountry string `json:"origin_country"` - } `json:"results"` -} - -// SearchCollectionsResults Result Types -type SearchCollectionsResults struct { - Results []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - ID int64 `json:"id"` - Name string `json:"name"` - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - } `json:"results"` -} - -// SearchKeywordsResults Result Types -type SearchKeywordsResults struct { - Results []struct { - ID int64 `json:"id"` - Name string `json:"name"` - } `json:"results"` -} - -// SearchMoviesResults Result Types -type SearchMoviesResults struct { - Results []MovieResult `json:"results"` -} - -// SearchMultiResults Result Types -type SearchMultiResults struct { - Results []struct { - PosterPath string `json:"poster_path,omitempty"` - Popularity float32 `json:"popularity"` - ID int64 `json:"id"` - Overview string `json:"overview,omitempty"` - BackdropPath string `json:"backdrop_path,omitempty"` - MediaType string `json:"media_type"` - FirstAirDate string `json:"first_air_date,omitempty"` - OriginCountry []string `json:"origin_country,omitempty"` - GenreIDs []int64 `json:"genre_ids,omitempty"` - OriginalLanguage string `json:"original_language,omitempty"` - Name string `json:"name,omitempty"` - OriginalName string `json:"original_name,omitempty"` - Adult bool `json:"adult,omitempty"` - ReleaseDate string `json:"release_date,omitempty"` - OriginalTitle string `json:"original_title,omitempty"` - Title string `json:"title,omitempty"` - Video bool `json:"video,omitempty"` - ProfilePath string `json:"profile_path,omitempty"` - KnownFor []struct { - PosterPath string `json:"poster_path"` - Adult bool `json:"adult"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - OriginalTitle string `json:"original_title"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - MediaType string `json:"media_type"` - OriginalLanguage string `json:"original_language"` - Title string `json:"title"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - Video bool `json:"video"` - VoteMetrics - } `json:"known_for,omitempty"` - VoteMetrics - } `json:"results"` -} - -// SearchPeopleResults Result Types -type SearchPeopleResults struct { - Results []struct { - Adult bool `json:"adult"` - Gender int `json:"gender,omitempty"` - ID int64 `json:"id"` - KnownFor []struct { - Adult bool `json:"adult,omitempty"` // Movie - BackdropPath string `json:"backdrop_path"` - FirstAirDate string `json:"first_air_date,omitempty"` // TV - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - MediaType string `json:"media_type"` - Name string `json:"name,omitempty"` // TV - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name,omitempty"` // TV - OriginalTitle string `json:"original_title,omitempty"` // Movie - OriginCountry []string `json:"origin_country,omitempty"` // TV - Overview string `json:"overview"` - Popularity float32 `json:"popularity"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date,omitempty"` // Movie - Title string `json:"title,omitempty"` // Movie - Video bool `json:"video,omitempty"` // Movie - VoteMetrics - } `json:"known_for"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - Popularity float32 `json:"popularity"` - ProfilePath string `json:"profile_path"` - } `json:"results"` -} - -// SearchTVShowsResults Result Types -type SearchTVShowsResults struct { - Results []TVShowResult `json:"results"` -} - -// TrendingResults Result Types -type TrendingResults struct { - Results []struct { - Adult bool `json:"adult,omitempty"` - Gender int `json:"gender,omitempty"` - BackdropPath string `json:"backdrop_path,omitempty"` - GenreIDs []int64 `json:"genre_ids,omitempty"` - ID int64 `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title,omitempty"` - Overview string `json:"overview,omitempty"` - PosterPath string `json:"poster_path,omitempty"` - ReleaseDate string `json:"release_date,omitempty"` - Title string `json:"title,omitempty"` - Video bool `json:"video,omitempty"` - Popularity float32 `json:"popularity,omitempty"` - FirstAirDate string `json:"first_air_date,omitempty"` - Name string `json:"name,omitempty"` - OriginCountry []string `json:"origin_country,omitempty"` - OriginalName string `json:"original_name,omitempty"` - KnownForDepartment string `json:"known_for_department,omitempty"` - ProfilePath string `json:"profile_path,omitempty"` - MediaType string `json:"media_type,omitempty"` - KnownFor []struct { - Adult bool `json:"adult"` - BackdropPath string `json:"backdrop_path"` - GenreIds []int `json:"genre_ids"` - ID int `json:"id"` - OriginalLanguage string `json:"original_language"` - OriginalTitle string `json:"original_title"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - ReleaseDate string `json:"release_date"` - Title string `json:"title"` - Video bool `json:"video"` - Popularity float64 `json:"popularity"` - MediaType string `json:"media_type"` - VoteMetrics - } `json:"known_for,omitempty"` - VoteMetrics - } `json:"results"` +type ChangeMedia struct { + ID int64 `json:"id"` + Adult bool `json:"adult"` +} + +type PaginatedChangesMediaResults struct { + Results []ChangeMedia `json:"results"` + PaginatedResultsMeta +} + +type PaginatedCompanyInfoResults struct { + Results []CompanyInfo `json:"results"` + PaginatedResultsMeta +} + +type PaginatedCollectionResults struct { + Results []Collection `json:"results"` + PaginatedResultsMeta +} + +type PaginatedPersonMediaResults struct { + Results []PersonMedia `json:"results"` + PaginatedResultsMeta } // MovieReleaseDatesResults Result Types -type MovieReleaseDatesResults struct { - Results []struct { - Iso3166_1 string `json:"iso_3166_1"` - ReleaseDates []struct { - Certification string `json:"certification"` - Iso639_1 string `json:"iso_639_1"` - ReleaseDate string `json:"release_date"` - Type int `json:"type"` - Note string `json:"note"` - } `json:"release_dates"` - } `json:"results"` -} - -// MovieVideosResults Result Types -type MovieVideosResults struct { - Results []struct { - ID string `json:"id"` - Iso639_1 string `json:"iso_639_1"` - Iso3166_1 string `json:"iso_3166_1"` - Key string `json:"key"` - Name string `json:"name"` - Official bool `json:"official"` - PublishedAt string `json:"published_at"` - Site string `json:"site"` - Size int `json:"size"` - Type string `json:"type"` - } `json:"results"` -} - -type WatchProviderResult struct { - Link string `json:"link"` - Flatrate *[]WatchProvider `json:"flatrate"` - Rent *[]WatchProvider `json:"rent"` - Buy *[]WatchProvider `json:"buy"` +type MovieReleaseDateResults struct { + Results []MovieReleaseDate `json:"results"` +} + +type IDMovieReleaseDateResults struct { + ID int64 `json:"id"` + MovieReleaseDateResults +} + +type WatchProvider struct { + Link string `json:"link"` + Flatrate *[]WatchProviderBase `json:"flatrate"` + Rent *[]WatchProviderBase `json:"rent"` + Buy *[]WatchProviderBase `json:"buy"` } type WatchProviderResults struct { - ID int64 `json:"id"` - Results map[string]WatchProviderResult `json:"results"` -} - -// MovieRecommendationsResults Result Types -type MovieRecommendationsResults struct { - Results []struct { - PosterPath string `json:"poster_path"` - Adult bool `json:"adult"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - GenreIDs []int64 `json:"genre_ids"` - ID int64 `json:"id"` - OriginalTitle string `json:"original_title"` - OriginalLanguage string `json:"original_language"` - Title string `json:"title"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - Video bool `json:"video"` - VoteMetrics - } `json:"results"` -} - -// MovieReviewsResults Result Types -type MovieReviewsResults struct { - Results []struct { - ID string `json:"id"` - Author string `json:"author"` - Content string `json:"content"` - URL string `json:"url"` - } `json:"results"` -} - -// MovieListsResults Result Types -type MovieListsResults struct { - Results []struct { - Description string `json:"description"` - FavoriteCount int64 `json:"favorite_count"` - ID int64 `json:"id"` - ItemCount int64 `json:"item_count"` - Iso639_1 string `json:"iso_639_1"` - ListType string `json:"list_type"` - Name string `json:"name"` - PosterPath string `json:"poster_path"` - } `json:"results"` -} - -// MovieNowPlayingResults Result Types -type MovieNowPlayingResults struct { - Results []struct { - PosterPath string `json:"poster_path"` - Adult bool `json:"adult"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - Genres []Genre `json:"genres"` - ID int64 `json:"id"` - OriginalTitle string `json:"original_title"` - OriginalLanguage string `json:"original_language"` - Title string `json:"title"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - Video bool `json:"video"` - VoteMetrics - } `json:"results"` -} - -// MoviePopularResults Result Types -type MoviePopularResults struct { - Results []struct { - PosterPath string `json:"poster_path"` - Adult bool `json:"adult"` - Overview string `json:"overview"` - ReleaseDate string `json:"release_date"` - Genres []Genre `json:"genres"` - ID int64 `json:"id"` - OriginalTitle string `json:"original_title"` - OriginalLanguage string `json:"original_language"` - Title string `json:"title"` - BackdropPath string `json:"backdrop_path"` - Popularity float32 `json:"popularity"` - Video bool `json:"video"` - VoteMetrics - } `json:"results"` + Results map[string]WatchProvider `json:"results"` +} + +type IDWatchProviderResults struct { + ID int64 `json:"id"` + WatchProviderResults +} + +type PaginatedMovieListResults struct { + Results []MovieList `json:"results"` + PaginatedResultsMeta +} + +type IDPaginatedMovieListResults struct { + ID int64 `json:"id"` + PaginatedMovieListResults } // TVContentRatingsResults Result Types type TVContentRatingsResults struct { - Results []struct { - Iso3166_1 string `json:"iso_3166_1"` - Rating string `json:"rating"` - } `json:"results"` + Results []ContentRatings `json:"results"` +} + +type IDTVContentRatingsResults struct { + ID int64 `json:"id"` + TVContentRatingsResults } // TVEpisodeGroupsResults Result Types type TVEpisodeGroupsResults struct { - Results []struct { - Description string `json:"description"` - EpisodeCount int `json:"episode_count"` - GroupCount int `json:"group_count"` - ID string `json:"id"` - Name string `json:"name"` - Network struct { - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - Name string `json:"name"` - OriginCountry string `json:"origin_country"` - } `json:"network"` - Type int `json:"type"` - } `json:"results"` -} - -// TVKeywordsResults Result Types -type TVKeywordsResults struct { - Results []struct { - ID int64 `json:"id"` - Name string `json:"name"` - } `json:"results"` -} - -// TVRecommendationsResults Result Types -type TVRecommendationsResults struct { - Results []struct { - PosterPath string `json:"poster_path"` - Popularity float32 `json:"popularity"` - ID int64 `json:"id"` - BackdropPath string `json:"backdrop_path"` - Overview string `json:"overview"` - FirstAirDate string `json:"first_air_date"` - OriginCountry []string `json:"origin_country"` - GenreIDs []int64 `json:"genre_ids"` - OriginalLanguage string `json:"original_language"` - Name string `json:"name"` - OriginalName string `json:"original_name"` - VoteMetrics - } `json:"results"` -} - -// TVReviewsResults Result Types -type TVReviewsResults struct { - Results []struct { - ID string `json:"id"` - Author string `json:"author"` - Content string `json:"content"` - URL string `json:"url"` - } `json:"results"` + Results []TVEpisodeGroup `json:"results"` +} + +type IDTVEpisodeGroupsResults struct { + ID int64 `json:"id"` + TVEpisodeGroupsResults +} + +// KeywordsResults Result Types +type KeywordsResults struct { + Results []Keyword `json:"results"` +} + +type IDKeywordsResults struct { + ID int64 `json:"id"` + KeywordsResults } // TVScreenedTheatricallyResults Result Types type TVScreenedTheatricallyResults struct { - Results []struct { - ID int64 `json:"id"` - EpisodeNumber int `json:"episode_number"` - SeasonNumber int `json:"season_number"` - } `json:"results"` -} - -// TVWatchProvidersResults Result Types -type TVWatchProvidersResults struct { - Results map[string]struct { - Link string `json:"link"` - Flatrate []struct { - DisplayPriority int64 `json:"display_priority"` - LogoPath string `json:"logo_path"` - ProviderID int64 `json:"provider_id"` - ProviderName string `json:"provider_name"` - } `json:"flatrate,omitempty"` - Rent []struct { - DisplayPriority int64 `json:"display_priority"` - LogoPath string `json:"logo_path"` - ProviderID int64 `json:"provider_id"` - ProviderName string `json:"provider_name"` - } `json:"rent,omitempty"` - Buy []struct { - DisplayPriority int64 `json:"display_priority"` - LogoPath string `json:"logo_path"` - ProviderID int64 `json:"provider_id"` - ProviderName string `json:"provider_name"` - } `json:"buy,omitempty"` - } `json:"results"` -} - -// TVAiringTodayResults Result Types -type TVAiringTodayResults struct { - Results []struct { - OriginalName string `json:"original_name"` - GenreIDs []int64 `json:"genre_ids"` - Name string `json:"name"` - Popularity float32 `json:"popularity"` - OriginCountry []string `json:"origin_country"` - FirstAirDate string `json:"first_air_date"` - BackdropPath string `json:"backdrop_path"` - OriginalLanguage string `json:"original_language"` - ID int64 `json:"id"` - Overview string `json:"overview"` - PosterPath string `json:"poster_path"` - VoteMetrics - } `json:"results"` -} - -type VideoResult struct { + Results []ScreenedTheatrically `json:"results"` +} + +type Video struct { ID string `json:"id"` Iso639_1 string `json:"iso_639_1"` Iso3166_1 string `json:"iso_3166_1"` @@ -543,6 +110,103 @@ type VideoResult struct { } type VideoResults struct { - ID int64 `json:"id"` - Results []VideoResult `json:"results"` + ID int64 `json:"id"` + Results []Video `json:"results"` +} + +type PaginatedMovieMediaResults struct { + Results []MovieMedia `json:"results"` + PaginatedResultsMeta +} + +type PaginatedMovieResults struct { + Results []Movie `json:"results"` + PaginatedResultsMeta +} + +type PaginatedPersonTaggedImagesResults struct { + Results []PersonTaggedImage `json:"results"` + PaginatedResultsMeta +} + +type PaginatedTVShowMediaResults struct { + Results []TVShowMedia `json:"results"` + PaginatedResultsMeta +} + +type PaginatedTVShowResults struct { + Results []TVShow `json:"results"` + PaginatedResultsMeta +} + +type PaginatedTVShowRatingResults struct { + Results []TVShowRating `json:"results"` + PaginatedResultsMeta +} + +type PaginatedListResults struct { + Results []List `json:"results"` + PaginatedResultsMeta +} + +type PaginatedMovieRatingResults struct { + Results []MovieRating `json:"results"` + PaginatedResultsMeta +} + +type PaginatedTVEpisodeRatingResults struct { + Results []TVEpisodeRating `json:"results"` + PaginatedResultsMeta +} + +type PaginatedMediaResults struct { + Results []Media `json:"results"` + PaginatedResultsMeta +} + +type PaginatedKeywordsResults struct { + KeywordsResults + PaginatedResultsMeta +} + +// KeywordMovies type is a struct for movies that belong to a keyword JSON response. +type IDPaginatedMovieResults struct { + ID int64 `json:"id"` + PaginatedMovieResults +} + +type PaginatedReviewsResults struct { + Results []Review `json:"results"` + PaginatedResultsMeta +} + +type IDPaginatedReviewsResults struct { + ID int64 `json:"id"` + PaginatedReviewsResults +} + +type MediaWatchProviderResults struct { + Results []MediaWatchProvider `json:"results"` +} + +type CountryWatchProviderResults struct { + Results []Country `json:"results"` +} + +type AlternativeTitleResults struct { + Results []AlternativeTitle `json:"results"` +} + +type IDAlternativeTitleResults struct { + ID int `json:"id"` + AlternativeTitleResults +} + +type AlternativeNameResults struct { + Results []AlternativeName `json:"results"` +} + +type IDAlternativeNameResults struct { + ID int64 `json:"id"` + AlternativeNameResults } diff --git a/reviews.go b/reviews.go index c04827d..10d89c3 100644 --- a/reviews.go +++ b/reviews.go @@ -4,22 +4,11 @@ import "fmt" // ReviewDetails type is a struct for details JSON response. type ReviewDetails struct { - ID string `json:"id"` - Author string `json:"author"` - AuthorDetails struct { - AvatarPath string `json:"avatar_path"` - Name string `json:"name"` - Rating float32 `json:"rating"` - Username string `json:"username"` - } `json:"author_details"` - Content string `json:"content"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` - Iso639_1 string `json:"iso_639_1"` - MediaID int64 `json:"media_id"` - MediaTitle string `json:"media_title"` - MediaType string `json:"media_type"` - URL string `json:"url"` + Review + Iso639_1 string `json:"iso_639_1"` + MediaID int64 `json:"media_id"` + MediaTitle string `json:"media_title"` + MediaType MediaType `json:"media_type"` } // GetReviewDetails get review details by id. diff --git a/search.go b/search.go index 1bedfdb..8868802 100644 --- a/search.go +++ b/search.go @@ -5,19 +5,13 @@ import ( "net/url" ) -// SearchCompanies type is a struct for companies JSON response. -type SearchCompanies struct { - *SearchCompaniesResults - PaginatedResultsMeta -} - // GetSearchCompanies search for companies. // // https://developers.themoviedb.org/3/search/search-companies func (c *Client) GetSearchCompanies( query string, urlOptions map[string]string, -) (*SearchCompanies, error) { +) (*PaginatedCompanyInfoResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%scompany?api_key=%s&query=%s%s", @@ -27,26 +21,20 @@ func (c *Client) GetSearchCompanies( url.QueryEscape(query), options, ) - SearchCompanies := SearchCompanies{} + SearchCompanies := PaginatedCompanyInfoResults{} if err := c.get(tmdbURL, &SearchCompanies); err != nil { return nil, err } return &SearchCompanies, nil } -// SearchCollections type is a strcut for collections JSON response. -type SearchCollections struct { - *SearchCollectionsResults - PaginatedResultsMeta -} - // GetSearchCollections search for collections. // -// https://developers.themoviedb.org/3/search/search-collections +// https://developer.themoviedb.org/reference/search-collection func (c *Client) GetSearchCollections( query string, urlOptions map[string]string, -) (*SearchCollections, error) { +) (*PaginatedCollectionResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%scollection?api_key=%s&query=%s%s", @@ -56,26 +44,20 @@ func (c *Client) GetSearchCollections( url.QueryEscape(query), options, ) - searchCollections := SearchCollections{} + searchCollections := PaginatedCollectionResults{} if err := c.get(tmdbURL, &searchCollections); err != nil { return nil, err } return &searchCollections, nil } -// SearchKeywords type is a struct for keywords JSON response. -type SearchKeywords struct { - *SearchKeywordsResults - PaginatedResultsMeta -} - // GetSearchKeywords search for keywords. // -// https://developers.themoviedb.org/3/search/search-keywords +// https://developer.themoviedb.org/reference/search-keyword func (c *Client) GetSearchKeywords( query string, urlOptions map[string]string, -) (*SearchKeywords, error) { +) (*PaginatedKeywordsResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%skeyword?api_key=%s&query=%s%s", @@ -85,26 +67,20 @@ func (c *Client) GetSearchKeywords( url.QueryEscape(query), options, ) - searchKeywords := SearchKeywords{} + searchKeywords := PaginatedKeywordsResults{} if err := c.get(tmdbURL, &searchKeywords); err != nil { return nil, err } return &searchKeywords, nil } -// SearchMovies type is a struct for movies JSON response. -type SearchMovies struct { - PaginatedResultsMeta - *SearchMoviesResults -} - // GetSearchMovies search for keywords. // // https://developers.themoviedb.org/3/search/search-movies func (c *Client) GetSearchMovies( query string, urlOptions map[string]string, -) (*SearchMovies, error) { +) (*PaginatedMovieMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%smovie?api_key=%s&query=%s%s", @@ -114,19 +90,13 @@ func (c *Client) GetSearchMovies( url.QueryEscape(query), options, ) - searchMovies := SearchMovies{} + searchMovies := PaginatedMovieMediaResults{} if err := c.get(tmdbURL, &searchMovies); err != nil { return nil, err } return &searchMovies, nil } -// SearchMulti type is a struct for multi JSON response. -type SearchMulti struct { - *SearchMultiResults - PaginatedResultsMeta -} - // GetSearchMulti search multiple models in a single request. // Multi search currently supports searching for movies, // tv shows and people in a single request. @@ -135,7 +105,7 @@ type SearchMulti struct { func (c *Client) GetSearchMulti( query string, urlOptions map[string]string, -) (*SearchMulti, error) { +) (*PaginatedMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%smulti?api_key=%s&query=%s%s", @@ -145,26 +115,20 @@ func (c *Client) GetSearchMulti( url.QueryEscape(query), options, ) - searchMulti := SearchMulti{} + searchMulti := PaginatedMediaResults{} if err := c.get(tmdbURL, &searchMulti); err != nil { return nil, err } return &searchMulti, nil } -// SearchPeople type is a struct for people JSON response. -type SearchPeople struct { - PaginatedResultsMeta - *SearchPeopleResults -} - // GetSearchPeople search for people. // // https://developers.themoviedb.org/3/search/search-people func (c *Client) GetSearchPeople( query string, urlOptions map[string]string, -) (*SearchPeople, error) { +) (*PaginatedPersonMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%sperson?api_key=%s&query=%s%s", @@ -174,26 +138,20 @@ func (c *Client) GetSearchPeople( url.QueryEscape(query), options, ) - searchPeople := SearchPeople{} + searchPeople := PaginatedPersonMediaResults{} if err := c.get(tmdbURL, &searchPeople); err != nil { return nil, err } return &searchPeople, nil } -// SearchTVShows type is a struct for tv show JSON response. -type SearchTVShows struct { - PaginatedResultsMeta - *SearchTVShowsResults -} - // GetSearchTVShow search for a TV Show. // // https://developers.themoviedb.org/3/search/search-tv-shows func (c *Client) GetSearchTVShow( query string, urlOptions map[string]string, -) (*SearchTVShows, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%stv?api_key=%s&query=%s%s", @@ -203,7 +161,7 @@ func (c *Client) GetSearchTVShow( url.QueryEscape(query), options, ) - searchTVShows := SearchTVShows{} + searchTVShows := PaginatedTVShowResults{} if err := c.get(tmdbURL, &searchTVShows); err != nil { return nil, err } diff --git a/trending.go b/trending.go index d702539..8eefffe 100644 --- a/trending.go +++ b/trending.go @@ -4,12 +4,6 @@ import ( "fmt" ) -// Trending type is a struct for trending JSON response. -type Trending struct { - *TrendingResults - PaginatedResultsMeta -} - // GetTrending get the daily or weekly trending items. // // The daily trending list tracks items over the period of @@ -34,12 +28,12 @@ type Trending struct { // // week - View the trending list for the week. // -// https://developers.themoviedb.org/3/trending/get-trending +// https://developer.themoviedb.org/reference/trending-all func (c *Client) GetTrending( mediaType string, timeWindow string, urlOptions map[string]string, -) (*Trending, error) { +) (*PaginatedMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s/trending/%s/%s?api_key=%s%s", @@ -49,7 +43,7 @@ func (c *Client) GetTrending( c.apiKey, options, ) - trending := Trending{} + trending := PaginatedMediaResults{} if err := c.get(tmdbURL, &trending); err != nil { return nil, err } diff --git a/tv.go b/tv.go index 69207f6..cf3f0dd 100644 --- a/tv.go +++ b/tv.go @@ -3,160 +3,13 @@ package tmdb import ( "fmt" "net/http" - - json "github.com/goccy/go-json" ) -// TVDetails type is a struct for details JSON response. -type TVDetails struct { - BackdropPath string `json:"backdrop_path"` - CreatedBy []CreatedBy `json:"created_by"` - EpisodeRunTime []int `json:"episode_run_time"` - FirstAirDate string `json:"first_air_date"` - Genres []Genre `json:"genres"` - Homepage string `json:"homepage"` - ID int64 `json:"id"` - InProduction bool `json:"in_production"` - Languages []string `json:"languages"` - LastAirDate string `json:"last_air_date"` - Name string `json:"name"` - LastEpisodeToAir LastEpisodeToAir `json:"last_episode_to_air"` - NextEpisodeToAir NextEpisodeToAir `json:"next_episode_to_air"` - Networks []Network `json:"networks"` - NumberOfEpisodes int `json:"number_of_episodes"` - NumberOfSeasons int `json:"number_of_seasons"` - OriginCountry []string `json:"origin_country"` - OriginalLanguage string `json:"original_language"` - OriginalName string `json:"original_name"` - Overview string `json:"overview"` - Popularity float32 `json:"popularity"` - PosterPath string `json:"poster_path"` - ProductionCompanies []ProductionCompany `json:"production_companies"` - ProductionCountries []ProductionCountry `json:"production_countries"` - Seasons []Season `json:"seasons"` - Status string `json:"status"` - Tagline string `json:"tagline"` - Type string `json:"type"` - VoteMetrics - *TVAggregateCreditsAppend - *TVAlternativeTitlesAppend - *TVChangesAppend - *TVContentRatingsAppend - *TVCreditsAppend - *TVEpisodeGroupsAppend - *TVExternalIDsAppend - *TVImagesAppend - *TVKeywordsAppend - *TVRecommendationsAppend - *TVReviewsAppend - *TVScreenedTheatricallyAppend - *TVSimilarAppend - *TVTranslationsAppend - *TVVideosAppend - *TVWatchProvidersAppend -} - -// TVAggregateCreditsAppend type is a struct -// for aggregate credits in append to response. -type TVAggregateCreditsAppend struct { - AggregateCredits *TVAggregateCredits `json:"aggregate_credits,omitempty"` -} - -// TVAlternativeTitlesAppend type is a struct -// for alternative titles in append to response. -type TVAlternativeTitlesAppend struct { - AlternativeTitles *TVAlternativeTitles `json:"alternative_titles,omitempty"` -} - -// TVChangesAppend type is a struct for changes in append to response. -type TVChangesAppend struct { - Changes *TVChanges `json:"changes,omitempty"` -} - -// TVContentRatingsAppend type is a struct for -// content ratings in append to response. -type TVContentRatingsAppend struct { - ContentRatings *TVContentRatings `json:"content_ratings,omitempty"` -} - -// TVCreditsAppend type is a struct for credits in append to response. -type TVCreditsAppend struct { - Credits struct { - *TVCredits - } `json:"credits,omitempty"` -} - -// TVEpisodeGroupsAppend type is a struct for -// episode groups in append to response. -type TVEpisodeGroupsAppend struct { - EpisodeGroups *TVEpisodeGroups `json:"episode_groups,omitempty"` -} - -// TVExternalIDsAppend type is a short for -// external ids in append to response. -type TVExternalIDsAppend struct { - *TVExternalIDs `json:"external_ids,omitempty"` -} - -// TVImagesAppend type is a struct for images in append to response. -type TVImagesAppend struct { - Images *TVImages `json:"images,omitempty"` -} - -// TVKeywordsAppend type is a struct for keywords in append to response. -type TVKeywordsAppend struct { - Keywords struct { - *TVKeywords - } `json:"keywords,omitempty"` -} - -// TVRecommendationsAppend type is a struct -// for recommendations in append to response. -type TVRecommendationsAppend struct { - Recommendations *TVRecommendations `json:"recommendations,omitempty"` -} - -// TVReviewsAppend type is a struct for reviews in append to response. -type TVReviewsAppend struct { - Reviews struct { - *TVReviews - } `json:"reviews,omitempty"` -} - -// TVScreenedTheatricallyAppend type is a struct -// for screened theatrically in append to response. -type TVScreenedTheatricallyAppend struct { - ScreenedTheatrically *TVScreenedTheatrically `json:"screened_theatrically,omitempty"` -} - -// TVSimilarAppend type is a struct for -// similar tv shows in append to response. -type TVSimilarAppend struct { - Similar *TVSimilar `json:"similar,omitempty"` -} - -// TVTranslationsAppend type is a struct -// for translations in append to response. -type TVTranslationsAppend struct { - Translations *TVTranslations `json:"translations,omitempty"` -} - -// TVVideosAppend type is a struct for videos in append to response. -type TVVideosAppend struct { - Videos *VideoResults `json:"videos"` -} - -// TVWatchProvidersAppend type is a struct for -// watch/providers in append to response. -type TVWatchProvidersAppend struct { - WatchProviders *WatchProviderResults `json:"watch/providers"` -} - // GetTVDetails get the primary TV show details by id. // // Supports append_to_response. // -// https://developers.themoviedb.org/3/tv/get-tv-details +// https://developer.themoviedb.org/reference/tv-series-details func (c *Client) GetTVDetails( id int, urlOptions map[string]string, @@ -177,14 +30,6 @@ func (c *Client) GetTVDetails( return &tvDetails, nil } -// TVAccountStates type is a struct for account states JSON response. -type TVAccountStates struct { - ID int64 `json:"id"` - Favorite bool `json:"favorite"` - Rated json.RawMessage `json:"rated"` - Watchlist bool `json:"watchlist"` -} - // GetTVAccountStates grab the following account states for a session: // // TV show rating. @@ -214,52 +59,13 @@ func (c *Client) GetTVAccountStates( return &tvAccountStates, nil } -// TVAggregateCredits type is a struct for aggregate credits JSON response. -type TVAggregateCredits struct { - ID int64 `json:"id,omitempty"` - Cast []struct { - ID int64 `json:"id"` - Adult bool `json:"adult"` - Gender int `json:"gender"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - Order int `json:"order"` - OriginalName string `json:"original_name"` - Popularity float64 `json:"popularity"` - ProfilePath string `json:"profile_path"` - Roles []struct { - Character string `json:"character"` - CreditID string `json:"credit_id"` - EpisodeCount int `json:"episode_count"` - } `json:"roles"` - TotalEpisodeCount int `json:"total_episode_count"` - } `json:"cast"` - Crew []struct { - ID int64 `json:"id"` - Adult bool `json:"adult"` - Department string `json:"department"` - Gender int `json:"gender"` - Jobs []struct { - CreditID string `json:"credit_id"` - EpisodeCount int `json:"episode_count"` - Job string `json:"job"` - } `json:"jobs"` - TotalEpisodeCount int `json:"total_episode_count"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - OriginalName string `json:"original_name"` - Popularity float64 `json:"popularity"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` -} - // GetTVAggregateCredits get the aggregate credits (cast and crew) that have been added to a TV show. // -// https://developers.themoviedb.org/3/tv/get-tv-aggregate-credits +// https://developer.themoviedb.org/reference/tv-series-aggregate-credits func (c *Client) GetTVAggregateCredits( id int, urlOptions map[string]string, -) (*TVAggregateCredits, error) { +) (*IDTVAggregateCredits, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/aggregate_credits?api_key=%s%s", @@ -269,26 +75,20 @@ func (c *Client) GetTVAggregateCredits( c.apiKey, options, ) - tvAggregateCredits := TVAggregateCredits{} + tvAggregateCredits := IDTVAggregateCredits{} if err := c.get(tmdbURL, &tvAggregateCredits); err != nil { return nil, err } return &tvAggregateCredits, nil } -// TVAlternativeTitles type is a struct for alternative titles JSON response. -type TVAlternativeTitles struct { - ID int `json:"id"` - Results []AlternativeTitle `json:"results"` -} - // GetTVAlternativeTitles get all of the alternative titles for a TV show. // -// https://developers.themoviedb.org/3/tv/get-tv-alternative-titles +// https://developer.themoviedb.org/reference/tv-series-alternative-titles func (c *Client) GetTVAlternativeTitles( id int, urlOptions map[string]string, -) (*TVAlternativeTitles, error) { +) (*IDAlternativeTitleResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/alternative_titles?api_key=%s%s", @@ -298,29 +98,13 @@ func (c *Client) GetTVAlternativeTitles( c.apiKey, options, ) - tvAlternativeTitles := TVAlternativeTitles{} + tvAlternativeTitles := IDAlternativeTitleResults{} if err := c.get(tmdbURL, &tvAlternativeTitles); err != nil { return nil, err } return &tvAlternativeTitles, nil } -// TVChanges type is a struct for changes JSON response. -type TVChanges struct { - Changes []struct { - Key string `json:"key"` - Items []struct { - ID string `json:"id"` - Action string `json:"action"` - Time string `json:"time"` - Iso639_1 string `json:"iso_639_1"` - Iso3166_1 string `json:"iso_3166_1"` - Value json.RawMessage `json:"value"` - OriginalValue json.RawMessage `json:"original_value"` - } `json:"items"` - } `json:"changes"` -} - // GetTVChanges get the changes for a TV show. // // By default only the last 24 hours are returned. @@ -337,7 +121,7 @@ type TVChanges struct { func (c *Client) GetTVChanges( id int, urlOptions map[string]string, -) (*TVChanges, error) { +) (*Changes, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/changes?api_key=%s%s", @@ -347,26 +131,20 @@ func (c *Client) GetTVChanges( c.apiKey, options, ) - tVChanges := TVChanges{} + tVChanges := Changes{} if err := c.get(tmdbURL, &tVChanges); err != nil { return nil, err } return &tVChanges, nil } -// TVContentRatings type is a struct for content ratings JSON response. -type TVContentRatings struct { - *TVContentRatingsResults - ID int64 `json:"id,omitempty"` -} - // GetTVContentRatings get the list of content ratings (certifications) that have been added to a TV show. // // https://developers.themoviedb.org/3/tv/get-tv-content-ratings func (c *Client) GetTVContentRatings( id int, urlOptions map[string]string, -) (*TVContentRatings, error) { +) (*IDTVContentRatingsResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/content_ratings?api_key=%s%s", @@ -376,42 +154,13 @@ func (c *Client) GetTVContentRatings( c.apiKey, options, ) - tvContentRatings := TVContentRatings{} + tvContentRatings := IDTVContentRatingsResults{} if err := c.get(tmdbURL, &tvContentRatings); err != nil { return nil, err } return &tvContentRatings, nil } -// TVCredits type is a struct for credits JSON response. -type TVCredits struct { - ID int64 `json:"id,omitempty"` - Cast []struct { - Character string `json:"character"` - CreditID string `json:"credit_id"` - Gender int `json:"gender"` - ID int64 `json:"id"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - Order int `json:"order"` - OriginalName string `json:"original_name"` - Popularity float32 `json:"popularity"` - ProfilePath string `json:"profile_path"` - } `json:"cast"` - Crew []struct { - CreditID string `json:"credit_id"` - Department string `json:"department"` - Gender int `json:"gender"` - ID int64 `json:"id"` - Job string `json:"job"` - KnownForDepartment string `json:"known_for_department"` - Name string `json:"name"` - OriginalName string `json:"original_name"` - Popularity float32 `json:"popularity"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` -} - // GetTVCredits get the credits (cast and crew) that have been added to a TV show. // // https://developers.themoviedb.org/3/tv/get-tv-credits @@ -435,12 +184,6 @@ func (c *Client) GetTVCredits( return &tvCredits, nil } -// TVEpisodeGroups type is a struct for episode groups JSON response. -type TVEpisodeGroups struct { - *TVEpisodeGroupsResults - ID int64 `json:"id,omitempty"` -} - // GetTVEpisodeGroups get all of the episode groups that have been created for a TV show. // // With a group ID you can call the get TV episode group details method. @@ -449,7 +192,7 @@ type TVEpisodeGroups struct { func (c *Client) GetTVEpisodeGroups( id int, urlOptions map[string]string, -) (*TVEpisodeGroups, error) { +) (*IDTVEpisodeGroupsResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/episode_groups?api_key=%s%s", @@ -459,27 +202,13 @@ func (c *Client) GetTVEpisodeGroups( c.apiKey, options, ) - tVEpisodeGroups := TVEpisodeGroups{} + tVEpisodeGroups := IDTVEpisodeGroupsResults{} if err := c.get(tmdbURL, &tVEpisodeGroups); err != nil { return nil, err } return &tVEpisodeGroups, nil } -// TVExternalIDs type is a struct for external ids JSON response. -type TVExternalIDs struct { - IMDbID string `json:"imdb_id"` - FreebaseMID string `json:"freebase_mid"` - FreebaseID string `json:"freebase_id"` - TVDBID int64 `json:"tvdb_id"` - TVRageID int64 `json:"tvrage_id"` - FacebookID string `json:"facebook_id"` - InstagramID string `json:"instagram_id"` - TwitterID string `json:"twitter_id"` - WikiDataID string `json:"wikidata_id,omitempty"` - ID int64 `json:"id,omitempty"` -} - // GetTVExternalIDs get the external ids for a TV show. // // We currently support the following external sources. @@ -511,20 +240,6 @@ func (c *Client) GetTVExternalIDs( return &tvExternalIDs, nil } -// TVImage type is a struct for a single image. -type TVImage struct { - ImageBase - Iso639_1 string `json:"iso_639_1"` -} - -// TVImages type is a struct for images JSON response. -type TVImages struct { - ID int64 `json:"id,omitempty"` - Backdrops []TVImage `json:"backdrops"` - Logos []TVImage `json:"logos"` - Posters []TVImage `json:"posters"` -} - // GetTVImages get the images that belong to a TV show. // // Querying images with a language parameter will filter the results. @@ -532,11 +247,11 @@ type TVImages struct { // you can use the include_image_language parameter. This should be a comma // separated value like so: include_image_language=en,null. // -// https://developers.themoviedb.org/3/tv/get-tv-images +// https://developer.themoviedb.org/reference/tv-series-images func (c *Client) GetTVImages( id int, urlOptions map[string]string, -) (*TVImages, error) { +) (*IDTVImages, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/images?api_key=%s%s", @@ -546,25 +261,19 @@ func (c *Client) GetTVImages( c.apiKey, options, ) - tvImages := TVImages{} + tvImages := IDTVImages{} if err := c.get(tmdbURL, &tvImages); err != nil { return nil, err } return &tvImages, nil } -// TVKeywords type is a struct for keywords JSON response. -type TVKeywords struct { - ID int64 `json:"id,omitempty"` - *TVKeywordsResults -} - // GetTVKeywords get the keywords that have been added to a TV show. // // https://developers.themoviedb.org/3/tv/get-tv-keywords func (c *Client) GetTVKeywords( id int, -) (*TVKeywords, error) { +) (*IDKeywordsResults, error) { tmdbURL := fmt.Sprintf( "%s%s%d/keywords?api_key=%s", baseURL, @@ -572,26 +281,20 @@ func (c *Client) GetTVKeywords( id, c.apiKey, ) - tvKeywords := TVKeywords{} + tvKeywords := IDKeywordsResults{} if err := c.get(tmdbURL, &tvKeywords); err != nil { return nil, err } return &tvKeywords, nil } -// TVRecommendations type is a struct for recommendations JSON response. -type TVRecommendations struct { - *TVRecommendationsResults - PaginatedResultsMeta -} - // GetTVRecommendations get the list of TV show recommendations for this item. // -// https://developers.themoviedb.org/3/tv/get-tv-recommendations +// https://developer.themoviedb.org/reference/tv-series-recommendations func (c *Client) GetTVRecommendations( id int, urlOptions map[string]string, -) (*TVRecommendations, error) { +) (*PaginatedTVShowMediaResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/recommendations?api_key=%s%s", @@ -601,27 +304,20 @@ func (c *Client) GetTVRecommendations( c.apiKey, options, ) - tvRecommendations := TVRecommendations{} + tvRecommendations := PaginatedTVShowMediaResults{} if err := c.get(tmdbURL, &tvRecommendations); err != nil { return nil, err } return &tvRecommendations, nil } -// TVReviews type is a struct for reviews JSON response. -type TVReviews struct { - ID int64 `json:"id,omitempty"` - *TVReviewsResults - PaginatedResultsMeta -} - // GetTVReviews get the reviews for a TV show. // -// https://developers.themoviedb.org/3/tv/get-tv-reviews +// https://developer.themoviedb.org/reference/tv-series-reviews func (c *Client) GetTVReviews( id int, urlOptions map[string]string, -) (*TVReviews, error) { +) (*IDPaginatedReviewsResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/reviews?api_key=%s%s", @@ -631,19 +327,13 @@ func (c *Client) GetTVReviews( c.apiKey, options, ) - tvReviews := TVReviews{} + tvReviews := IDPaginatedReviewsResults{} if err := c.get(tmdbURL, &tvReviews); err != nil { return nil, err } return &tvReviews, nil } -// TVScreenedTheatrically type is a struct for screened theatrically JSON response. -type TVScreenedTheatrically struct { - ID int64 `json:"id,omitempty"` - *TVScreenedTheatricallyResults -} - // GetTVScreenedTheatrically get a list of seasons or episodes that // have been screened in a film festival or theatre. // @@ -665,11 +355,6 @@ func (c *Client) GetTVScreenedTheatrically( return &tvScreenedTheatrically, nil } -// TVSimilar type is a struct for similar tv shows JSON response. -type TVSimilar struct { - *TVRecommendations -} - // GetTVSimilar a list of similar TV shows. // These items are assembled by looking at keywords and genres. // @@ -677,7 +362,7 @@ type TVSimilar struct { func (c *Client) GetTVSimilar( id int, urlOptions map[string]string, -) (*TVSimilar, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/similar?api_key=%s%s", @@ -687,7 +372,7 @@ func (c *Client) GetTVSimilar( c.apiKey, options, ) - tVSimilar := TVSimilar{} + tVSimilar := PaginatedTVShowResults{} if err := c.get(tmdbURL, &tVSimilar); err != nil { return nil, err } @@ -700,7 +385,7 @@ func (c *Client) GetTVSimilar( func (c *Client) GetTVWatchProviders( id int, urlOptions map[string]string, -) (*WatchProviderResults, error) { +) (*IDWatchProviderResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d/watch/providers?api_key=%s%s", @@ -710,19 +395,13 @@ func (c *Client) GetTVWatchProviders( c.apiKey, options, ) - tvWatchProviders := WatchProviderResults{} + tvWatchProviders := IDWatchProviderResults{} if err := c.get(tmdbURL, &tvWatchProviders); err != nil { return nil, err } return &tvWatchProviders, nil } -// TVTranslations type is a struct for translations JSON response. -type TVTranslations struct { - ID int64 `json:"id,omitempty"` - Translations []Translation `json:"translations"` -} - // GetTVTranslations get a list fo translations that have been created for a TV Show. // // https://developers.themoviedb.org/3/tv/get-tv-translations @@ -769,11 +448,6 @@ func (c *Client) GetTVVideos( return &tvVideos, nil } -// TVLatest type is a struct for latest JSON response. -type TVLatest struct { - *TVDetails -} - // GetTVLatest get the most newly created TV show. // // This is a live response and will continuously change. @@ -781,7 +455,7 @@ type TVLatest struct { // https://developers.themoviedb.org/3/tv/get-latest-tv func (c *Client) GetTVLatest( urlOptions map[string]string, -) (*TVLatest, error) { +) (*TVDetails, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%slatest?api_key=%s%s", @@ -790,19 +464,13 @@ func (c *Client) GetTVLatest( c.apiKey, options, ) - tvLatest := TVLatest{} + tvLatest := TVDetails{} if err := c.get(tmdbURL, &tvLatest); err != nil { return nil, err } return &tvLatest, nil } -// TVAiringToday type is a struct for airing today JSON response. -type TVAiringToday struct { - PaginatedResultsMeta - *TVAiringTodayResults -} - // GetTVAiringToday get a list of TV shows that are airing today. // This query is purely day based as we do not currently support // airing times. @@ -814,7 +482,7 @@ type TVAiringToday struct { // https://developers.themoviedb.org/3/tv/get-tv-airing-today func (c *Client) GetTVAiringToday( urlOptions map[string]string, -) (*TVAiringToday, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%sairing_today?api_key=%s%s", @@ -823,18 +491,13 @@ func (c *Client) GetTVAiringToday( c.apiKey, options, ) - tvAiringToday := TVAiringToday{} + tvAiringToday := PaginatedTVShowResults{} if err := c.get(tmdbURL, &tvAiringToday); err != nil { return nil, err } return &tvAiringToday, nil } -// TVOnTheAir type is a struct for on the air JSON response. -type TVOnTheAir struct { - *TVAiringToday -} - // GetTVOnTheAir get a list of shows that are currently on the air. // // This query looks for any TV show that has an episode with an @@ -843,7 +506,7 @@ type TVOnTheAir struct { // https://developers.themoviedb.org/3/tv/get-tv-on-the-air func (c *Client) GetTVOnTheAir( urlOptions map[string]string, -) (*TVOnTheAir, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%son_the_air?api_key=%s%s", @@ -852,25 +515,20 @@ func (c *Client) GetTVOnTheAir( c.apiKey, options, ) - tvOnTheAir := TVOnTheAir{} + tvOnTheAir := PaginatedTVShowResults{} if err := c.get(tmdbURL, &tvOnTheAir); err != nil { return nil, err } return &tvOnTheAir, nil } -// TVPopular type is a struct for popular JSON response. -type TVPopular struct { - *TVAiringToday -} - // GetTVPopular get a list of the current popular TV shows on TMDb. // This list updates daily. // // https://developers.themoviedb.org/3/tv/get-popular-tv-shows func (c *Client) GetTVPopular( urlOptions map[string]string, -) (*TVPopular, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%spopular?api_key=%s%s", @@ -879,24 +537,19 @@ func (c *Client) GetTVPopular( c.apiKey, options, ) - tvPopular := TVPopular{} + tvPopular := PaginatedTVShowResults{} if err := c.get(tmdbURL, &tvPopular); err != nil { return nil, err } return &tvPopular, nil } -// TVTopRated type is a struct for top rated JSON response. -type TVTopRated struct { - *TVAiringToday -} - // GetTVTopRated get a list of the top rated TV shows on TMDb. // // https://developers.themoviedb.org/3/tv/get-top-rated-tv func (c *Client) GetTVTopRated( urlOptions map[string]string, -) (*TVTopRated, error) { +) (*PaginatedTVShowResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%stop_rated?api_key=%s%s", @@ -905,7 +558,7 @@ func (c *Client) GetTVTopRated( c.apiKey, options, ) - tvTopRated := TVTopRated{} + tvTopRated := PaginatedTVShowResults{} if err := c.get(tmdbURL, &tvTopRated); err != nil { return nil, err } diff --git a/tv_episode_groups.go b/tv_episode_groups.go index ceb4c8c..07db0af 100644 --- a/tv_episode_groups.go +++ b/tv_episode_groups.go @@ -2,45 +2,8 @@ package tmdb import ( "fmt" - - json "github.com/goccy/go-json" ) -// TVEpisodeGroupsDetails type is a struct for details JSON response. -type TVEpisodeGroupsDetails struct { - Description string `json:"description"` - EpisodeCount int `json:"episode_count"` - GroupCount int `json:"group_count"` - Groups []struct { - ID string `json:"id"` - Name string `json:"name"` - Order int `json:"order"` - Episodes []struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode json.RawMessage `json:"production_code"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - Order int `json:"order"` - VoteMetrics - } `json:"episodes"` - Locked bool `json:"locked"` - } `json:"groups"` - ID string `json:"id"` - Name string `json:"name"` - Network struct { - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - Name string `json:"name"` - OriginCountry string `json:"origin_country"` - } `json:"network"` - Type int `json:"type"` -} - // GetTVEpisodeGroupsDetails the details of a TV episode group. // Groups support 7 different types which are enumerated as the following: // @@ -52,7 +15,7 @@ type TVEpisodeGroupsDetails struct { // 6. Production // 7. TV // -// https://developers.themoviedb.org/3/tv-episode-groups/get-tv-episode-group-details +// https://developer.themoviedb.org/reference/tv-episode-group-details func (c *Client) GetTVEpisodeGroupsDetails( id string, urlOptions map[string]string, diff --git a/tv_episode_groups_struct.go b/tv_episode_groups_struct.go new file mode 100644 index 0000000..29ea5e3 --- /dev/null +++ b/tv_episode_groups_struct.go @@ -0,0 +1,13 @@ +package tmdb + +// TVEpisodeGroupsDetails type is a struct for details JSON response. +type TVEpisodeGroupsDetails struct { + Description string `json:"description"` + EpisodeCount int `json:"episode_count"` + GroupCount int `json:"group_count"` + Groups []Group `json:"groups"` + ID string `json:"id"` + Name string `json:"name"` + Network Network `json:"network"` + Type GroupType `json:"type"` +} diff --git a/tv_episodes.go b/tv_episodes.go index 206fb68..8b8ce99 100644 --- a/tv_episodes.go +++ b/tv_episodes.go @@ -2,77 +2,8 @@ package tmdb import ( "fmt" - - json "github.com/goccy/go-json" ) -// TVEpisodeDetails type is a struct for details JSON response. -type TVEpisodeDetails struct { - AirDate string `json:"air_date"` - Crew []struct { - ID int64 `json:"id"` - CreditID string `json:"credit_id"` - Name string `json:"name"` - Department string `json:"department"` - Job string `json:"job"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` - EpisodeNumber int `json:"episode_number"` - GuestStars []struct { - ID int64 `json:"id"` - Name string `json:"name"` - CreditID string `json:"credit_id"` - Character string `json:"character"` - Order int `json:"order"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` - } `json:"guest_stars"` - Name string `json:"name"` - Overview string `json:"overview"` - ID int64 `json:"id"` - ProductionCode string `json:"production_code"` - Runtime int `json:"runtime"` - SeasonNumber int `json:"season_number"` - StillPath string `json:"still_path"` - VoteMetrics - *TVEpisodeCreditsAppend - *TVEpisodeExternalIDsAppend - *TVEpisodeImagesAppend - *TVEpisodeTranslationsAppend - *TVEpisodeVideosAppend -} - -// TVEpisodeCreditsAppend type is a struct -// for credits in append to response. -type TVEpisodeCreditsAppend struct { - Credits *TVEpisodeCredits `json:"credits,omitempty"` -} - -// TVEpisodeExternalIDsAppend type is a struct -// for external ids in append to response. -type TVEpisodeExternalIDsAppend struct { - ExternalIDs *TVEpisodeExternalIDs `json:"external_ids,omitempty"` -} - -// TVEpisodeImagesAppend type is a struct -// for images in append to response. -type TVEpisodeImagesAppend struct { - Images *TVEpisodeImages `json:"images,omitempty"` -} - -// TVEpisodeTranslationsAppend type is a struct -// for translations in append to response. -type TVEpisodeTranslationsAppend struct { - Translations *TVEpisodeTranslations `json:"translations,omitempty"` -} - -// TVEpisodeVideosAppend type is a struct -// for videos in append to response. -type TVEpisodeVideosAppend struct { - Videos *VideoResults `json:"videos"` -} - // GetTVEpisodeDetails get the TV episode details by id. // // Supports append_to_response. @@ -104,27 +35,6 @@ func (c *Client) GetTVEpisodeDetails( return &tvEpisodeDetails, nil } -// TVEpisodeChanges type is a struct for changes JSON response. -type TVEpisodeChanges struct { - Changes []struct { - Key string `json:"key"` - Items []struct { - ID string `json:"id"` - Action string `json:"action"` - Time string `json:"time"` - Iso639_1 string `json:"iso_639_1"` - Iso3166_1 string `json:"iso_3166_1"` - OriginalValue struct { - PersonID int64 `json:"person_id"` - Character string `json:"character"` - Order int64 `json:"order"` - CreditID string `json:"credit_id"` - } `json:"original_values,omitempty"` - Value json.RawMessage `json:"value,omitempty"` - } `json:"items"` - } `json:"changes"` -} - // GetTVEpisodeChanges get the changes for a TV episode. // By default only the last 24 hours are returned. // @@ -135,7 +45,7 @@ type TVEpisodeChanges struct { func (c *Client) GetTVEpisodeChanges( id int, urlOptions map[string]string, -) (*TVEpisodeChanges, error) { +) (*Changes, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%sepisode/%d/changes?api_key=%s%s", @@ -145,45 +55,13 @@ func (c *Client) GetTVEpisodeChanges( c.apiKey, options, ) - tvEpisodeChanges := TVEpisodeChanges{} + tvEpisodeChanges := Changes{} if err := c.get(tmdbURL, &tvEpisodeChanges); err != nil { return nil, err } return &tvEpisodeChanges, nil } -// TVEpisodeCredits type is a struct for credits JSON response. -type TVEpisodeCredits struct { - Cast []struct { - Character string `json:"character"` - CreditID string `json:"credit_id"` - Gender int `json:"gender"` - ID int64 `json:"id"` - Name string `json:"name"` - Order int `json:"order"` - ProfilePath string `json:"profile_path"` - } `json:"cast"` - Crew []struct { - ID int64 `json:"id"` - CreditID string `json:"credit_id"` - Name string `json:"name"` - Department string `json:"department"` - Job string `json:"job"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` - GuestStars []struct { - ID int64 `json:"id"` - Name string `json:"name"` - CreditID string `json:"credit_id"` - Character string `json:"character"` - Order int `json:"order"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` - } `json:"guest_stars"` - ID int64 `json:"id,omitempty"` -} - // GetTVEpisodeCredits get the credits (cast, crew and guest stars) for a TV episode. // // https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-credits @@ -210,16 +88,6 @@ func (c *Client) GetTVEpisodeCredits( return &tvEpisodeCredits, nil } -// TVEpisodeExternalIDs type is a struct for external ids JSON response. -type TVEpisodeExternalIDs struct { - ID int64 `json:"id,omitempty"` - IMDbID string `json:"imdb_id"` - FreebaseMID string `json:"freebase_mid"` - FreebaseID string `json:"freebase_id"` - TVDBID int64 `json:"tvdb_id"` - TVRageID int64 `json:"tvrage_id"` -} - // GetTVEpisodeExternalIDs get the external ids for a TV episode. // We currently support the following external sources. // @@ -251,18 +119,6 @@ func (c *Client) GetTVEpisodeExternalIDs( return &tvEpisodeExternalIDs, nil } -// TVEpisodeImage type is a struct for a single image. -type TVEpisodeImage struct { - ImageBase - Iso6391 any `json:"iso_639_1"` -} - -// TVEpisodeImages type is a struct for images JSON response. -type TVEpisodeImages struct { - ID int64 `json:"id,omitempty"` - Stills []TVEpisodeImage `json:"stills"` -} - // GetTVEpisodeImages get the images that belong to a TV episode. // // Querying images with a language parameter will filter the results. @@ -294,12 +150,6 @@ func (c *Client) GetTVEpisodeImages( return &tvEpisodeImages, nil } -// TVEpisodeTranslations type is a struct for translations JSON response. -type TVEpisodeTranslations struct { - ID int64 `json:"id,omitempty"` - Translations []Translation `json:"translations"` -} - // GetTVEpisodeTranslations get the translation data for an episode. // // https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-translations @@ -326,12 +176,6 @@ func (c *Client) GetTVEpisodeTranslations( return &tvEpisodeTranslations, nil } -// TVEpisodeRate type is a struct for rate JSON response. -type TVEpisodeRate struct { - StatusCode int `json:"status_code"` - StatusMessage string `json:"status_message"` -} - // GetTVEpisodeVideos get the videos that have been added to a TV episode. // // https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-videos diff --git a/tv_episodes_struct.go b/tv_episodes_struct.go new file mode 100644 index 0000000..4425f42 --- /dev/null +++ b/tv_episodes_struct.go @@ -0,0 +1,77 @@ +package tmdb + +// TVEpisodeDetails type is a struct for details JSON response. +type TVEpisodeDetails struct { + TVEpisodeDetailsBase + *TVEpisodeCreditsAppend + *TVEpisodeExternalIDsAppend + *TVEpisodeImagesAppend + *TVEpisodeTranslationsAppend + *TVEpisodeVideosAppend +} + +// TVEpisodeCreditsAppend type is a struct +// for credits in append to response. +type TVEpisodeCreditsAppend struct { + Credits *TVEpisodeCredits `json:"credits"` +} + +// TVEpisodeExternalIDsAppend type is a struct +// for external ids in append to response. +type TVEpisodeExternalIDsAppend struct { + ExternalIDs *TVEpisodeExternalIDs `json:"external_ids"` +} + +// TVEpisodeImagesAppend type is a struct +// for images in append to response. +type TVEpisodeImagesAppend struct { + Images *TVEpisodeImages `json:"images"` +} + +// TVEpisodeTranslationsAppend type is a struct +// for translations in append to response. +type TVEpisodeTranslationsAppend struct { + Translations *TVEpisodeTranslations `json:"translations"` +} + +// TVEpisodeVideosAppend type is a struct +// for videos in append to response. +type TVEpisodeVideosAppend struct { + Videos *VideoResults `json:"videos"` +} + +// TVEpisodeCredits type is a struct for credits JSON response. +type TVEpisodeCredits struct { + Cast []CastBase `json:"cast"` + Crew []Crew `json:"crew"` + GuestStars []CastBase `json:"guest_stars"` + ID int64 `json:"id"` +} + +// TVEpisodeExternalIDs type is a struct for external ids JSON response. +type TVEpisodeExternalIDs struct { + ID int64 `json:"id,omitempty"` + IMDbID string `json:"imdb_id"` + FreebaseMID string `json:"freebase_mid"` + FreebaseID string `json:"freebase_id"` + TVDBID int64 `json:"tvdb_id"` + TVRageID int64 `json:"tvrage_id"` +} + +// TVEpisodeImages type is a struct for images JSON response. +type TVEpisodeImages struct { + ID int64 `json:"id"` + Stills []ImageIso `json:"stills"` +} + +// TVEpisodeTranslations type is a struct for translations JSON response. +type TVEpisodeTranslations struct { + ID int64 `json:"id"` + Translations []TVEpisodeTranslation `json:"translations"` +} + +// TVEpisodeRate type is a struct for rate JSON response. +type TVEpisodeRate struct { + StatusCode int `json:"status_code"` + StatusMessage string `json:"status_message"` +} diff --git a/tv_seasons.go b/tv_seasons.go index 4a29eb1..9ab8886 100644 --- a/tv_seasons.go +++ b/tv_seasons.go @@ -2,96 +2,11 @@ package tmdb import "fmt" -// TVSeasonDetails is a struct for details JSON response. -type TVSeasonDetails struct { - IDString string `json:"_id"` - AirDate string `json:"air_date"` - Episodes []struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode string `json:"production_code"` - Runtime int `json:"runtime"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - VoteMetrics - Crew []struct { - ID int64 `json:"id"` - CreditID string `json:"credit_id"` - Name string `json:"name"` - Department string `json:"department"` - Job string `json:"job"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` - GuestStars []struct { - ID int64 `json:"id"` - Name string `json:"name"` - CreditID string `json:"credit_id"` - Character string `json:"character"` - Order int `json:"order"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` - } `json:"guest_stars"` - } `json:"episodes"` - Name string `json:"name"` - Overview string `json:"overview"` - ID int64 `json:"id"` - PosterPath string `json:"poster_path"` - SeasonNumber int `json:"season_number"` - VoteAverage float32 `json:"vote_average"` - *TVAggregateCreditsAppend - *TVSeasonCreditsAppend - *TVSeasonExternalIDsAppend - *TVSeasonImagesAppend - *TVSeasonVideosAppend - *TVSeasonTranslationsAppend -} - -// TVSeasonCreditsAppend type is a struct -// for credits in append to response. -type TVSeasonCreditsAppend struct { - Credits *TVSeasonCredits `json:"credits,omitempty"` -} - -// TVSeasonExternalIDsAppend type is a struct -// for external ids in append to response. -type TVSeasonExternalIDsAppend struct { - ExternalIDs *TVSeasonExternalIDs `json:"external_ids,omitempty"` -} - -// TVSeasonImagesAppend type is a struct -// for images in append to response. -type TVSeasonImagesAppend struct { - Images *TVSeasonImages `json:"images,omitempty"` -} - -// TVSeasonTranslationsAppend type is a struct -// for translations in append to response. -type TVSeasonTranslationsAppend struct { - Translations *TVSeasonTranslations `json:"translations,omitempty"` -} - -// TVSeasonTranslations type is a struct -type TVSeasonTranslations struct { - ID int64 `json:"id,omitempty"` - Translations []Translation `json:"translations"` -} - -// TVSeasonVideosAppend type is a struct -// for videos in append to response. -type TVSeasonVideosAppend struct { - Videos *VideoResults `json:"videos"` -} - // GetTVSeasonDetails get the TV season details by id. // // Supports append_to_response. // -// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-details +// https://developer.themoviedb.org/reference/tv-season-details func (c *Client) GetTVSeasonDetails( id int, seasonNumber int, @@ -115,35 +30,17 @@ func (c *Client) GetTVSeasonDetails( return &tvSeasonDetails, nil } -// TVSeasonChanges is a struct for changes JSON response. -type TVSeasonChanges struct { - Changes []struct { - Items []struct { - ID string `json:"id"` - Action string `json:"action"` - Time string `json:"time"` - Iso639_1 string `json:"iso_639_1"` - Iso3166_1 string `json:"iso_3166_1"` - Value struct { - EpisodeID int64 `json:"episode_id"` - EpisodeNumber int `json:"episode_number"` - } `json:"value"` - } `json:"items"` - Key string `json:"key"` - } `json:"changes"` -} - // GetTVSeasonChanges get the changes for a TV season. // By default only the last 24 hours are returned. // // You can query up to 14 days in a single query by using // the start_date and end_date query parameters. // -// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-changes +// https://developer.themoviedb.org/reference/tv-season-changes-by-id func (c *Client) GetTVSeasonChanges( id int, urlOptions map[string]string, -) (*TVSeasonChanges, error) { +) (*Changes, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%sseason/%d/changes?api_key=%s%s", @@ -153,44 +50,21 @@ func (c *Client) GetTVSeasonChanges( c.apiKey, options, ) - tvSeasonChanges := TVSeasonChanges{} + tvSeasonChanges := Changes{} if err := c.get(tmdbURL, &tvSeasonChanges); err != nil { return nil, err } return &tvSeasonChanges, nil } -// TVSeasonCredits type is a struct for credits JSON response. -type TVSeasonCredits struct { - Cast []struct { - Character string `json:"character"` - CreditID string `json:"credit_id"` - Gender int `json:"gender"` - ID int64 `json:"id"` - Name string `json:"name"` - Order int `json:"order"` - ProfilePath string `json:"profile_path"` - } `json:"cast"` - Crew []struct { - CreditID string `json:"credit_id"` - Department string `json:"department"` - Gender int `json:"gender"` - ID int64 `json:"id"` - Job string `json:"job"` - Name string `json:"name"` - ProfilePath string `json:"profile_path"` - } `json:"crew"` - ID int `json:"id"` -} - // GetTVSeasonCredits get the credits for TV season. // -// https://developers.themoviedb.org/3/tv-seasons/get-tv-season-credits +// https://developer.themoviedb.org/reference/tv-season-credits func (c *Client) GetTVSeasonCredits( id int, seasonNumber int, urlOptions map[string]string, -) (*TVSeasonCredits, error) { +) (*TVCredits, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%s%d%s%d/credits?api_key=%s%s", @@ -202,22 +76,13 @@ func (c *Client) GetTVSeasonCredits( c.apiKey, options, ) - tVSeasonCredits := TVSeasonCredits{} + tVSeasonCredits := TVCredits{} if err := c.get(tmdbURL, &tVSeasonCredits); err != nil { return nil, err } return &tVSeasonCredits, nil } -// TVSeasonExternalIDs type is a struct for external ids JSON response. -type TVSeasonExternalIDs struct { - FreebaseMID string `json:"freebase_mid"` - FreebaseID string `json:"freebase_id"` - TVDBID int64 `json:"tvdb_id"` - TVRageID int64 `json:"tvrage_id"` - ID int64 `json:"id,omitempty"` -} - // GetTVSeasonExternalIDs get the external ids for a TV season. // We currently support the following external sources. // @@ -249,18 +114,6 @@ func (c *Client) GetTVSeasonExternalIDs( return &tvSeasonExternalIDs, nil } -// TVSeasonImage type is a struct for a single image. -type TVSeasonImage struct { - ImageBase - Iso639_1 string `json:"iso_639_1"` -} - -// TVSeasonImages type is a struct for images JSON response. -type TVSeasonImages struct { - ID int64 `json:"id,omitempty"` - Posters []TVSeasonImage `json:"posters"` -} - // GetTVSeasonImages get the images that belong to a TV season. // // Querying images with a language parameter will filter the results. diff --git a/tv_seasons_struct.go b/tv_seasons_struct.go new file mode 100644 index 0000000..327b6f0 --- /dev/null +++ b/tv_seasons_struct.go @@ -0,0 +1,75 @@ +package tmdb + +// TVSeasonDetails is a struct for details JSON response. +type TVSeasonDetails struct { + TVSeason + IDString string `json:"_id"` + Episodes []TVEpisodeDetailsBase `json:"episodes"` + *TVAggregateCreditsAppend + *TVSeasonCreditsAppend + *TVSeasonExternalIDsAppend + *TVSeasonImagesAppend + *TVSeasonVideosAppend + *TVSeasonTranslationsAppend +} + +// TVSeasonCreditsAppend type is a struct +// for credits in append to response. +type TVSeasonCreditsAppend struct { + Credits TVCredits `json:"credits"` +} + +// TVSeasonExternalIDsAppend type is a struct +// for external ids in append to response. +type TVSeasonExternalIDsAppend struct { + ExternalIDs TVSeasonExternalIDs `json:"external_ids"` +} + +// TVSeasonImagesAppend type is a struct +// for images in append to response. +type TVSeasonImagesAppend struct { + Images TVSeasonImages `json:"images"` +} + +// TVSeasonTranslationsAppend type is a struct +// for translations in append to response. +type TVSeasonTranslationsAppend struct { + Translations TVSeasonTranslations `json:"translations"` +} + +// TVSeasonTranslations type is a struct +type TVSeasonTranslations struct { + ID int64 `json:"id"` + Translations []TVSeasonTranslation `json:"translations"` +} + +type TVSeasonTranslation struct { + TranslationBase + Data TVSeasonDataTranslation `json:"data"` +} + +type TVSeasonDataTranslation struct { + Name string `json:"name"` + Overview string `json:"overview"` +} + +// TVSeasonVideosAppend type is a struct +// for videos in append to response. +type TVSeasonVideosAppend struct { + Videos *VideoResults `json:"videos"` +} + +// TVSeasonExternalIDs type is a struct for external ids JSON response. +type TVSeasonExternalIDs struct { + FreebaseMID string `json:"freebase_mid"` + FreebaseID string `json:"freebase_id"` + TVDBID int64 `json:"tvdb_id"` + TVRageID int64 `json:"tvrage_id"` + ID int64 `json:"id,omitempty"` +} + +// TVSeasonImages type is a struct for images JSON response. +type TVSeasonImages struct { + ID int64 `json:"id"` + Posters []ImageIso `json:"posters"` +} diff --git a/tv_struct.go b/tv_struct.go new file mode 100644 index 0000000..26629cc --- /dev/null +++ b/tv_struct.go @@ -0,0 +1,191 @@ +package tmdb + +// TVDetails type is a struct for details JSON response. +type TVDetails struct { + VideoDetails + TVShowMeta + CreatedBy []CreatedBy `json:"created_by"` + EpisodeRunTime []int `json:"episode_run_time"` + InProduction bool `json:"in_production"` + Languages []string `json:"languages"` + LastAirDate string `json:"last_air_date"` + LastEpisodeToAir TVEpisode `json:"last_episode_to_air"` + NextEpisodeToAir *TVEpisode `json:"next_episode_to_air"` + Networks []Network `json:"networks"` + NumberOfEpisodes int `json:"number_of_episodes"` + NumberOfSeasons int `json:"number_of_seasons"` + Seasons []Season `json:"seasons"` + Type string `json:"type"` + *TVAggregateCreditsAppend + *TVAlternativeTitlesAppend + *TVChangesAppend + *TVContentRatingsAppend + *TVCreditsAppend + *TVEpisodeGroupsAppend + *TVExternalIDsAppend + *TVImagesAppend + *TVKeywordsAppend + *TVRecommendationsAppend + *TVReviewsAppend + *TVScreenedTheatricallyAppend + *TVSimilarAppend + *TVTranslationsAppend + *TVVideosAppend + *TVWatchProvidersAppend +} + +// TVAggregateCreditsAppend type is a struct +// for aggregate credits in append to response. +type TVAggregateCreditsAppend struct { + AggregateCredits TVAggregateCredits `json:"aggregate_credits"` +} + +// TVAlternativeTitlesAppend type is a struct +// for alternative titles in append to response. +type TVAlternativeTitlesAppend struct { + AlternativeTitles IDAlternativeTitleResults `json:"alternative_titles"` +} + +// TVChangesAppend type is a struct for changes in append to response. +type TVChangesAppend struct { + Changes Changes `json:"changes"` +} + +// TVContentRatingsAppend type is a struct for +// content ratings in append to response. +type TVContentRatingsAppend struct { + ContentRatings TVContentRatingsResults `json:"content_ratings"` +} + +// TVCreditsAppend type is a struct for credits in append to response. +type TVCreditsAppend struct { + Credits *TVCredits `json:"credits"` +} + +// TVEpisodeGroupsAppend type is a struct for +// episode groups in append to response. +type TVEpisodeGroupsAppend struct { + EpisodeGroups TVEpisodeGroupsResults `json:"episode_groups"` +} + +// TVExternalIDsAppend type is a short for +// external ids in append to response. +type TVExternalIDsAppend struct { + *TVExternalIDs `json:"external_ids"` +} + +// TVImagesAppend type is a struct for images in append to response. +type TVImagesAppend struct { + Images TVImages `json:"images"` +} + +// TVKeywordsAppend type is a struct for keywords in append to response. +type TVKeywordsAppend struct { + Keywords KeywordsResults `json:"keywords"` +} + +// TVRecommendationsAppend type is a struct +// for recommendations in append to response. +type TVRecommendationsAppend struct { + Recommendations PaginatedTVShowResults `json:"recommendations"` +} + +// TVReviewsAppend type is a struct for reviews in append to response. +type TVReviewsAppend struct { + Reviews PaginatedReviewsResults `json:"reviews"` +} + +// TVScreenedTheatricallyAppend type is a struct +// for screened theatrically in append to response. +type TVScreenedTheatricallyAppend struct { + ScreenedTheatrically *TVScreenedTheatrically `json:"screened_theatrically"` +} + +// TVSimilarAppend type is a struct for +// similar tv shows in append to response. +type TVSimilarAppend struct { + Similar *PaginatedTVShowResults `json:"similar"` +} + +// TVTranslationsAppend type is a struct +// for translations in append to response. +type TVTranslationsAppend struct { + Translations *TVTranslations `json:"translations"` +} + +// TVVideosAppend type is a struct for videos in append to response. +type TVVideosAppend struct { + Videos *VideoResults `json:"videos"` +} + +// TVWatchProvidersAppend type is a struct for +// watch/providers in append to response. +type TVWatchProvidersAppend struct { + WatchProviders IDWatchProviderResults `json:"watch/providers"` +} + +// TVAccountStates type is a struct for account states JSON response. +type TVAccountStates struct { + AccountStates +} + +// TVAggregateCredits type is a struct for aggregate credits JSON response. +type TVAggregateCredits struct { + Cast []CastCredit `json:"cast"` + Crew []CrewCredit `json:"crew"` +} + +type IDTVAggregateCredits struct { + ID int64 `json:"id"` + TVAggregateCredits +} + +// TVExternalIDs type is a struct for external ids JSON response. +type TVExternalIDs struct { + IMDbID string `json:"imdb_id"` + FreebaseMID string `json:"freebase_mid"` + FreebaseID string `json:"freebase_id"` + TVDBID int64 `json:"tvdb_id"` + TVRageID int64 `json:"tvrage_id"` + FacebookID string `json:"facebook_id"` + InstagramID string `json:"instagram_id"` + TwitterID string `json:"twitter_id"` + WikiDataID string `json:"wikidata_id"` + ID int64 `json:"id,omitempty"` +} + +// TVImages type is a struct for images JSON response. +type TVImages struct { + Backdrops []ImageIso `json:"backdrops"` + Logos []ImageIso `json:"logos"` + Posters []ImageIso `json:"posters"` +} + +type IDTVImages struct { + ID int64 `json:"id"` + TVImages +} + +// TVScreenedTheatrically type is a struct for screened theatrically JSON response. +type TVScreenedTheatrically struct { + ID int64 `json:"id"` + *TVScreenedTheatricallyResults +} + +type TVDataTranslation struct { + Name string `json:"name"` + Overview string `json:"overview"` + Homepage string `json:"homepage"` + Tagline string `json:"tagline"` +} + +type TVTranslation struct { + TranslationBase + Data TVDataTranslation `json:"data"` +} + +// TVTranslations type is a struct for translations JSON response. +type TVTranslations struct { + ID int64 `json:"id"` + Translations []TVTranslation `json:"translations"` +} diff --git a/types.go b/types.go index 5edd8aa..6eec2fc 100644 --- a/types.go +++ b/types.go @@ -1,5 +1,7 @@ package tmdb +import json "github.com/goccy/go-json" + // BelongsToCollection represents information about a collection to which a movie belongs, // including its unique identifier, name, poster image path, and backdrop image path. type BelongsToCollection struct { @@ -12,10 +14,7 @@ type BelongsToCollection struct { // ProductionCompany represents a company involved in the production of a movie or TV show. // It includes the company's name, unique identifier, logo path, and country of origin. type ProductionCompany struct { - Name string `json:"name"` - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - OriginCountry string `json:"origin_country"` + CompanyInfo } // Genre represents a movie or TV show genre with its unique identifier and name. @@ -33,30 +32,35 @@ type ProductionCountry struct { // SpokenLanguage represents a language spoken in a media item, including its ISO 639-1 code and name. type SpokenLanguage struct { - Iso639_1 string `json:"iso_639_1"` + EnglishName string `json:"english_name"` + Iso639_1 string `json:"iso_639_1"` + Name string `json:"name"` +} + +type CollectionTranslationData struct { + Title string `json:"title"` + Overview string `json:"overview"` + Homepage string `json:"homepage"` +} + +type CollectionTranslation struct { + TranslationBase + Data CollectionTranslationData `json:"data"` +} + +type TVEpisodeTranslationData struct { Name string `json:"name"` + Overview string `json:"overview"` } -// TranslationData represents the translated information for a media item, -// including its title, name, overview, homepage, runtime, and tagline. -// Fields are mapped to their respective JSON keys and may be omitted if empty. -type TranslationData struct { - Title string `json:"title,omitempty"` - Name string `json:"name,omitempty"` - Overview string `json:"overview,omitempty"` - Homepage string `json:"homepage,omitempty"` - Runtime *int `json:"runtime,omitempty"` - Tagline string `json:"tagline,omitempty"` +type TVEpisodeTranslation struct { + TranslationBase + Data TVEpisodeTranslationData `json:"data"` } -// Translation represents a translation entry with language and country codes, -// localized and English names, and associated translation data. -type Translation struct { - Iso3166_1 string `json:"iso_3166_1"` - Iso639_1 string `json:"iso_639_1"` - Name string `json:"name"` - EnglishName string `json:"english_name"` - Data TranslationData `json:"data"` +type TranslationBase struct { + Iso3166_1 string `json:"iso_3166_1"` + SpokenLanguage } // PaginatedResultsMeta represents metadata for paginated API responses, @@ -69,66 +73,27 @@ type PaginatedResultsMeta struct { // Season represents a TV show season with details such as air date, episode count, name, overview, poster path, season number, vote average, and associated show ID. type Season struct { - AirDate string `json:"air_date"` - EpisodeCount int `json:"episode_count"` ID int64 `json:"id"` Name string `json:"name"` Overview string `json:"overview"` PosterPath string `json:"poster_path"` + VoteAverage float32 `json:"vote_average"` + AirDate string `json:"air_date"` SeasonNumber int `json:"season_number"` - VoteAverage float32 `json:"vote_average,omitempty"` - ShowID int64 `json:"show_id,omitempty"` -} - -// LastEpisodeToAir represents the details of the most recently aired episode of a TV show. -// It includes information such as air date, episode and season numbers, production code, -// episode overview, voting statistics, and related media paths. -type LastEpisodeToAir struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode string `json:"production_code"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - VoteMetrics -} - -// NextEpisodeToAir represents the details of the next episode scheduled to air for a TV show. -// It includes information such as air date, episode and season numbers, show and episode IDs, -// episode name and overview, production code, still image path, and voting statistics. -type NextEpisodeToAir struct { - AirDate string `json:"air_date"` - EpisodeNumber int `json:"episode_number"` - ID int64 `json:"id"` - Name string `json:"name"` - Overview string `json:"overview"` - ProductionCode string `json:"production_code"` - SeasonNumber int `json:"season_number"` - ShowID int64 `json:"show_id"` - StillPath string `json:"still_path"` - VoteMetrics + EpisodeCount int `json:"episode_count"` } // Network represents a television network with its identifying information, // including name, unique ID, logo path, and country of origin. type Network struct { - Name string `json:"name"` - ID int64 `json:"id"` - LogoPath string `json:"logo_path"` - OriginCountry string `json:"origin_country"` + CompanyInfo } // CreatedBy represents a person who created a particular media item, such as a TV show or movie. // It includes identifying information such as ID, credit ID, name, gender, and profile image path. type CreatedBy struct { - ID int64 `json:"id"` - CreditID string `json:"credit_id"` - Name string `json:"name"` - Gender int `json:"gender"` - ProfilePath string `json:"profile_path"` + PersonBase + CreditID string `json:"credit_id"` } type VoteMetrics struct { @@ -144,15 +109,529 @@ type ImageBase struct { VoteMetrics } -type WatchProvider struct { +type ImageIso struct { + ImageBase + Iso639_1 string `json:"iso_639_1"` +} + +type WatchProviderBase struct { LogoPath string `json:"logo_path"` ProviderID int `json:"provider_id"` ProviderName string `json:"provider_name"` DisplayPriority int `json:"display_priority"` } +type MediaWatchProvider struct { + WatchProviderBase + DisplayPriorities map[string]int `json:"display_priorities"` +} + type AlternativeTitle struct { Iso3166_1 string `json:"iso_3166_1"` Title string `json:"title"` Type string `json:"type"` } + +type AlternativeName struct { + Name string `json:"name"` + Type string `json:"type"` +} + +type PersonBase struct { + ID int64 `json:"id"` + Name string `json:"name"` + OriginalName string `json:"original_name"` + Gender int `json:"gender"` + ProfilePath string `json:"profile_path"` +} + +type Person struct { + PersonBase + Adult bool `json:"adult"` + Popularity float32 `json:"popularity"` + KnownForDepartment string `json:"known_for_department"` +} + +type PersonMediaBase struct { + Person + MediaType MediaType `json:"media_type"` +} + +type PersonMedia struct { + PersonMediaBase + KnownFor []Media `json:"known_for"` +} + +type Media interface { + GetMediaType() MediaType +} + +func (movie MovieMedia) GetMediaType() MediaType { return movie.MediaType } +func (tv TVShowMedia) GetMediaType() MediaType { return tv.MediaType } +func (person PersonMedia) GetMediaType() MediaType { return person.MediaType } + +type CreditMedia interface { + GetMediaType() MediaType +} + +func (movie CreditMovieMedia) GetMediaType() MediaType { return movie.MediaType } +func (tv CreditTVShowMedia) GetMediaType() MediaType { return tv.MediaType } + +type CreditTVShowMedia struct { + TVShowMedia + Character string `json:"character"` + Episodes []TVEpisodeMedia `json:"episodes"` + Seasons []TVSeasonMedia `json:"seasons"` +} + +type CreditMovieMedia struct { + MovieMedia + Character string `json:"character"` +} + +type VideoBase struct { + Adult bool `json:"adult"` + BackdropPath string `json:"backdrop_path"` + ID int64 `json:"id"` + Overview string `json:"overview"` + PosterPath string `json:"poster_path"` + OriginalLanguage string `json:"original_language"` + Popularity float32 `json:"popularity"` + VoteMetrics +} + +type MovieMeta struct { + Title string `json:"title"` + OriginalTitle string `json:"original_title"` + ReleaseDate string `json:"release_date"` + Video bool `json:"video"` +} + +type Movie struct { + VideoBase + MovieMeta + GenreIDs []int64 `json:"genre_ids"` +} + +type MovieMedia struct { + Movie + MediaType MediaType `json:"media_type"` +} + +type MediaType string + +const ( + MediaTypeTV MediaType = "tv" + MediaTypeMovie MediaType = "movie" + MediaTypePerson MediaType = "person" +) + +type TVShowMeta struct { + Name string `json:"name"` + OriginalName string `json:"original_name"` + FirstAirDate string `json:"first_air_date"` + OriginCountry []string `json:"origin_country"` +} + +type TVShow struct { + VideoBase + TVShowMeta + GenreIDs []int64 `json:"genre_ids"` +} + +type TVShowRating struct { + TVShow + Rating +} + +type TVShowMedia struct { + TVShow + MediaType MediaType `json:"media_type"` +} + +type VideoDetails struct { + VideoBase + Genres []Genre `json:"genres"` + Homepage string `json:"homepage"` + ProductionCompanies []ProductionCompany `json:"production_companies"` + ProductionCountries []ProductionCountry `json:"production_countries"` + SpokenLanguages []SpokenLanguage `json:"spoken_languages"` + Status string `json:"status"` + Tagline string `json:"tagline"` +} + +type TVEpisode struct { + ScreenedTheatrically + Name string `json:"name"` + Overview string `json:"overview"` + AirDate string `json:"air_date"` + EpisodeType string `json:"episode_type"` + ProductionCode string `json:"production_code"` + Runtime *int `json:"runtime"` + ShowID int64 `json:"show_id"` + StillPath *string `json:"still_path"` + VoteMetrics +} + +type TVEpisodeMedia struct { + TVEpisode + MediaType MediaType `json:"media_type"` +} + +type TVSeason struct { + AirDate string `json:"air_date"` + ID int64 `json:"id"` + Name string `json:"name"` + Overview string `json:"overview"` + PosterPath string `json:"poster_path"` + SeasonNumber int `json:"season_number"` + VoteAverage float32 `json:"vote_average"` +} + +type TVSeasonMedia struct { + TVSeason + EpisodeCount int `json:"episode_count"` + MediaType MediaType `json:"media_type"` + ShowID int64 `json:"show_id"` +} + +type PersonCredit struct { + Person + CreditID string `json:"credit_id"` +} + +type Crew struct { + PersonCredit + Department string `json:"department"` + Job string `json:"job"` +} + +type CastBase struct { + PersonCredit + Character string `json:"character"` + Order int `json:"order"` +} + +type Cast struct { + CastBase + CastID int `json:"cast_id"` +} + +type PeopleMovieCreditCast struct { + Adult bool `json:"adult"` + BackdropPath string `json:"backdrop_path"` + GenreIDs []int64 `json:"genre_ids"` + ID int64 `json:"id"` + OriginalLanguage string `json:"original_language"` + OriginalTitle string `json:"original_title"` + Overview string `json:"overview"` + Popularity float32 `json:"popularity"` + PosterPath string `json:"poster_path"` + ReleaseDate string `json:"release_date"` + Title string `json:"title"` + Video bool `json:"video"` + VoteMetrics + Character string `json:"character"` + CreditID string `json:"credit_id"` + Order int `json:"order"` +} + +type PeopleMovieCreditCrew struct { + Adult bool `json:"adult"` + BackdropPath string `json:"backdrop_path"` + GenreIDs []int64 `json:"genre_ids"` + ID int64 `json:"id"` + OriginalLanguage string `json:"original_language"` + OriginalTitle string `json:"original_title"` + Overview string `json:"overview"` + Popularity float32 `json:"popularity"` + PosterPath string `json:"poster_path"` + ReleaseDate string `json:"release_date"` + Title string `json:"title"` + Video bool `json:"video"` + CreditID string `json:"credit_id"` + Department string `json:"department"` + Job string `json:"job"` + VoteMetrics +} + +type PeopleTVCreditCrew struct { + ID int64 `json:"id"` + Department string `json:"department"` + OriginalLanguage string `json:"original_language"` + EpisodeCount int `json:"episode_count"` + Job string `json:"job"` + Overview string `json:"overview"` + OriginCountry []string `json:"origin_country"` + OriginalName string `json:"original_name"` + GenreIDs []int64 `json:"genre_ids"` + Name string `json:"name"` + FirstAirDate string `json:"first_air_date"` + BackdropPath string `json:"backdrop_path"` + Popularity float32 `json:"popularity"` + PosterPath string `json:"poster_path"` + CreditID string `json:"credit_id"` + VoteMetrics +} +type PeopleTVCreditCast struct { + CreditID string `json:"credit_id"` + OriginalName string `json:"original_name"` + ID int64 `json:"id"` + GenreIDs []int64 `json:"genre_ids"` + Character string `json:"character"` + Name string `json:"name"` + PosterPath string `json:"poster_path"` + Popularity float32 `json:"popularity"` + EpisodeCount int `json:"episode_count"` + OriginalLanguage string `json:"original_language"` + FirstAirDate string `json:"first_air_date"` + BackdropPath string `json:"backdrop_path"` + Overview string `json:"overview"` + OriginCountry []string `json:"origin_country"` + VoteMetrics +} + +type TVEpisodeDetailsBase struct { + TVEpisode + Crew []Crew `json:"crew"` + GuestStars []CastBase `json:"guest_stars"` +} + +type CompanyInfo struct { + Name string `json:"name"` + ID int64 `json:"id"` + LogoPath string `json:"logo_path"` + OriginCountry string `json:"origin_country"` +} + +type Job struct { + CreditID string `json:"credit_id"` + Job string `json:"job"` + EpisodeCount int `json:"episode_count"` +} + +type Role struct { + CreditID string `json:"credit_id"` + Character string `json:"character"` + EpisodeCount int `json:"episode_count"` +} + +type Jobs struct { + Department string `json:"department"` + Jobs []string `json:"jobs"` +} + +type JobsDetails struct { + Department string `json:"department"` + Jobs []Job `json:"jobs"` +} + +type CrewCredit struct { + Person + JobsDetails + TotalEpisodeCount int `json:"total_episode_count"` +} + +type CastCredit struct { + Person + Order int `json:"order"` + Roles []Role `json:"roles"` + TotalEpisodeCount int `json:"total_episode_count"` +} + +type Change struct { + Key string `json:"key"` + Items []ChangeItem `json:"items"` +} + +type Changes struct { + Changes []Change `json:"changes"` +} + +type ChangeItem struct { + ID string `json:"id"` + Action string `json:"action"` + Time string `json:"time"` + Iso639_1 string `json:"iso_639_1"` + Iso3166_1 string `json:"iso_3166_1"` + Value *json.RawMessage `json:"value"` + OriginalValue *json.RawMessage `json:"original_value"` +} + +type ContentRatings struct { + Descriptors []any `json:"descriptors"` + Iso3166_1 string `json:"iso_3166_1"` + Rating string `json:"rating"` +} + +type TVEpisodeGroup struct { + Description string `json:"description"` + EpisodeCount int `json:"episode_count"` + GroupCount int `json:"group_count"` + ID string `json:"id"` + Name string `json:"name"` + Network Network `json:"network"` + Type int `json:"type"` +} + +type TVEpisodeOrder struct { + TVEpisode + Order int `json:"order"` +} + +type Group struct { + ID string `json:"id"` + Name string `json:"name"` + Order int `json:"order"` + Episodes []TVEpisodeOrder `json:"episodes"` + Locked bool `json:"locked"` +} + +type Review struct { + Author string `json:"author"` + AuthorDetails Author `json:"author_details"` + Content string `json:"content"` + CreatedAt string `json:"created_at"` + ID string `json:"id"` + UpdatedAt string `json:"updated_at"` + URL string `json:"url"` +} + +type Author struct { + Name string `json:"name"` + Username string `json:"username"` + AvatarPath string `json:"avatar_path"` + Rating float32 `json:"rating"` +} + +type ScreenedTheatrically struct { + ID int64 `json:"id"` + EpisodeNumber int `json:"episode_number"` + SeasonNumber int `json:"season_number"` +} + +type List struct { + Description string `json:"description"` + FavoriteCount int64 `json:"favorite_count"` + ID int64 `json:"id"` + ItemCount int64 `json:"item_count"` + Iso639_1 string `json:"iso_639_1"` + ListType string `json:"list_type"` + Name string `json:"name"` + PosterPath *string `json:"poster_path"` +} + +type MovieList struct { + List + Iso3166_1 string `json:"iso_3166_1"` +} + +type Country struct { + Iso3166_1 string `json:"iso_3166_1"` + EnglishName string `json:"english_name"` + NativeName string `json:"native_name"` +} + +type ReleaseType int + +const ( + ReleaseTypePremiere ReleaseType = iota + 1 + ReleaseTypeTheatricalLimited + ReleaseTypeTheatrical + ReleaseTypeDigital + ReleaseTypePhysical + ReleaseTypeTV +) + +type ReleaseDate struct { + Certification string `json:"certification"` + Descriptors []any `json:"descriptors"` + Iso639_1 string `json:"iso_639_1"` + Note string `json:"note"` + ReleaseDate string `json:"release_date"` + Type ReleaseType `json:"type"` +} + +type MovieReleaseDate struct { + Iso3166_1 string `json:"iso_3166_1"` + ReleaseDates []ReleaseDate `json:"release_dates"` +} + +type AccountStates struct { + ID int64 `json:"id"` + Favorite bool `json:"favorite"` + Rated json.RawMessage `json:"rated"` + Watchlist bool `json:"watchlist"` +} + +type PersonTaggedImage struct { + ImageIso + ID string `json:"id"` + ImageType string `json:"image_type"` + Media Media `json:"media"` +} + +type Rating struct { + Rating float32 `json:"rating"` +} + +type TVEpisodeRating struct { + TVEpisode + Rating +} + +type MovieRating struct { + Movie + Rating +} + +type Collection struct { + Adult bool `json:"adult"` + BackdropPath string `json:"backdrop_path"` + ID int64 `json:"id"` + Name string `json:"name"` + OriginalLanguage string `json:"original_language"` + OriginalName string `json:"original_name"` + Overview string `json:"overview"` + PosterPath string `json:"poster_path"` +} + +// Keyword type is a struct for keyword JSON response. +type Keyword struct { + ID int64 `json:"id"` + Name string `json:"name"` +} + +type GroupType int + +const ( + GroupTypeOriginalAirDate GroupType = iota + 1 + GroupTypeAbsolute + GroupTypeDVD + GroupTypeDigital + GroupTypeStoryARC + GroupTypeProduction + GroupTypeTV +) + +type TVCredits struct { + Cast []CastBase `json:"cast"` + Crew []Crew `json:"crew"` + ID int64 `json:"id"` +} + +// MovieCredits type is a struct for credits JSON response. +type MovieCredits struct { + ID int64 `json:"id"` + Cast []Cast `json:"cast"` + Crew []Crew `json:"crew"` +} + +type IDKeywordsList struct { + ID int64 `json:"id"` + KeywordsList +} + +type KeywordsList struct { + Keywords []Keyword `json:"keywords"` +} diff --git a/unmarshal.go b/unmarshal.go new file mode 100644 index 0000000..df9c196 --- /dev/null +++ b/unmarshal.go @@ -0,0 +1,129 @@ +package tmdb + +import ( + "fmt" + + json "github.com/goccy/go-json" +) + +func (c *CreditsDetails) UnmarshalJSON(data []byte) error { + type alias CreditsDetails + var raw struct { + alias + Media json.RawMessage `json:"media"` + } + if err := json.Unmarshal(data, &raw); err != nil { + return err + } + *c = CreditsDetails(raw.alias) + var mediaType struct { + MediaType MediaType `json:"media_type"` + } + if err := json.Unmarshal(raw.Media, &mediaType); err != nil { + return err + } + + switch mediaType.MediaType { + case MediaTypeMovie: + var movie CreditMovieMedia + if err := json.Unmarshal(raw.Media, &movie); err != nil { + return err + } + c.Media = movie + case MediaTypeTV: + var tv CreditTVShowMedia + if err := json.Unmarshal(raw.Media, &tv); err != nil { + return err + } + c.Media = tv + default: + return fmt.Errorf("unknown media_type: %s", mediaType.MediaType) + } + return nil +} + +func (p *PersonMedia) UnmarshalJSON(data []byte) error { + type alias PersonMedia + var raw struct { + alias + KnownFor []json.RawMessage `json:"known_for"` + } + if err := json.Unmarshal(data, &raw); err != nil { + return err + } + *p = PersonMedia(raw.alias) + return unmarshalMediaList(raw.KnownFor, func(m Media) { + p.KnownFor = append(p.KnownFor, m) + }) +} + +func (pti *PersonTaggedImage) UnmarshalJSON(data []byte) error { + type alias PersonTaggedImage + var raw struct { + alias + Media json.RawMessage `json:"media"` + } + if err := json.Unmarshal(data, &raw); err != nil { + return err + } + *pti = PersonTaggedImage(raw.alias) + return unmarshalMedia(raw.Media, func(m Media) { + pti.Media = m + }) +} + +func (pmr *PaginatedMediaResults) UnmarshalJSON(data []byte) error { + type alias PaginatedMediaResults + var raw struct { + alias + Results []json.RawMessage `json:"results"` + } + if err := json.Unmarshal(data, &raw); err != nil { + return err + } + *pmr = PaginatedMediaResults(raw.alias) + return unmarshalMediaList(raw.Results, func(m Media) { + pmr.Results = append(pmr.Results, m) + }) +} + +func unmarshalMedia(item json.RawMessage, handleMedia func(Media)) error { + var mediaType struct { + MediaType MediaType `json:"media_type"` + } + if err := json.Unmarshal(item, &mediaType); err != nil { + return err + } + switch mediaType.MediaType { + case MediaTypeMovie: + var movie MovieMedia + if err := json.Unmarshal(item, &movie); err != nil { + return err + } + handleMedia(movie) + case MediaTypeTV: + var tv TVShowMedia + if err := json.Unmarshal(item, &tv); err != nil { + return err + } + handleMedia(tv) + case MediaTypePerson: + var person PersonMedia + if err := json.Unmarshal(item, &person); err != nil { + return err + } + handleMedia(person) + default: + return fmt.Errorf("unknown media_type: %s", mediaType.MediaType) + } + return nil +} + +func unmarshalMediaList(rawItems []json.RawMessage, handleMedia func(Media)) error { + for _, item := range rawItems { + if err := unmarshalMedia(item, handleMedia); err != nil { + return err + } + } + return nil +} diff --git a/unmarshal_test.go b/unmarshal_test.go new file mode 100644 index 0000000..a1ad9ce --- /dev/null +++ b/unmarshal_test.go @@ -0,0 +1,222 @@ +package tmdb + +import json "github.com/goccy/go-json" + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsMovieMediaType() { + jsonData := `{ + "media": { + "title": "Title", + "media_type": "movie" + } +}` + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Nil(err) + media := cd.Media + suite.NotNil(media) + suite.Equal(MediaTypeMovie, media.GetMediaType()) +} + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsMovieMediaTypeFail() { + jsonData := `{ + "media": { + "title": ["Name"], + "media_type": "movie" + } +}` + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsTVMediaType() { + jsonData := `{ + "media": { + "name": "Name", + "media_type": "tv" + } +}` + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Nil(err) + media := cd.Media + suite.NotNil(media) + suite.Equal(MediaTypeTV, media.GetMediaType()) +} + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsTVMediaTypeFail() { + jsonData := `{ + "media": { + "name": ["Name"], + "media_type": "tv" + } +}` + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsUnknownMediaType() { + jsonData := `{ + "media": { + "media_type": "unknown" + } +}` + + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Error(err) + suite.Contains(err.Error(), "unknown media_type") +} + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsInvalidMediaType() { + jsonData := `{ + "media": { + media_type: [] + } +}` + + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalCreditsDetailsInvalidMedia() { + jsonData := `{invalid_data}` + + var cd CreditsDetails + err := json.Unmarshal([]byte(jsonData), &cd) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonInvalidResult() { + jsonData := `{invalid_data}` + + var t PersonMedia + err := json.Unmarshal([]byte(jsonData), &t) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPaginatedMediaResultsInvalidResult() { + jsonData := `{invalid_data}` + + var pmr PaginatedMediaResults + err := json.Unmarshal([]byte(jsonData), &pmr) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonTaggedImageInvalidResult() { + jsonData := `{invalid_data}` + + var t PersonTaggedImage + err := json.Unmarshal([]byte(jsonData), &t) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonMediaInvalidMediaType() { + jsonData := `{ + "known_for": [ + { + media_type: [] + } + ] +}` + + var pr PersonMedia + err := json.Unmarshal([]byte(jsonData), &pr) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonMediaUnknownMediaType() { + jsonData := `{ + "known_for": [ + { + "media_type": "unknown" + } + ] +}` + + var pr PersonMedia + err := json.Unmarshal([]byte(jsonData), &pr) + suite.Error(err) + suite.Contains(err.Error(), "unknown media_type") +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonMediaMovieMediaTypeFail() { + jsonData := `{ + "known_for": [ + { + "title": [ + "Title" + ], + "media_type": "movie" + } + ] +}` + + var pr PersonMedia + err := json.Unmarshal([]byte(jsonData), &pr) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonMediaTVMediaTypeFail() { + jsonData := `{ + "known_for": [ + { + "name": [ + "Name" + ], + "media_type": "tv" + } + ] +}` + + var pr PersonMedia + err := json.Unmarshal([]byte(jsonData), &pr) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonMediaPersonMediaTypeFail() { + jsonData := `{ + "known_for": [ + { + "name": [ + "Name" + ], + "media_type": "person" + } + ] +}` + + var pr PersonMedia + err := json.Unmarshal([]byte(jsonData), &pr) + suite.Error(err) +} + +func (suite *TMBDTestSuite) TestUnmarshalPersonMediaMediaType() { + jsonData := `{ + "known_for": [ + { + "name": "Name", + "media_type": "tv" + }, + { + "title": "Title", + "media_type": "movie" + }, + { + "name": "Name", + "media_type": "person" + } + ] +}` + + var pr PersonMedia + err := json.Unmarshal([]byte(jsonData), &pr) + suite.Nil(err) + knownFor := pr.KnownFor + suite.NotNil(knownFor) + suite.Equal(MediaTypeTV, knownFor[0].GetMediaType()) + suite.Equal(MediaTypeMovie, knownFor[1].GetMediaType()) + suite.Equal(MediaTypePerson, knownFor[2].GetMediaType()) +} diff --git a/providers.go b/watch_providers.go similarity index 58% rename from providers.go rename to watch_providers.go index e6c7218..75aa9c3 100644 --- a/providers.go +++ b/watch_providers.go @@ -3,33 +3,13 @@ package tmdb import "fmt" // WatchRegionList type is a struct for watch region list JSON response. -type WatchRegionList struct { - Regions []struct { - Iso3166_1 string `json:"iso_3166_1"` - EnglishName string `json:"english_name"` - NativeName string `json:"native_name"` - } `json:"results"` -} - -// WatchProviderList type is a struct for watch provider list JSON response. -type WatchProviderList struct { - Providers []struct { - ID int64 `json:"id"` - Name string `json:"name"` - DisplayPriorities map[string]int `json:"display_priorities"` - DisplayPriority int64 `json:"display_priority"` - LogoPath string `json:"logo_path"` - ProviderName string `json:"provider_name"` - ProviderID int `json:"provider_id"` - } `json:"results"` -} // GetAvailableWatchProviderRegions get a list of all of the countries we have watch provider (OTT/streaming) data for. // -// https://developers.themoviedb.org/3/watch-providers/get-available-regions +// https://developer.themoviedb.org/reference/watch-providers-available-regions func (c *Client) GetAvailableWatchProviderRegions( urlOptions map[string]string, -) (*WatchRegionList, error) { +) (*CountryWatchProviderResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%sregions?api_key=%s%s", @@ -38,7 +18,7 @@ func (c *Client) GetAvailableWatchProviderRegions( c.apiKey, options, ) - watchRegionList := WatchRegionList{} + watchRegionList := CountryWatchProviderResults{} if err := c.get(tmdbURL, &watchRegionList); err != nil { return nil, err } @@ -48,10 +28,10 @@ func (c *Client) GetAvailableWatchProviderRegions( // GetWatchProvidersMovie get a list of the watch provider (OTT/streaming) data we have available for movies. // You can specify a watch_region param if you want to further filter the list by country. // -// https://developers.themoviedb.org/3/watch-providers/get-movie-providers +// https://developer.themoviedb.org/reference/watch-providers-movie-list func (c *Client) GetWatchProvidersMovie( urlOptions map[string]string, -) (*WatchProviderList, error) { +) (*MediaWatchProviderResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%smovie?api_key=%s%s", @@ -60,7 +40,7 @@ func (c *Client) GetWatchProvidersMovie( c.apiKey, options, ) - watchProvider := WatchProviderList{} + watchProvider := MediaWatchProviderResults{} if err := c.get(tmdbURL, &watchProvider); err != nil { return nil, err } @@ -70,10 +50,10 @@ func (c *Client) GetWatchProvidersMovie( // GetWatchProvidersTv get a list of the watch provider (OTT/streaming) data we have available for TV series. // You can specify a watch_region param if you want to further filter the list by country. // -// https://developers.themoviedb.org/3/watch-providers/get-tv-providers +// https://developer.themoviedb.org/reference/watch-provider-tv-list func (c *Client) GetWatchProvidersTv( urlOptions map[string]string, -) (*WatchProviderList, error) { +) (*MediaWatchProviderResults, error) { options := c.fmtOptions(urlOptions) tmdbURL := fmt.Sprintf( "%s%stv?api_key=%s%s", @@ -82,7 +62,7 @@ func (c *Client) GetWatchProvidersTv( c.apiKey, options, ) - watchProvider := WatchProviderList{} + watchProvider := MediaWatchProviderResults{} if err := c.get(tmdbURL, &watchProvider); err != nil { return nil, err } diff --git a/providers_test.go b/watch_providers_test.go similarity index 100% rename from providers_test.go rename to watch_providers_test.go