-
-
Save purplecandy/6c16ee39d1864144ed641767dd96fab5 to your computer and use it in GitHub Desktop.
Get images from TMDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
# TMDB | |
TMDB_API_KEY = '[your api key]' | |
# get configuration parameters | |
response = HTTParty.get("https://api.themoviedb.org/3/configuration?api_key=#{TMDB_API_KEY}") | |
config = JSON.parse(response.body) | |
image_prefix = config['images']['secure_base_url'] | |
# -------------------- | |
# movie images | |
tmdb_id = 20526 # Tron: Legacy | |
response = HTTParty.get("https://api.themoviedb.org/3/movie/#{tmdb_id}/images?api_key=#{TMDB_API_KEY}") | |
images = JSON.parse(response.body) | |
# this returns full size images by default (use a smaller image if possible) | |
# it is recommend to check the language and image size to work best in your app | |
poster = image_prefix + 'original' + images['posters'].first['file_path'] | |
fanart = image_prefix + 'original' + images['backdrops'].first['file_path'] | |
# -------------------- | |
# tv show images | |
tmdb_id = 62560 # Mr. Robot | |
response = HTTParty.get("https://api.themoviedb.org/3/tv/#{tmdb_id}/images?api_key=#{TMDB_API_KEY}") | |
images = JSON.parse(response.body) | |
# this returns full size images by default (use a smaller image if possible) | |
# it is recommend to check the language and image size to work best in your app | |
poster = image_prefix + 'original' + images['posters'].first['file_path'] | |
fanart = image_prefix + 'original' + images['backdrops'].first['file_path'] | |
# -------------------- | |
# season images | |
tmdb_id = 62560 # Mr. Robot | |
season_number = 1 | |
response = HTTParty.get("https://api.themoviedb.org/3/tv/#{tmdb_id}/season/#{season_number}/images?api_key=#{TMDB_API_KEY}") | |
images = JSON.parse(response.body) | |
# this returns full size images by default (use a smaller image if possible) | |
# it is recommend to check the language and image size to work best in your app | |
poster = image_prefix + 'original' + images['posters'].first['file_path'] | |
# -------------------- | |
# episode images | |
tmdb_id = 62560 # Mr. Robot | |
season_number = 1 | |
episode_number = 1 | |
response = HTTParty.get("https://api.themoviedb.org/3/tv/#{tmdb_id}/season/#{season_number}/episode/#{episode_number}/images?api_key=#{TMDB_API_KEY}") | |
images = JSON.parse(response.body) | |
# this returns full size images by default (use a smaller image if possible) | |
# it is recommend to check the language and image size to work best in your app | |
screenshot = image_prefix + 'original' + images['stills'].first['file_path'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment