2019-08-22 10:43:14 -07:00
|
|
|
import inspect
|
2019-07-23 15:49:57 -07:00
|
|
|
|
2020-08-05 18:47:29 -07:00
|
|
|
import requests
|
|
|
|
from flask import current_app
|
|
|
|
|
2019-07-23 15:49:57 -07:00
|
|
|
API_KEY = "***REMOVED***"
|
|
|
|
TMDB_FIND_URL = "https://api.themoviedb.org/3/find/"
|
2020-03-27 17:08:03 -07:00
|
|
|
TMDB_GET_TV_URL = "https://api.themoviedb.org/3/tv/"
|
2019-07-23 15:49:57 -07:00
|
|
|
|
|
|
|
TMDB_IMG_URL = "https://image.tmdb.org/t/p/original"
|
|
|
|
|
|
|
|
|
|
|
|
def get_movie_data(imdb_id):
|
2020-08-05 18:47:29 -07:00
|
|
|
try:
|
|
|
|
data = {"api_key": API_KEY, "language": "en-US", "external_source": "imdb_id"}
|
|
|
|
r = requests.get(TMDB_FIND_URL + imdb_id, params=data)
|
|
|
|
info = dict(r.json())
|
|
|
|
if "status_code" in info.keys():
|
|
|
|
current_app.logger.info("error getting tmdb movie data, status code: " + str(info["status_code"]) + " " + str(info["status_message"]))
|
|
|
|
return None
|
|
|
|
if info["movie_results"] == []:
|
|
|
|
current_app.logger.info("no tmdb results for: " + str(imdb_id))
|
|
|
|
return None
|
|
|
|
current_app.logger.info("tmdb movie title: " + str(info["movie_results"][0]["title"]))
|
|
|
|
movie_id = info["movie_results"][0]["id"]
|
|
|
|
overview = info["movie_results"][0]["overview"]
|
|
|
|
poster_path = info["movie_results"][0]["poster_path"]
|
|
|
|
backdrop_path = info["movie_results"][0]["backdrop_path"]
|
2019-07-23 15:49:57 -07:00
|
|
|
|
2020-08-05 18:47:29 -07:00
|
|
|
return movie_id, overview, poster_path, backdrop_path
|
|
|
|
except Exception as e:
|
2021-07-10 13:17:28 -07:00
|
|
|
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
2019-07-30 15:19:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
def get_tv_show_data(imdb_id):
|
2020-08-05 18:47:29 -07:00
|
|
|
try:
|
|
|
|
data = {"api_key": API_KEY, "language": "en-US", "external_source": "imdb_id"}
|
|
|
|
r = requests.get(TMDB_FIND_URL + imdb_id, params=data)
|
|
|
|
info = dict(r.json())
|
|
|
|
if "status_code" in info.keys():
|
|
|
|
current_app.logger.info("error getting tmdb tv show data, status code: " + str(info["status_code"]) + " " + str(info["status_message"]))
|
|
|
|
return None
|
|
|
|
if info["tv_results"] == []:
|
|
|
|
current_app.logger.info("no tmdb results for: " + str(imdb_id))
|
|
|
|
return None
|
|
|
|
current_app.logger.info("tmdb tv show title: " + str(info["tv_results"][0]["name"]))
|
|
|
|
tv_show_id = info["tv_results"][0]["id"]
|
|
|
|
overview = info["tv_results"][0]["overview"]
|
|
|
|
poster_path = info["tv_results"][0]["poster_path"]
|
2019-07-30 15:19:03 -07:00
|
|
|
|
2020-08-05 18:47:29 -07:00
|
|
|
return tv_show_id, overview, poster_path
|
|
|
|
except Exception as e:
|
2021-07-10 13:17:28 -07:00
|
|
|
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
2019-07-30 15:19:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
def get_tv_episode_data(imdb_id):
|
2020-08-05 18:47:29 -07:00
|
|
|
try:
|
|
|
|
data = {"api_key": API_KEY, "language": "en-US", "external_source": "imdb_id"}
|
|
|
|
r = requests.get(TMDB_FIND_URL + imdb_id, params=data)
|
|
|
|
episode_info = dict(r.json())
|
|
|
|
if "status_code" in episode_info.keys():
|
|
|
|
current_app.logger.info(
|
|
|
|
"error getting tmdb tv episode data, status code: " + str(episode_info["status_code"]) + " " + str(episode_info["status_message"])
|
|
|
|
)
|
|
|
|
return None
|
|
|
|
if episode_info["tv_episode_results"] == []:
|
|
|
|
current_app.logger.info("no tmdb results for: " + str(imdb_id))
|
|
|
|
return None
|
|
|
|
data = {"api_key": API_KEY, "language": "en-US"}
|
|
|
|
r = requests.get(TMDB_GET_TV_URL + str(episode_info["tv_episode_results"][0]["show_id"]), params=data)
|
|
|
|
show_name = dict(r.json())["name"]
|
|
|
|
current_app.logger.info("tmdb tv_episode title: " + show_name + ": " + str(episode_info["tv_episode_results"][0]["name"]))
|
|
|
|
tv_episode_id = episode_info["tv_episode_results"][0]["id"]
|
|
|
|
name = episode_info["tv_episode_results"][0]["name"]
|
|
|
|
overview = episode_info["tv_episode_results"][0]["overview"]
|
|
|
|
still_path = episode_info["tv_episode_results"][0]["still_path"]
|
2019-07-30 15:19:03 -07:00
|
|
|
|
2020-08-05 18:47:29 -07:00
|
|
|
return tv_episode_id, overview, still_path
|
|
|
|
except Exception as e:
|
2021-07-10 13:17:28 -07:00
|
|
|
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|