Skip to content

Commit

Permalink
Merge pull request #7 from zeroquinc/dev
Browse files Browse the repository at this point in the history
Fixed: don't search tmdb_id on title in API anymore, to many mismatches
  • Loading branch information
zeroquinc authored Jan 25, 2024
2 parents 73b341c + 512d755 commit 1ff3b9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_imdb_id(info, media_type):
if media_type == 'tv':
imdb_id = get_imdb_id_for_tv_show(info)
elif media_type == 'movie':
imdb_id = get_imdb_id_for_movie(info, 'movie')
imdb_id = get_imdb_id_for_movie(info)

logger.debug(f"IMDb ID: {imdb_id}")
return imdb_id
Expand Down
20 changes: 9 additions & 11 deletions src/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_tmdb_id_tmdb(info, media_type):
if media_type == 'tv':
tmdb_id = get_tmdb_id_for_tv_show(info)
elif media_type == 'movie':
tmdb_id = get_tmdb_id_for_media(info, 'movie')
tmdb_id = get_tmdb_id_for_media(info)

logger.debug(f"TMDB ID: {tmdb_id}")
return tmdb_id
Expand All @@ -38,7 +38,7 @@ def get_tmdb_id_for_tv_show(info):
if tv_show_id != -1:
tmdb_id = get_tmdb_id_from_tv_show_details(tv_show_id)
else:
tmdb_id = get_tmdb_id_for_media(info, 'tv')
tmdb_id = None
return tmdb_id

# Function to get the TMDB ID of a media via the TMDB API if the TMDB ID is not available in the info
Expand All @@ -51,16 +51,14 @@ def get_tmdb_id_from_tv_show_details(tv_show_id):
return tv_show_response['result']['tvshowdetails']['uniqueid']['tmdb']
return None

# Function to get the TMDB ID of a media via the TMDB API if the TMDB ID is not available in the info
# Function to fetch the tmdb_id of the media
def get_tmdb_id_for_media(info, media_type):
title = quote(info['showtitle'] if media_type == 'tv' else info['title'])
title_url = f"https://api.themoviedb.org/3/search/{media_type}?api_key={TMDB_API_KEY}&query={title}"
title_response = requests.get(title_url).json()
logger.debug(f"Searching TMDB {media_type.capitalize()} with title: {title}: {title_response}")
if 'results' in title_response and len(title_response['results']) > 0:
logger.debug(f"TMDB {media_type.capitalize()} search results: {title_response['results'][0]['id']}")
return title_response['results'][0]['id']
return None
if 'uniqueid' in info and 'tmdb' in info['uniqueid']:
logger.debug("Found uniqueid in info")
return info['uniqueid']['tmdb']
else:
logger.debug("Can't find TMDB ID in uniqueid")
return None

# Function to get the image URL of a media
def get_image_url(tmdb_id, media_type):
Expand Down
19 changes: 6 additions & 13 deletions src/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,15 @@ def get_tmdb_id_for_media(info, media_type):
logger.debug("Found uniqueid in info")
return info['uniqueid']['tmdb']
else:
logger.debug("Can't find TMDB ID in uniqueid, searching via API")
return get_tmdb_id_for_media_via_api(info, media_type)

# Function to get the TMDB ID of a media via the TMDB API if the TMDB ID is not available in the info
def get_tmdb_id_for_media_via_api(info, media_type):
title = quote(info['showtitle'] if media_type == 'episode' else info['title'])
title_url = f"https://api.themoviedb.org/3/search/{media_type}?api_key={TMDB_API_KEY}&query={title}"
title_response = requests.get(title_url).json()
logger.debug(f"Searching TMDB {media_type.capitalize()} with title: {title}: {title_response}")
if 'results' in title_response and len(title_response['results']) > 0:
logger.debug(f"TMDB {media_type.capitalize()} search results: {title_response['results'][0]['id']}")
return title_response['results'][0]['id']
return None
logger.debug("Can't find TMDB ID in uniqueid")
return None

# Function to get the Trakt URL of a media
def get_trakt_url(tmdb_id, media_type):
# Return None if tmdb_id is None
if tmdb_id is None:
return None

# Define the base URL
base_url = "https://trakt.tv/"

Expand Down

0 comments on commit 1ff3b9b

Please sign in to comment.