Matthew Welch
1fb4a869b0
Added initial implementation of user data for tv shows and movies as well as OAuth for Google sign in.
86 lines
3.0 KiB
Python
86 lines
3.0 KiB
Python
from flask import current_app
|
|
import requests
|
|
import inspect
|
|
|
|
API_KEY = "***REMOVED***"
|
|
TMDB_FIND_URL = "https://api.themoviedb.org/3/find/"
|
|
|
|
TMDB_IMG_URL = "https://image.tmdb.org/t/p/original"
|
|
|
|
|
|
def get_movie_data(imdb_id):
|
|
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"]
|
|
|
|
return movie_id, overview, poster_path, backdrop_path
|
|
except Exception as e:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
|
|
|
|
def get_tv_show_data(imdb_id):
|
|
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"]
|
|
|
|
return tv_show_id, overview, poster_path
|
|
except Exception as e:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
|
|
|
|
def get_tv_episode_data(imdb_id):
|
|
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 episode data, status code: " + str(info["status_code"])+" "+str(info["status_message"]))
|
|
return None
|
|
if info["tv_episode_results"] == []:
|
|
current_app.logger.info("no tmdb results for: " + str(imdb_id))
|
|
return None
|
|
current_app.logger.info("tmdb tv_episode title: " + str(info["tv_episode_results"][0]["name"]))
|
|
tv_episode_id = info["tv_episode_results"][0]["id"]
|
|
name = info["tv_episode_results"][0]["name"]
|
|
overview = info["tv_episode_results"][0]["overview"]
|
|
still_path = info["tv_episode_results"][0]["still_path"]
|
|
|
|
return tv_episode_id, overview, still_path
|
|
except Exception as e:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|