Fix Jellyfin playlist track fetch truncating at default API limit

get_playlist_tracks() had no Limit or StartIndex params, so Jellyfin
defaulted to ~100 items per response. This caused the Server Playlists
comparison to show most tracks as missing even though they were present.

Now paginates in batches of 1000 until a partial batch signals the last page.
pull/295/head
Broque Thomas 1 month ago
parent 20c8bff85c
commit 5bb36412be

@ -1470,28 +1470,39 @@ class JellyfinClient:
"""Get all tracks from a specific playlist"""
if not self.ensure_connection():
return []
try:
params = {
'ParentId': playlist_id,
'IncludeItemTypes': 'Audio',
'Recursive': True,
'Fields': 'AlbumId,ArtistItems,Path,MediaSources',
'SortBy': 'SortName',
'SortOrder': 'Ascending'
}
response = self._make_request(f'/Users/{self.user_id}/Items', params)
if not response:
return []
tracks = []
for item in response.get('Items', []):
tracks.append(JellyfinTrack(item, self))
start_index = 0
limit = 1000
while True:
params = {
'ParentId': playlist_id,
'IncludeItemTypes': 'Audio',
'Recursive': True,
'Fields': 'AlbumId,ArtistItems,Path,MediaSources',
'SortBy': 'SortName',
'SortOrder': 'Ascending',
'StartIndex': start_index,
'Limit': limit,
}
response = self._make_request(f'/Users/{self.user_id}/Items', params)
if not response:
break
batch = response.get('Items', [])
for item in batch:
tracks.append(JellyfinTrack(item, self))
if len(batch) < limit:
break # Last page
start_index += limit
logger.debug(f"Retrieved {len(tracks)} tracks from playlist {playlist_id}")
return tracks
except Exception as e:
logger.error(f"Error getting tracks for playlist {playlist_id}: {e}")
return []

Loading…
Cancel
Save