Fix Navidrome incremental update to use getAlbumList2 API for recent albums
Summary: Navidrome incremental updates always found 0 new tracks because _get_recent_albums_navidrome() fetched all artists, sampled only the first 200, collected their albums, and sorted by created date — missing artists beyond the first 200 entirely. Replaced this with a single getAlbumList2?type=newest Subsonic API call that directly returns albums sorted by library addition date, matching how Jellyfin and Plex already use their native "recently added" endpoints.
This commit is contained in:
parent
20c7aa33a3
commit
f2fb498693
2 changed files with 42 additions and 44 deletions
|
|
@ -916,52 +916,12 @@ class DatabaseUpdateWorker(QThread):
|
|||
return []
|
||||
|
||||
def _get_recent_albums_navidrome(self) -> List:
|
||||
"""Get recently added albums from Navidrome using all albums sorted by date"""
|
||||
"""Get recently added albums from Navidrome using getAlbumList2 API"""
|
||||
try:
|
||||
logger.info("Getting recent albums from Navidrome...")
|
||||
|
||||
# Navidrome doesn't have a direct "recent albums" API like Plex/Jellyfin
|
||||
# So we need to get all albums and sort them by date
|
||||
all_artists = self.media_client.get_all_artists()
|
||||
if not all_artists:
|
||||
return []
|
||||
|
||||
all_albums = []
|
||||
# Get albums from a subset of artists to avoid too much data
|
||||
# Take first 200 artists to get a reasonable sample of recent albums
|
||||
sample_artists = all_artists[:200]
|
||||
|
||||
for artist in sample_artists:
|
||||
try:
|
||||
artist_albums = self.media_client.get_albums_for_artist(artist.ratingKey)
|
||||
all_albums.extend(artist_albums)
|
||||
except Exception as e:
|
||||
logger.warning(f"Error getting albums for artist {getattr(artist, 'title', 'Unknown')}: {e}")
|
||||
continue
|
||||
|
||||
if not all_albums:
|
||||
return []
|
||||
|
||||
# Sort by addedAt date (newest first) and take recent ones
|
||||
try:
|
||||
def get_sort_date(album):
|
||||
date_val = getattr(album, 'addedAt', None)
|
||||
if date_val is None:
|
||||
return 0
|
||||
return date_val
|
||||
|
||||
all_albums.sort(key=get_sort_date, reverse=True)
|
||||
# Take the most recent 400 albums for incremental checking
|
||||
recent_albums = all_albums[:400]
|
||||
|
||||
logger.info(f"Found {len(recent_albums)} recent albums from Navidrome (from {len(all_albums)} total)")
|
||||
return recent_albums
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error sorting Navidrome albums by date: {e}")
|
||||
# If sorting fails, just return the first 400 albums
|
||||
return all_albums[:400]
|
||||
|
||||
recent_albums = self.media_client.get_recently_added_albums(400)
|
||||
logger.info(f"Found {len(recent_albums)} recently added albums from Navidrome")
|
||||
return recent_albums
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting recent Navidrome albums: {e}")
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -360,6 +360,44 @@ class NavidromeClient:
|
|||
logger.error(f"Error getting albums for artist {artist_id}: {e}")
|
||||
return []
|
||||
|
||||
def get_recently_added_albums(self, limit: int = 400) -> List[NavidromeAlbum]:
|
||||
"""Get recently added albums from Navidrome using getAlbumList2 sorted by newest"""
|
||||
if not self.ensure_connection():
|
||||
return []
|
||||
|
||||
try:
|
||||
albums = []
|
||||
page_size = min(limit, 500)
|
||||
offset = 0
|
||||
|
||||
while len(albums) < limit:
|
||||
response = self._make_request('getAlbumList2', {
|
||||
'type': 'newest',
|
||||
'size': page_size,
|
||||
'offset': offset
|
||||
})
|
||||
if not response:
|
||||
break
|
||||
|
||||
album_list = response.get('albumList2', {}).get('album', [])
|
||||
if not album_list:
|
||||
break
|
||||
|
||||
for album_data in album_list:
|
||||
albums.append(NavidromeAlbum(album_data, self))
|
||||
|
||||
if len(album_list) < page_size:
|
||||
break # No more pages
|
||||
|
||||
offset += page_size
|
||||
|
||||
logger.info(f"Retrieved {len(albums)} recently added albums from Navidrome")
|
||||
return albums[:limit]
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting recently added albums from Navidrome: {e}")
|
||||
return []
|
||||
|
||||
def get_tracks_for_album(self, album_id: str) -> List[NavidromeTrack]:
|
||||
"""Get all tracks for a specific album"""
|
||||
# Check cache first
|
||||
|
|
|
|||
Loading…
Reference in a new issue