Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

This is a Golang wrapper for working with TMDb API. It aims to support version 3.

License

NotificationsYou must be signed in to change notification settings

cyruzin/golang-tmdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buildCoverage StatusGo Report CardGoDocGitHub tag (latest SemVer)GitHub license

This is a Golang wrapper for working with TMDb API.

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

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

Requirements

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

Installation

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

Usage

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

import"github.com/cyruzin/golang-tmdb"tmdbClient,err:=tmdb.Init(os.Getenv("YOUR_APIKEY"))iferr!=nil {fmt.Println(err)}// Using v4tmdbClient,err:=tmdb.InitV4(os.Getenv("YOUR_BEARER_TOKEN"))iferr!=nil {fmt.Println(err)}// OPTIONAL (Recommended): Enabling auto retry functionality.// This option will retry if the previous request fail (429 TOO MANY REQUESTS).tmdbClient.SetClientAutoRetry()// OPTIONAL: Set an alternate base URL if you have problems with the default one.// Use https://api.tmdb.org/3 instead of https://api.themoviedb.org/3.tmdbClient.SetAlternateBaseURL()// OPTIONAL: For tests, set a custom base URLtmdbClient.SetCustomBaseURL("http://localhost:3000")// Get the current base URLtmdbClient.GetBaseURL()// OPTIONAL: Setting a custom config for the http.Client.// The default timeout is 10 seconds. Here you can set other// options like Timeout and Transport.customClient:= http.Client{Timeout:time.Second*5,Transport:&http.Transport{MaxIdleConns:10,IdleConnTimeout:15*time.Second,    },}tmdbClient.SetClientConfig(customClient)// OPTIONAL: Enable this option if you're going to use endpoints// that needs session id.//// You can read more about how this works:// https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-idtmdbClient.SetSessionID(os.Getenv("YOUR_SESSION_ID"))movie,err:=tmdbClient.GetMovieDetails(297802,nil)iferr!=nil {fmt.Println(err)}fmt.Println(movie.Title)

With optional params:

import"github.com/cyruzin/golang-tmdb"tmdbClient,err:=tmdb.Init(os.Getenv("YOUR_APIKEY"))iferr!=nil {fmt.Println(err)}// Using v4tmdbClient,err:=tmdb.InitV4(os.Getenv("YOUR_BEARER_TOKEN"))iferr!=nil {fmt.Println(err)}options:=map[string]string{"language":"pt-BR","append_to_response":"credits,images",}movie,err:=tmdbClient.GetMovieDetails(297802,options)iferr!=nil {fmt.Println(err)}fmt.Println(movie.Title)

Helpers:

Generate image and video URLs:

import"github.com/cyruzin/golang-tmdb"tmdbClient,err:=tmdb.Init(os.Getenv("YOUR_APIKEY"))iferr!=nil {fmt.Println(err)}options:=map[string]string{"append_to_response":"videos",}movie,err:=tmdbClient.GetMovieDetails(297802,options)iferr!=nil {fmt.Println(err)}fmt.Println(tmdb.GetImageURL(movie.BackdropPath,tmdb.W500))// Output: https://image.tmdb.org/t/p/w500/bOGkgRGdhrBYJSLpXaxhXVstddV.jpgfmt.Println(tmdb.GetImageURL(movie.PosterPath,tmdb.Original))// Ouput: https://image.tmdb.org/t/p/original/bOGkgRGdhrBYJSLpXaxhXVstddV.jpgfor_,video:=rangemovie.MovieVideosAppend.Videos.MovieVideos.Results {ifvideo.Key!="" {fmt.Println(tmdb.GetVideoURL(video.Key))// Output: https://www.youtube.com/watch?v=6ZfuNTqbHE8   }}

For more examples,click here.

Performance

Getting Movie Details:

Iterationsns/opB/opallocs/op
196088664860632184

Multi Search:

Iterationsns/opB/opallocs/op
1666596963107109608

Contributing

To start contributing, please checkCONTRIBUTING.

Tests

For local testing, just run:

gotest-v

License

MIT

About

This is a Golang wrapper for working with TMDb API. It aims to support version 3.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp