Skip to content

Commit 3996469

Browse files
committed
Fix: Final chunk count must not exceed maximum number of playlists (Fixes #389). Added pagination tests
1 parent 5164a23 commit 3996469

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

tidalapi/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ def get_tracks_count(
840840
This performs a minimal API request (limit=1) to fetch metadata about the tracks
841841
without retrieving all of them. The API response contains 'totalNumberOfItems',
842842
which represents the total items (tracks) available.
843+
Note: This number also includes track that may not be available for playback
843844
:return: The number of items available.
844845
"""
845846
params = {"limit": 1, "offset": 0}

tidalapi/workers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ def get_items(
4141
items = []
4242

4343
with ThreadPoolExecutor(processes) as pool:
44-
args_list = [(func, chunk_size, offset, *args) for offset in offsets]
44+
# Build argument tuples for each worker.
45+
# The limit is capped using `total_count` so the final chunk does not exceed
46+
# the available number of items (e.g., last chunk may be smaller than chunk_size).
47+
# i.e. for a total number of 123 tracks, the following ranges will be generated
48+
# (func, 50, 0, ...)
49+
# (func, 50, 50, ...)
50+
# (func, 23, 100, ...)
51+
args_list = [
52+
(func, min(chunk_size, total_count - offset), offset, *args)
53+
for offset in offsets
54+
]
4555

4656
for page_items in pool.map(func_wrapper, args_list):
4757
items.extend(page_items)

0 commit comments

Comments
 (0)