Audible: fixes pagination logic error is a users library have sub 50 items (#2055)
authorZtripez <reg@otherland.nu>
Sat, 22 Mar 2025 17:14:43 +0000 (18:14 +0100)
committerGitHub <noreply@github.com>
Sat, 22 Mar 2025 17:14:43 +0000 (18:14 +0100)
music_assistant/providers/audible/audible_helper.py

index fd8a1953c30a1de5380e4a0dd11c8fb07df5e8f9..0f997976f49196ec42adc06566749ba92e8e4ba1 100644 (file)
@@ -36,7 +36,6 @@ CACHE_CATEGORY_API = 0
 CACHE_CATEGORY_AUDIOBOOK = 1
 CACHE_CATEGORY_CHAPTERS = 2
 
-# Cache for authenticator objects to avoid repeated file reads
 _AUTH_CACHE: dict[str, audible.Authenticator] = {}
 
 
@@ -112,10 +111,9 @@ class AudibleHelper:
                 "Audible: Got %s items (total reported by API: %s)", len(items), total_items
             )
 
-            if not items or len(items) < page_size:
+            if not items:
                 self.logger.debug(
-                    "Audible: No more items or fewer than page size returned, "
-                    "ending pagination (processed %s items)",
+                    "Audible: No more items returned, ending pagination (processed %s items)",
                     total_processed,
                 )
                 break
@@ -164,6 +162,14 @@ class AudibleHelper:
                 total_items,
             )
 
+            if len(items) < page_size:
+                self.logger.debug(
+                    "Audible: Fewer than page size returned, "
+                    "ending pagination (processed %s items)",
+                    total_processed,
+                )
+                break
+
         if iteration >= max_iterations:
             self.logger.warning(
                 "Audible: Reached maximum iteration limit (%s) with %s items processed",