Fix Hydrabase not appearing as enhanced search source tab
- Remove stale hydrabase.enabled check, use is_connected() directly - Add hydrabase to frontend alternate source fetch list - Normalize Hydrabase artists to strings (server may send dicts), fixing silent crashes that prevented albums/tracks from appearing
This commit is contained in:
parent
a8c5a6ccaa
commit
a4f0745547
3 changed files with 22 additions and 8 deletions
|
|
@ -139,6 +139,21 @@ class HydrabaseClient:
|
|||
logger.error(f"Hydrabase query failed ({request_type}, '{query}'): {e}")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _normalize_artists(artists_raw) -> list:
|
||||
"""Normalize artists to a list of strings (Hydrabase may send dicts or strings)."""
|
||||
if not artists_raw or not isinstance(artists_raw, list):
|
||||
return []
|
||||
result = []
|
||||
for a in artists_raw:
|
||||
if isinstance(a, str):
|
||||
result.append(a)
|
||||
elif isinstance(a, dict):
|
||||
result.append(a.get('name', ''))
|
||||
else:
|
||||
result.append(str(a))
|
||||
return [x for x in result if x]
|
||||
|
||||
@staticmethod
|
||||
def _normalize_release_date(date_str: str) -> str:
|
||||
"""Strip time portion from ISO dates like '1995-01-01T08:00:00Z' -> '1995-01-01'."""
|
||||
|
|
@ -161,7 +176,7 @@ class HydrabaseClient:
|
|||
tracks.append(Track(
|
||||
id=str(item.get('id', '')),
|
||||
name=item.get('name', ''),
|
||||
artists=item.get('artists', []),
|
||||
artists=self._normalize_artists(item.get('artists', [])),
|
||||
album=item.get('album', ''),
|
||||
duration_ms=item.get('duration_ms', 0),
|
||||
popularity=item.get('popularity', 0),
|
||||
|
|
@ -210,7 +225,7 @@ class HydrabaseClient:
|
|||
albums.append(Album(
|
||||
id=str(item.get('soul_id', item.get('id', ''))),
|
||||
name=item.get('name', ''),
|
||||
artists=item.get('artists', []),
|
||||
artists=self._normalize_artists(item.get('artists', [])),
|
||||
release_date=self._normalize_release_date(item.get('release_date', '')),
|
||||
total_tracks=item.get('total_tracks', 0),
|
||||
album_type=item.get('album_type', 'album'),
|
||||
|
|
@ -235,7 +250,7 @@ class HydrabaseClient:
|
|||
albums.append(Album(
|
||||
id=str(item.get('soul_id', item.get('id', ''))),
|
||||
name=item.get('name', ''),
|
||||
artists=item.get('artists', []),
|
||||
artists=self._normalize_artists(item.get('artists', [])),
|
||||
release_date=self._normalize_release_date(item.get('release_date', '')),
|
||||
total_tracks=item.get('total_tracks', 0),
|
||||
album_type=item.get('album_type', 'album'),
|
||||
|
|
@ -376,7 +391,7 @@ class HydrabaseClient:
|
|||
tracks.append(Track(
|
||||
id=str(item.get('id', '')),
|
||||
name=item.get('name', ''),
|
||||
artists=item.get('artists', []),
|
||||
artists=self._normalize_artists(item.get('artists', [])),
|
||||
album=item.get('album', ''),
|
||||
duration_ms=item.get('duration_ms', 0),
|
||||
popularity=item.get('popularity', 0),
|
||||
|
|
@ -504,7 +519,7 @@ class HydrabaseClient:
|
|||
albums.append(Album(
|
||||
id=str(item.get('soul_id', item.get('id', ''))),
|
||||
name=item.get('name', ''),
|
||||
artists=item.get('artists', []),
|
||||
artists=self._normalize_artists(item.get('artists', [])),
|
||||
release_date=self._normalize_release_date(item.get('release_date', '')),
|
||||
total_tracks=item.get('total_tracks', 0),
|
||||
album_type=item_type,
|
||||
|
|
|
|||
|
|
@ -7006,8 +7006,7 @@ def enhanced_search():
|
|||
|
||||
# Determine which alternate sources are available (for frontend to fetch async)
|
||||
spotify_available = bool(spotify_client and spotify_client.is_spotify_authenticated())
|
||||
hydrabase_available = bool(hydrabase_client and hydrabase_client.is_connected()
|
||||
and (dev_mode_enabled or config_manager.get('hydrabase.enabled', False)))
|
||||
hydrabase_available = bool(hydrabase_client and hydrabase_client.is_connected())
|
||||
alternate_sources = []
|
||||
if primary_source != 'spotify' and spotify_available:
|
||||
alternate_sources.append('spotify')
|
||||
|
|
|
|||
|
|
@ -7574,7 +7574,7 @@ function initializeSearchModeToggle() {
|
|||
// Fire ALL source fetches immediately in parallel with the primary endpoint.
|
||||
// Don't guess which is primary — the main endpoint response will tell us.
|
||||
// If an alternate duplicates the primary, it just overwrites with same data.
|
||||
for (const srcName of ['spotify', 'itunes', 'deezer']) {
|
||||
for (const srcName of ['spotify', 'itunes', 'deezer', 'hydrabase']) {
|
||||
_fetchAlternateSource(srcName, query);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue