tmdbapi

package
v0.0.0-...-b4bf89c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tmdbapi defines the service used for interacting with the TMDB API for retrieving movie data.

Index

Constants

This section is empty.

Variables

View Source
var GenreMap = map[int]string{
	28:    "Action",
	12:    "Adventure",
	16:    "Animation",
	35:    "Comedy",
	80:    "Crime",
	99:    "Documentary",
	18:    "Drama",
	10751: "Family",
	14:    "Fantasy",
	36:    "History",
	27:    "Horror",
	10402: "Music",
	9648:  "Mystery",
	10749: "Romance",
	878:   "Science Fiction",
	10770: "TV Movie",
	53:    "Thriller",
	10752: "War",
	37:    "Western",
}

GenreMap maps from genre ID to genre name. This was hard-coded based on a call to the TMDB movie genre list endpoint (https://developer.themoviedb.org/reference/genre-movie-list)

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks if the error returned form a TMDB API call is a "not found" error

Types

type MovieCast

type MovieCast struct {
	ID           int     `json:"id"`
	Name         string  `json:"name"`
	OriginalName string  `json:"original_name"`
	Popularity   float64 `json:"popularity"`
	ProfilePath  string  `json:"profile_path"`
	CastID       int     `json:"cast_id"`
	Character    string  `json:"character"`
	CreditID     string  `json:"credit_id"`
	Order        int     `json:"order"`
}

MovieCast represents data for a single cast as received from the TMDB API

type MovieCredits

type MovieCredits struct {
	ID   int         `json:"id"`
	Cast []MovieCast `json:"cast"`
}

MovieCredits represents the cast data received from the TMDB API

type MovieDetails

type MovieDetails struct {
	// Adult               bool   `json:"adult"`
	// BackdropPath        string `json:"backdrop_path"`
	// BelongsToCollection any    `json:"belongs_to_collection"`
	// Budget              int    `json:"budget"`
	ID          int     `json:"id"`
	ImdbID      string  `json:"imdb_id"`
	Overview    string  `json:"overview"`
	Popularity  float64 `json:"popularity"`
	PosterPath  string  `json:"poster_path"`
	ReleaseDate string  `json:"release_date"`
	Revenue     int     `json:"revenue"`
	Runtime     int     `json:"runtime"`
	Tagline     string  `json:"tagline"`
	Title       string  `json:"title"`
	Video       bool    `json:"video"`
	Genres      []struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	} `json:"genres"`
}

MovieDetails matches the JSON response coming from a call to the Movie Details API endpoint

type NowPlayingMovie

type NowPlayingMovie struct {
	ID          int     `json:"id"`
	Popularity  float64 `json:"popularity"`
	PosterPath  string  `json:"poster_path"`
	ReleaseDate string  `json:"release_date"`
	Title       string  `json:"title"`
	Overview    string  `json:"overview"`
	GenreIDs    []int   `json:"genre_ids"`
}

NowPlayingMovie matches the JSON structure of a single movie in a NowPlayingRes struct

type NowPlayingRes

type NowPlayingRes struct {
	Page         int               `json:"page"`
	Results      []NowPlayingMovie `json:"results"`
	TotalPages   int               `json:"total_pages"`
	TotalResults int               `json:"total_results"`
}

NowPlayingRes matches the JSON response coming from a call to the Now Playing API

type Review

type Review struct {
	database.GetReviewsRow
	Title      string
	PosterPath string
}

Review is a type that extends the DB review data by adding the external TMDB API data needed before rendering.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds the functions needed to consume the TMDB API. Fields should be private to prevent access by other services.

func NewService

func NewService(tmdbToken string) *Service

NewService is the constructor function for creating the TMDB API service.

func (*Service) GetMovieCast

func (s *Service) GetMovieCast(movieID string) ([]MovieCast, error)

GetMovieCast makes the call to the Movie Credits API

func (*Service) GetMovieDetails

func (s *Service) GetMovieDetails(movieID string) (MovieDetails, error)

GetMovieDetails makes the call to the Movie Details API

func (*Service) GetNowPlaying

func (s *Service) GetNowPlaying(n int) ([]NowPlayingMovie, error)

GetNowPlaying makes the call to the Now Playing API endpoint and sorts them by descending popularity

func (*Service) GetReviewMovieDetails

func (s *Service) GetReviewMovieDetails(reviews []database.GetReviewsRow) []Review

GetReviewMovieDetails takes a slice of DB reviews and attached the TMDB data to them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL