No description
  • Go 99.9%
  • Pkl 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Tim Hårek Andreassen 0e5a08ae23
Some checks failed
ci / check (push) Failing after 10s
Decide not-found on the status, not on the body
2026-09-16 11:49:39 +02:00
.forgejo/workflows ci: Replace the GitHub workflows with Forgejo Actions 2026-09-16 09:54:43 +02:00
img Logo resized 2019-01-26 15:29:37 -03:00
.gitignore Improved testing (#85) 2025-07-08 16:43:33 -03:00
.golangci.toml make: Use tools 2026-01-15 14:47:50 +01:00
account.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
account_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
authentication.go refactor: Make [Client.request] more type-safe 2026-01-15 13:51:44 +01:00
authentication_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
certifications.go refactor: Make [Client.request] more type-safe 2026-01-15 13:51:44 +01:00
certifications_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
changes.go refactor: Make [Client.request] more type-safe 2026-01-15 13:51:44 +01:00
changes_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2019-06-29 12:53:53 -03:00
collections.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
collections_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
companies.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
companies_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
configuration.go refactor: Make [Client.request] more type-safe 2026-01-15 13:51:44 +01:00
configuration_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
CONTRIBUTING.md ci: Replace the GitHub workflows with Forgejo Actions 2026-09-16 09:54:43 +02:00
credits.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
credits_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
discover.go refactor: Make [Client.request] more type-safe 2026-01-15 13:51:44 +01:00
discover_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
errors.go Report a missing title as ErrNotFound 2026-09-16 11:43:09 +02:00
find.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
find_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
genres.go refactor: Make [Client.request] more type-safe 2026-01-15 13:51:44 +01:00
genres_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
go.mod remove examples and set the real name 2026-09-16 10:29:53 +02:00
go.sum remove examples and set the real name 2026-09-16 10:29:53 +02:00
guest_sessions.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
guest_sessions_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
helpers.go Added enum for images. Closes #20 2020-12-15 10:05:09 -03:00
helpers_test.go Added enum for images. Closes #20 2020-12-15 10:05:09 -03:00
hk.pkl build: Pin golangci-lint with mise and use the hk builtin 2026-09-16 09:49:34 +02:00
keywords.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
keywords_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
LICENSE Initial commit 2019-01-11 19:59:33 -03:00
list.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
list_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
mise.toml test: Run the live API tests only when not short 2026-09-16 10:55:50 +02:00
movies.go Name the cast and crew members 2026-09-16 11:45:49 +02:00
movies_test.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
networks.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
networks_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
people.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
people_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
providers.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
providers_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
README.md test: Run the live API tests only when not short 2026-09-16 10:55:50 +02:00
results.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
reviews.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
reviews_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
search.go fix(search): Escape the query once, not twice 2026-09-16 10:24:02 +02:00
search_test.go test: Run the live API tests only when not short 2026-09-16 10:55:50 +02:00
tmdb.go Decide not-found on the status, not on the body 2026-09-16 11:49:39 +02:00
tmdb_test.go Report a missing title as ErrNotFound 2026-09-16 11:43:09 +02:00
trending.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
trending_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
tv.go Name the cast and crew members 2026-09-16 11:45:49 +02:00
tv_episode_groups.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
tv_episode_groups_test.go refactor: Make [Client.get] more type-safe 2026-01-15 13:26:21 +01:00
tv_episodes.go go fix 2026-09-16 10:04:58 +02:00
tv_episodes_test.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
tv_seasons.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
tv_seasons_test.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
tv_test.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00
types.go fix: Remove mix of int64 and int 2026-01-15 15:38:25 +01:00

Go Report Card GoDoc

This is a Golang wrapper around the TMDb API, forked from cyruzin/golang-tmdb.

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

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

Fork

This is a fork of cyruzin/golang-tmdb. It is a drop-in replacement: the client is built with functional options (tmdb.New(tmdb.WithAPIKey(...))) instead of the Init and InitV4 constructors, and the request path retries 429s with tmdb.WithAutoRetry(). Endpoint methods and their signatures are unchanged.

It has its own module path, so it is a plain dependency rather than something a replace points at:

go get src.timharek.no/tim/tmdb-go
import tmdb "src.timharek.no/tim/tmdb-go"

Coming from upstream, the import path is the only thing that changes.

If your code calls Init or InitV4, switch to the equivalent option:

-tmdbClient, err := tmdb.Init(os.Getenv("YOUR_APIKEY"))
+tmdbClient, err := tmdb.New(tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")))

-tmdbClient, err := tmdb.InitV4(os.Getenv("YOUR_BEARER_TOKEN"))
+tmdbClient, err := tmdb.New(tmdb.WithBearerToken(os.Getenv("YOUR_BEARER_TOKEN")))

Requirements

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

Installation

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

See Fork above for using this fork instead of upstream.

Usage

To get started, create a new client. The import is github.com/cyruzin/golang-tmdb in both cases — with upstream it resolves to the upstream module, with this fork it resolves through the replace:

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

// With API key (v3 authentication)
tmdbClient, err := tmdb.New(tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")))
if err != nil {
    fmt.Println(err)
}

// With bearer token (v4 authentication)
tmdbClient, err := tmdb.New(tmdb.WithBearerToken(os.Getenv("YOUR_BEARER_TOKEN")))
if err != nil {
    fmt.Println(err)
}

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

fmt.Println(movie.Title)

Client Options

The client supports functional options for configuration:

// Auto retry on rate limit (429 TOO MANY REQUESTS)
tmdbClient, err := tmdb.New(
    tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")),
    tmdb.WithAutoRetry(),
)

// Custom timeout (default is 10 seconds)
tmdbClient, err := tmdb.New(
    tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")),
    tmdb.WithTimeout(time.Second * 5),
)

// Alternate base URL (https://api.tmdb.org/3 instead of https://api.themoviedb.org/3)
tmdbClient, err := tmdb.New(
    tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")),
    tmdb.WithAlternateBaseURL(),
)

// Custom base URL (useful for testing)
tmdbClient, err := tmdb.New(
    tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")),
    tmdb.WithCustomBaseURL("http://localhost:3000"),
)

// Custom http.Client configuration
customClient := http.Client{
    Timeout: time.Second * 5,
    Transport: &http.Transport{
        MaxIdleConns:    10,
        IdleConnTimeout: 15 * time.Second,
    },
}
tmdbClient, err := tmdb.New(
    tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")),
    tmdb.WithHTTPClient(customClient),
)

// Session ID for authenticated endpoints
// https://developers.themoviedb.org/3/authentication/how-do-i-generate-a-session-id
tmdbClient, err := tmdb.New(
    tmdb.WithAPIKey(os.Getenv("YOUR_APIKEY")),
    tmdb.WithSessionID(os.Getenv("YOUR_SESSION_ID")),
)

Request Options

Pass optional parameters to endpoints:

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

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

fmt.Println(movie.Title)

Helpers

Generate image and video URLs:

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

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

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

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

For more examples, see the examples directory.

Performance

Getting Movie Details:

Iterations ns/op B/op allocs/op
19 60886648 60632 184

Multi Search:

Iterations ns/op B/op allocs/op
16 66596963 107109 608

Contributing

To start contributing, please check CONTRIBUTING.

Tests

For local testing, just run:

 mise run test

Most of the tests call the live TMDb API, so CI runs mise run test:short, which covers only the tests that need no network.

License

MIT