Fix operator precedence and inverted dedup logic in audiobooks playlog (#3153)
authorDavid Bishop <teancom@users.noreply.github.com>
Fri, 13 Feb 2026 09:53:46 +0000 (01:53 -0800)
committerGitHub <noreply@github.com>
Fri, 13 Feb 2026 09:53:46 +0000 (10:53 +0100)
Two bugs in the audiobook resume/playlog tracking:

1. `int(media_item.resume_position_ms or 0 / 1000)` never divides by
   1000 because `/` binds tighter than `or`. The expression evaluates as
   `int(resume_position_ms or (0 / 1000))`, so non-zero values pass
   through as raw milliseconds instead of seconds.

2. The dedup check `abs(difference) > 2` skips the DB write when data
   HAS changed (difference > 2 seconds) and writes when it has NOT
   changed (difference <= 2 seconds). The comparison is inverted.

Co-authored-by: David Bishop <git@gnuconsulting.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
music_assistant/controllers/media/audiobooks.py

index 36035fd8b9a42af5bd397bdadfad90facbd444ba..1fc3d8295636e500f0fc6af54855d24f64d85375 100644 (file)
@@ -305,12 +305,12 @@ class AudiobooksController(MediaControllerBase[Audiobook]):
                 "provider": "library",
             },
         )
-        seconds_played = int(media_item.resume_position_ms or 0 / 1000)
+        seconds_played = int((media_item.resume_position_ms or 0) / 1000)
         # abort if nothing changed
         if (
             cur_entry
             and cur_entry["fully_played"] == media_item.fully_played
-            and abs((cur_entry["seconds_played"] or 0) - seconds_played) > 2
+            and abs((cur_entry["seconds_played"] or 0) - seconds_played) <= 2
         ):
             return
         await self.mass.music.database.insert(