Skip to content

Instantly share code, notes, and snippets.

@codejockie
Created May 11, 2020 12:20
Show Gist options
  • Select an option

  • Save codejockie/7dc8948a6392c5ec5c168bc7c787d135 to your computer and use it in GitHub Desktop.

Select an option

Save codejockie/7dc8948a6392c5ec5c168bc7c787d135 to your computer and use it in GitHub Desktop.
const axios = require('axios') // import axios from 'axios'
const axiosInstance = axios.create({
baseURL: "https://api.themoviedb.org/3/",
})
export default axiosInstance
// TMDB
const TMDB_API_KEY = '[your api key]'
// Get configuration parameters
let config
axios.get(`configuration?api_key=${TMDB_API_KEY}`, )
.then(({ data }) => {
config = data
})
.catch((error) => console.log(error))
// Set base path for images
const imagePath = config['images']['secure_base_url']
// --------------------
// Movie images
const tmdbId = 20526 // Tron: Legacy
let images
axios.get(`movie/${tmdbId}/images?api_key=${TMDB_API_KEY}`)
.then(({ data }) => {
images = data
})
.catch((error) => console.log(error))
// Available backdrop sizes ["w300", "w780", "w1280", "original"]
// Available poster sizes ["w92", "w154", "w185", "w342", "w500", "w780", "original"]
// It is recommend to check the language and image size to work best in your app
const poster = imagePath + images['poster_sizes'][0]
const fanart = imagePath + images['backdrop_sizes'][0]
// --------------------
// TV show images
const tmdbId = 62560 // Mr. Robot
axios.get(`tv/${tmdbId}/images?api_key=${TMDB_API_KEY}`)
.then(({ data }) => {
images = data
})
.catch((error) => console.log(error))
// It is recommend to check the language and image size to work best in your app
const poster = imagePath + images['poster_sizes'][0]
const fanart = imagePath + images['backdrop_sizes'][0]
// --------------------
// Season images
const tmdbId = 62560 // Mr. Robot
const seasonNumber = 1
axios.get(`tv/${tmdbId}/season/${seasonNumber}/images?api_key${TMDB_API_KEY}`)
.then(({ data }) => {
images = data
})
.catch((error) => console.log(error))
// It is recommend to check the language and image size to work best in your app
const poster = imagePath + images['poster_sizes'][0]
// --------------------
// Episode images
const tmdbId = 62560 // Mr. Robot
const seasonNumber = 1
const episodeNumber = 1
axios.get(`tv/${tmdbId}/season/${seasonNumber}/episode/${episodeNumber}/images?api_key=${TMDB_API_KEY}`)
.then(({ data }) => {
images = data
})
.catch((error) => console.log(error))
// Available still sizes: ["w92", "w185", "w300", "original"]
// It is recommend to check the language and image size to work best in your app
const screenshot = imagePath + images['still_sizes'][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment