Skip to content

Commit

Permalink
refactor: catch unexpected result
Browse files Browse the repository at this point in the history
  • Loading branch information
dylandoamaral committed Nov 23, 2023
1 parent b3ded27 commit cc2de4d
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions custom_components/trakt_tv/apis/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,26 @@ async def fetch_watched(self, excluded_shows: list):
if is_excluded:
continue

identifier = ids["slug"]

try:
raw_episode = await self.fetch_show_progress(ids["trakt"])
if raw_episode is not None:
if raw_episode.get("next_episode") is not None:
if raw_episode["next_episode"].get("season") is not None:
raw_episode_full = await self.fetch_show_informations(
ids["trakt"],
raw_episode["next_episode"].get("season"),
raw_episode["next_episode"].get("number"),
)
show["episode"] = raw_episode_full
show["first_aired"] = raw_episode_full["first_aired"]
raw_medias.append(show)
raw_episode_full = await self.fetch_show_informations(
ids["trakt"],
raw_episode["next_episode"]["season"],
raw_episode["next_episode"]["number"],
)
show["episode"] = raw_episode_full
show["first_aired"] = raw_episode_full["first_aired"]
raw_medias.append(show)
except IndexError:
LOGGER.warning("Show %s doesn't contain any trakt ID", ids["slug"])
LOGGER.warning(f"Show {identifier} doesn't contain any trakt ID")
continue
except TypeError as e:
LOGGER.warning(f"Show {identifier} can't be extracted due to {e}")
continue
except KeyError as e:
LOGGER.warning(f"Show {identifier} can't be extracted due to {e}")
continue

return raw_medias
Expand All @@ -183,6 +188,7 @@ async def fetch_show_progress(self, id: str):
cache_key = f"show_progress_{id}"

maybe_answer = cache_retrieve(self.cache(), cache_key)

if maybe_answer is not None:
return maybe_answer

Expand Down

0 comments on commit cc2de4d

Please sign in to comment.