Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions resources/lib/scrobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def playbackStarted(self, data: Dict) -> None:
else:
self.videoDuration = xbmc.Player().getTotalTime()
except Exception as e:
logger.debug("Suddenly stopped watching item: %s" % e.message)
logger.debug("Suddenly stopped watching item: %s" % str(e))
self.curVideo = None
return

Expand Down Expand Up @@ -409,9 +409,11 @@ def playbackStarted(self, data: Dict) -> None:

def __preFetchUserRatings(self, result: Dict) -> None:
if result:
if utilities.isMovie(
self.curVideo["type"]
) and kodiUtilities.getSettingAsBool("rate_movie"):
if (
utilities.isMovie(self.curVideo["type"])
and kodiUtilities.getSettingAsBool("rate_movie")
and "movie" in result
):
# pre-get summary information, for faster rating dialog.
logger.debug(
"Movie rating is enabled, pre-fetching summary information."
Expand All @@ -422,9 +424,12 @@ def __preFetchUserRatings(self, result: Dict) -> None:
result["movie"]["ids"]["trakt"], "trakt"
)
}
elif utilities.isEpisode(
self.curVideo["type"]
) and kodiUtilities.getSettingAsBool("rate_episode"):
elif (
utilities.isEpisode(self.curVideo["type"])
and kodiUtilities.getSettingAsBool("rate_episode")
and "episode" in result
and "show" in result
):
# pre-get summary information, for faster rating dialog.
logger.debug(
"Episode rating is enabled, pre-fetching summary information."
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def findSeasonMatchInList(id: str, seasonNumber: int, listToMatch: Dict, idType:


def findEpisodeMatchInList(id: str, seasonNumber: int, episodeNumber: int, list_data: Dict, idType: str) -> Dict:
season = findSeasonMatchInList(id, seasonNumber, list, idType)
season = findSeasonMatchInList(id, seasonNumber, list_data, idType)
if season:
for episode in season["episodes"]:
if episode["number"] == episodeNumber:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,26 @@ def test_createError():
error_msg = utilities.createError(e)
assert "ValueError" in error_msg
assert "test error" in error_msg


def test_findEpisodeMatchInList():
# Mocking a structure that would be returned by Trakt API
class MockItem:
def __init__(self, data, keys):
self.data = data
self.keys = keys

def to_dict(self):
return self.data

episode_data = {"number": 1, "title": "Winter Is Coming"}
season_data = {"number": 1, "episodes": [episode_data]}
show_data = {"title": "Game of Thrones", "seasons": [season_data]}

mock_show = MockItem(show_data, [("tvdb", "121361")])
list_data = {"121361": mock_show}

# This should trigger the bug where 'list' is passed instead of 'list_data'
# and fail with AttributeError: type object 'list' has no attribute 'items'
result = utilities.findEpisodeMatchInList("121361", 1, 1, list_data, "tvdb")
assert result == episode_data