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.
This commit is contained in:
parent
20c8bff85c
commit
5bb36412be
1 changed files with 29 additions and 18 deletions
|
|
@ -1472,22 +1472,33 @@ class JellyfinClient:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
try:
|
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 = []
|
tracks = []
|
||||||
for item in response.get('Items', []):
|
start_index = 0
|
||||||
tracks.append(JellyfinTrack(item, self))
|
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}")
|
logger.debug(f"Retrieved {len(tracks)} tracks from playlist {playlist_id}")
|
||||||
return tracks
|
return tracks
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue