TMDB: Improvements to TMDb ID checking function

- Moved validating ID check from trakt helper to tmdb helper.
pull/105/head
desimaniac 5 years ago
parent 826d6915fa
commit 4abf1a1eba

@ -1,29 +1,47 @@
from helpers import str as misc_str
from misc.log import logger
import requests
log = logger.get_logger(__name__)
def does_movie_exist_on_tmdb(sorted_movie):
def validate_movie_tmdb_id(movie_title, movie_year, movie_tmdb_id):
try:
movie_title = sorted_movie['movie']['title']
movie_year = str(sorted_movie['movie']['year']) \
if sorted_movie['movie']['year'] else '????'
movie_tmdbid = sorted_movie['movie']['ids']['tmdb']
if not movie_tmdb_id or not isinstance(movie_tmdb_id, int):
log.debug("SKIPPING: \'%s (%s)\' blacklisted it has an invalid TMDb ID", movie_title, movie_year)
return False
else:
return True
except Exception:
log.exception("Exception validating TMDb ID for \'%s (%s)\'.", movie_title, movie_year)
return False
req = requests.get('https://www.themoviedb.org/movie/%s' % movie_tmdbid)
def verify_movie_exists_on_tmdb(movie_title, movie_year, movie_tmdb_id):
try:
req = requests.get('https://www.themoviedb.org/movie/%s' % movie_tmdb_id)
if req.status_code == 200:
log.debug("\'%s (%s)\' [TMDb ID: %s] exists on TMDb.", movie_title, movie_year, movie_tmdbid)
log.debug("\'%s (%s)\' [TMDb ID: %s] exists on TMDb.", movie_title, movie_year, movie_tmdb_id)
return True
else:
log.debug("SKIPPING: \'%s (%s)\' [TMDb ID: %s] because it does not exist on TMDb.", movie_title, movie_year,
movie_tmdb_id)
return False
except Exception:
log.exception("Exception verifying TMDb ID for \'%s (%s)\'.", movie_title, movie_year)
return False
log.debug("SKIPPING: \'%s (%s)\' [TMDb ID: %s] because it does not exist on TMDb.", movie_title, movie_year,
movie_tmdbid)
return False
except Exception:
log.exception("Exception validating TMDb ID: ")
def check_movie_tmdb_id(sorted_movie):
movie_title = sorted_movie['movie']['title']
movie_year = str(sorted_movie['movie']['year']) \
if sorted_movie['movie']['year'] else '????'
movie_tmdb_id = sorted_movie['movie']['ids']['tmdb']
try:
if validate_movie_tmdb_id(movie_title, movie_year, movie_tmdb_id) and \
verify_movie_exists_on_tmdb(movie_title, movie_year, movie_tmdb_id):
return True
except Exception:
log.exception("Exception verifying/validating TMDb ID for \'%s (%s)\'.", movie_title, movie_year)
return False

@ -250,16 +250,13 @@ def blacklisted_movie_id(movie, blacklisted_ids):
blacklisted = False
blacklisted_ids = sorted(map(int, blacklisted_ids))
try:
if not movie['movie']['ids']['tmdb'] or not isinstance(movie['movie']['ids']['tmdb'], int):
log.debug("\'%s\' was blacklisted because it had an invalid TMDb ID", movie['movie']['title'])
blacklisted = True
elif movie['movie']['ids']['tmdb'] in blacklisted_ids:
if movie['movie']['ids']['tmdb'] in blacklisted_ids:
log.debug("\'%s\' was blacklisted because it had a blacklisted TMDb ID of: %d", movie['movie']['title'],
movie['movie']['ids']['tmdb'])
blacklisted = True
except Exception:
log.exception("Exception determining if show had a blacklisted TMDb ID %s: ", movie)
log.exception("Exception determining if movie had a blacklisted TMDb ID %s: ", movie)
return blacklisted

@ -720,8 +720,8 @@ def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', rating=None, gen
if sorted_movie['movie']['genres'] else 'N/A'
try:
# check if movie exists on TMDb website
if not tmdb_helper.does_movie_exist_on_tmdb(sorted_movie):
# check if movie has a valid TMDb ID and that it exists on TMDb
if not tmdb_helper.check_movie_tmdb_id(sorted_movie):
continue
# check if genre matches genre supplied via argument

Loading…
Cancel
Save