Skip to content

Commit

Permalink
lookups now check for keys
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Jan 23, 2022
1 parent 6f68014 commit 00ce812
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.4
0.1.5
25 changes: 10 additions & 15 deletions tmdbapis/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,20 @@ def _tv_genre_lookup(self):
return self._tv_genre_lookups

def _get_object(self, lookup, obj_type):
if isinstance(lookup, dict):
if obj_type == "country" and "iso_3166_1" in lookup:
lookup = lookup["iso_3166_1"]
elif obj_type == "language" and "iso_639_1" in lookup:
lookup = lookup["iso_639_1"]
elif obj_type in ["movie_genre", "tv_genre"] and "id" in lookup:
lookup = lookup["id"]
else:
return None
if not lookup:
return None
def object_check(lookup_obj, key, lookup_dict, is_int=False):
if isinstance(lookup_obj, dict) and key in lookup_obj:
lookup_obj = lookup_obj[key]
return lookup_dict[int(lookup_obj) if is_int else lookup_obj] if lookup_obj in lookup_dict else None
if obj_type == "country":
return self._iso_3166_1[lookup]
return object_check(lookup, "iso_3166_1", self._iso_3166_1)
elif obj_type == "language":
return self._iso_639_1[lookup]
return object_check(lookup, "iso_639_1", self._iso_639_1)
elif obj_type == "movie_genre":
return self._movie_genre_lookup[int(lookup)]
return object_check(lookup, "id", self._movie_genre_lookup, is_int=True)
elif obj_type == "tv_genre":
return self._tv_genre_lookup[int(lookup)]
return object_check(lookup, "id", self._tv_genre_lookup, is_int=True)
else:
return None

@property
def language(self):
Expand Down

0 comments on commit 00ce812

Please sign in to comment.