Skip to content

Commit

Permalink
Handle invalid IMDB ID returned by Kodi
Browse files Browse the repository at this point in the history
  • Loading branch information
musse authored and newt-sc committed Apr 18, 2024
1 parent aac12c2 commit 740c29f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions a4kSubtitles/lib/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
__64k = 65536
__longlong_format_char = 'q'
__byte_size = struct.calcsize(__longlong_format_char)
__imdb_id_prefix = 'tt'

def __sum_64k_bytes(file, result):
range_value = __64k / __byte_size
Expand Down Expand Up @@ -327,13 +328,14 @@ def __get_basic_info():

return meta

def __is_imdb_id(id: str) -> bool:
return id.startswith(__imdb_id_prefix)

def get_meta(core):
meta = __get_basic_info()

# For some reason, imdb_id does not contain an IMDB ID (example: tt14230458),
# but rather contains a TMDB (themoviedb.org) ID (example: 792307).
# This causes the search on (at least) OpenSubtitles to fail.
if meta.imdb_id == '':
# Depending on the used scraper, the imdb_id returned by Kodi might not actually be an IMDB ID.
if meta.imdb_id == '' or not __is_imdb_id(meta.imdb_id):
cache_key = cache.hash_data(meta)
imdb_id_cache = cache.get_imdb_id_cache()
meta.imdb_id = imdb_id_cache.get(cache_key, '')
Expand Down

0 comments on commit 740c29f

Please sign in to comment.