Last active
March 10, 2023 01:15
-
-
Save rectifyer/ce87e4972f24d589d540a16696309dc5 to your computer and use it in GitHub Desktop.
Get images from TVDB
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' | |
# TVDB | |
TVDB_API_KEY = '[your api key]' | |
TVDB_USERNAME = '[your username]' | |
TVDB_USERKEY = '[your user key]' | |
image_prefix = 'http://thetvdb.com/banners/' | |
# get token | |
response = HTTParty.post('https://api.thetvdb.com/login', { | |
body: { | |
apikey: TVDB_API_KEY, | |
username: TVDB_USERNAME, | |
userkey: TVDB_USERKEY | |
}.to_json, | |
headers: { | |
'content-type': 'application/json' | |
} | |
}) | |
json = JSON.parse(response.body) | |
token = json['token'] | |
# -------------------- | |
# tv show poster | |
tvdb_id = 289590 # Mr. Robot | |
response = HTTParty.get("https://api.thetvdb.com/series/#{tvdb_id}/images/query?keyType=poster", { | |
headers: { | |
'Authorization': "Bearer #{token}", | |
'Accept-Language': 'en' | |
} | |
}) | |
images = JSON.parse(response.body) | |
# this returns full size images by default (use the thumbnail image if possible) | |
# it is recommend to check the language and image size to work best in your app | |
poster = image_prefix + images['data'].first['fileName'] | |
# -------------------- | |
# tv show fanart | |
tvdb_id = 289590 # Mr. Robot | |
response = HTTParty.get("https://api.thetvdb.com/series/#{tvdb_id}/images/query?keyType=fanart", { | |
headers: { | |
'Authorization': "Bearer #{token}", | |
'Accept-Language': 'en' | |
} | |
}) | |
images = JSON.parse(response.body) | |
# this returns full size images by default (use the thumbnail image if possible) | |
# it is recommend to check the language and image size to work best in your app | |
fanart = image_prefix + images['data'].first['fileName'] | |
# -------------------- | |
# episode images | |
tvdb_id = 5077068 # Mr. Robot | |
response = HTTParty.get("https://api.thetvdb.com/episodes/#{tvdb_id}", { | |
headers: { | |
'Authorization': "Bearer #{token}", | |
'Accept-Language': 'en' | |
} | |
}) | |
episode = JSON.parse(response.body) | |
# this returns full size images by default | |
# it is recommend to check the language and image size to work best in your app | |
screenshot = image_prefix + episode['data']['filename'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment