Skip to content

Instantly share code, notes, and snippets.

@rectifyer
Last active June 24, 2019 02:45
Show Gist options
  • Save rectifyer/902ededec071fbd0f05aa82e114a1fe2 to your computer and use it in GitHub Desktop.
Save rectifyer/902ededec071fbd0f05aa82e114a1fe2 to your computer and use it in GitHub Desktop.
Get Images from Fanart.tv
require 'httparty'
# Fanart.tv
FANART_API_KEY = '[your api key]'
FANART_CLIENT_KEY = '[your client key]'
# --------------------
# movie iamges
tmdb_id = 20526 # Tron: Legacy
response = HTTParty.get("https://webservice.fanart.tv/v3/movies/#{tmdb_id}?api_key=#{FANART_API_KEY}&client_key=#{FANART_CLIENT_KEY}")
json = JSON.parse(response.body)
# this returns full size images by default
# replace /fanart with /preview to get a smaller resolution image
poster = json['movieposter'].first['url']
fanart = json['moviebackground'].first['url']
logo = json['hdmovielogo'].first['url']
thumb = json['moviethumb'].first['url']
banner = json['moviebanner'].first['url']
clearart = json['hdmovieclearart'].first['url']
# --------------------
# tv show images
tvdb_id = 289590 # Mr. Robot
response = HTTParty.get("https://webservice.fanart.tv/v3/tv/#{tvdb_id}?api_key=#{FANART_API_KEY}&client_key=#{FANART_CLIENT_KEY}")
json = JSON.parse(response.body)
# this returns full size images by default
# replace /fanart with /preview to get a smaller resolution image
poster = json['tvposter'].first['url']
fanart = json['showbackground'].first['url']
logo = json['hdtvlogo'].first['url']
thumb = json['tvthumb'].first['url']
banner = json['tvbanner'].first['url']
clearart = json['hdclearart'].first['url']
# --------------------
# season images
season_posters = {}
json['seasonposter'].each do |poster|
number = poster['season'].to_i
season_posters[number] ||= poster['url']
end
# season_posters = {
# 1 => "http://assets.fanart.tv/fanart/tv/289590/seasonposter/mr-robot-575fec1bb68d4.jpg",
# 2 => "http://assets.fanart.tv/fanart/tv/289590/seasonposter/mr-robot-575fd5cd15fca.jpg"
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment