Giter VIP home page Giter VIP logo

golang-tmdb's Introduction

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

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

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

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

Requirements

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

Installation

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

Usage

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

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

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

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

tmdbClient.SetClientConfig(customClient)

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

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

fmt.Println(movie.Title)

With optional params:

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

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

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

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

fmt.Println(movie.Title)

Helpers:

Generate image and video URLs:

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

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

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

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

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

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

For more examples, click here.

Performance

Getting Movie Details:

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:

 go test -v 

License

MIT

golang-tmdb's People

Contributors

cyruzin avatar rqphqel avatar cevatbarisyilmaz avatar tim-koehler avatar tmm1 avatar dimuska139 avatar kalafut avatar rohfle avatar allanpk716 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.