fix: seasonal service constructor, source-aware track IDs, deep-link timing
- Use get_seasonal_discovery_service(spotify_client, database) instead of broken SeasonalDiscoveryService(database) in both auto-sync and track_count paths - Replace nonexistent get_current_season_playlist() with working get_current_season() + get_curated_seasonal_playlist() pattern - Use generic track_id field for personalized playlist auto-sync instead of hardcoded spotify_track_id (fixes Deezer/iTunes) - Replace fixed 400ms setTimeout in _applySyncTabAction with polling loop that waits for target element (up to 4s)
This commit is contained in:
parent
20cad61e4f
commit
6ce90ba10d
2 changed files with 57 additions and 18 deletions
|
|
@ -44103,17 +44103,41 @@ def _auto_sync_discover_playlists(profile_id, active_source):
|
||||||
'duration_ms': t.duration_ms or 0
|
'duration_ms': t.duration_ms or 0
|
||||||
})
|
})
|
||||||
elif ptype == 'seasonal_playlist':
|
elif ptype == 'seasonal_playlist':
|
||||||
from core.seasonal_discovery import SeasonalDiscoveryService
|
from core.seasonal_discovery import get_seasonal_discovery_service, SEASONAL_CONFIG
|
||||||
seasonal_svc = SeasonalDiscoveryService(database)
|
seasonal_svc = get_seasonal_discovery_service(spotify_client, database)
|
||||||
season_data = seasonal_svc.get_current_season_playlist()
|
current_season = seasonal_svc.get_current_season()
|
||||||
if season_data and season_data.get('tracks'):
|
if current_season and current_season in SEASONAL_CONFIG:
|
||||||
tracks = [{
|
track_ids = seasonal_svc.get_curated_seasonal_playlist(current_season, source=active_source)
|
||||||
'id': t.get('spotify_track_id', ''),
|
if track_ids:
|
||||||
'name': t.get('track_name', ''),
|
if active_source == 'itunes':
|
||||||
'artists': [t.get('artist_name', '')],
|
s_id_col = 'itunes_track_id'
|
||||||
'album': t.get('album_name', ''),
|
elif active_source == 'deezer':
|
||||||
'duration_ms': t.get('duration_ms', 0)
|
s_id_col = 'deezer_track_id'
|
||||||
} for t in season_data['tracks']]
|
else:
|
||||||
|
s_id_col = 'spotify_track_id'
|
||||||
|
with database._get_connection() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
for tid in track_ids:
|
||||||
|
cursor.execute(f"""
|
||||||
|
SELECT {s_id_col} as track_id, track_name, artist_name, album_name, duration_ms
|
||||||
|
FROM seasonal_tracks WHERE {s_id_col} = ? AND source = ?
|
||||||
|
""", (tid, active_source))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not row:
|
||||||
|
cursor.execute(f"""
|
||||||
|
SELECT {s_id_col} as track_id, track_name, artist_name, album_name, duration_ms
|
||||||
|
FROM discovery_pool WHERE {s_id_col} = ? AND source = ?
|
||||||
|
""", (tid, active_source))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
r = dict(row)
|
||||||
|
tracks.append({
|
||||||
|
'id': r.get('track_id', ''),
|
||||||
|
'name': r.get('track_name', ''),
|
||||||
|
'artists': [r.get('artist_name', '')],
|
||||||
|
'album': r.get('album_name', ''),
|
||||||
|
'duration_ms': r.get('duration_ms', 0)
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
from core.personalized_playlists import PersonalizedPlaylistsService
|
from core.personalized_playlists import PersonalizedPlaylistsService
|
||||||
service = PersonalizedPlaylistsService(database)
|
service = PersonalizedPlaylistsService(database)
|
||||||
|
|
@ -44126,7 +44150,7 @@ def _auto_sync_discover_playlists(profile_id, active_source):
|
||||||
if ptype in method_map:
|
if ptype in method_map:
|
||||||
raw_tracks = method_map[ptype](limit=50)
|
raw_tracks = method_map[ptype](limit=50)
|
||||||
tracks = [{
|
tracks = [{
|
||||||
'id': t.get('spotify_track_id', ''),
|
'id': t.get('track_id') or t.get('spotify_track_id') or t.get('deezer_track_id') or t.get('itunes_track_id') or '',
|
||||||
'name': t.get('track_name', ''),
|
'name': t.get('track_name', ''),
|
||||||
'artists': [t.get('artist_name', '')],
|
'artists': [t.get('artist_name', '')],
|
||||||
'album': t.get('album_name', ''),
|
'album': t.get('album_name', ''),
|
||||||
|
|
@ -44192,11 +44216,15 @@ def get_discover_synced_playlists():
|
||||||
curated_ids = database.get_curated_playlist(ptype, profile_id=pid)
|
curated_ids = database.get_curated_playlist(ptype, profile_id=pid)
|
||||||
track_count = len(curated_ids) if curated_ids else 0
|
track_count = len(curated_ids) if curated_ids else 0
|
||||||
elif ptype == 'seasonal_playlist':
|
elif ptype == 'seasonal_playlist':
|
||||||
from core.seasonal_discovery import SeasonalDiscoveryService
|
from core.seasonal_discovery import get_seasonal_discovery_service
|
||||||
try:
|
try:
|
||||||
seasonal_svc = SeasonalDiscoveryService(database)
|
seasonal_svc = get_seasonal_discovery_service(spotify_client, database)
|
||||||
season_data = seasonal_svc.get_current_season_playlist()
|
current_season = seasonal_svc.get_current_season()
|
||||||
track_count = len(season_data.get('tracks', [])) if season_data else 0
|
if current_season:
|
||||||
|
curated = seasonal_svc.get_curated_seasonal_playlist(current_season, source=active_source)
|
||||||
|
track_count = len(curated) if curated else 0
|
||||||
|
else:
|
||||||
|
track_count = 0
|
||||||
except Exception:
|
except Exception:
|
||||||
track_count = 0
|
track_count = 0
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -2780,8 +2780,19 @@ function _applySyncTabAction() {
|
||||||
syncDiscoverPlaylistFromTab(action.autoSync, action.autoSyncName || action.autoSync);
|
syncDiscoverPlaylistFromTab(action.autoSync, action.autoSyncName || action.autoSync);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Small delay to let lazy tab content render
|
// Wait for lazy-loaded content to appear before applying
|
||||||
setTimeout(apply, 400);
|
let attempts = 0;
|
||||||
|
const maxAttempts = 20; // 20 * 200ms = 4s max
|
||||||
|
const waitAndApply = () => {
|
||||||
|
const ready = !action.highlight || document.getElementById(action.highlight);
|
||||||
|
if (ready || attempts >= maxAttempts) {
|
||||||
|
apply();
|
||||||
|
} else {
|
||||||
|
attempts++;
|
||||||
|
setTimeout(waitAndApply, 200);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setTimeout(waitAndApply, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeSyncPage() {
|
function initializeSyncPage() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue