Skip to content

Fix: Handle empty Kodi media details by setting curVideoInfo to `No…#707

Merged
razzeee merged 1 commit intomainfrom
scrobble
Mar 12, 2026
Merged

Fix: Handle empty Kodi media details by setting curVideoInfo to `No…#707
razzeee merged 1 commit intomainfrom
scrobble

Conversation

@razzeee
Copy link
Owner

@razzeee razzeee commented Mar 11, 2026

…ne` and refine ID assignment conditions.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves robustness of the scrobbling flow when Kodi’s JSON-RPC returns empty/invalid media details by explicitly setting curVideoInfo to None and tightening conditions around assigning Kodi library IDs into Trakt result payloads.

Changes:

  • Guard getEpisodeDetailsFromKodi / getMovieDetailsFromKodi results before converting to Trakt media objects; set curVideoInfo = None when empty.
  • Avoid indexing into missing episode details by gating traktShowSummary/curVideoInfo setup on a non-empty response.
  • Refine Kodi ID assignment to Trakt scrobble results by checking result and expected keys (movie/episode) first.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"movie", movieDetailsKodi
)
else:
self.curVideoInfo = None
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When movieDetailsKodi is empty, self.curVideoInfo is set to None but playback continues. Later in this method there are conditions like "ids" in self.curVideoInfo that will raise TypeError when self.curVideoInfo is None (e.g., when scrobbling is disabled but rating is enabled). Consider aborting the playbackStarted flow (similar to the episode invalid-ID path) or ensure subsequent checks are guarded with self.curVideoInfo being a dict before using membership tests.

Suggested change
self.curVideoInfo = None
# Ensure curVideoInfo remains a dict so membership tests like
# `"ids" in self.curVideoInfo` do not raise TypeError.
self.curVideoInfo = {}

Copilot uses AI. Check for mistakes.
"episode", episode_details
)
else:
self.curVideoInfo = None
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If episode_details is empty, self.curVideoInfo becomes None but the multi-episode transition continues. playbackEnded() later unconditionally appends self.curVideoInfo to videosToRate, which can introduce None entries and crash the rating flow (it expects dicts). Consider aborting scrobbling/rating for the remainder of this multi-part item when details are empty, or ensure videosToRate never contains None values.

Suggested change
self.curVideoInfo = None
logger.warning(
"Failed to get episode details for multi-part "
"episode index %s; keeping existing curVideoInfo.",
self.curMPEpisode,
)

Copilot uses AI. Check for mistakes.
Comment on lines +411 to 415
if result and "id" in self.curVideo:
if utilities.isMovie(self.curVideo["type"]) and "movie" in result:
result["movie"]["movieid"] = self.curVideo["id"]
elif utilities.isEpisode(self.curVideo["type"]):
elif utilities.isEpisode(self.curVideo["type"]) and "episode" in result:
result["episode"]["episodeid"] = self.curVideo["id"]
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result can be None here (e.g., self.__scrobble("start") returns None when self.curVideoInfo is missing), but it is passed to __preFetchUserRatings which is annotated as result: Dict. Consider normalizing result to {} (or updating the type hints to Optional[Dict]) to keep the types consistent and avoid future misuse of result as a dict in this block.

Copilot uses AI. Check for mistakes.
@razzeee razzeee merged commit 09f5ae0 into main Mar 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants