Fix Tidal playlist endpoints redundantly re-fetching all playlists — use direct single-playlist fetch
This commit is contained in:
parent
27bd896540
commit
d329dd4fe8
2 changed files with 12 additions and 31 deletions
|
|
@ -795,6 +795,9 @@ class TidalClient:
|
||||||
# Continue pagination — we lose this batch but can still get remaining
|
# Continue pagination — we lose this batch but can still get remaining
|
||||||
batch_tracks = []
|
batch_tracks = []
|
||||||
|
|
||||||
|
if len(batch_tracks) < len(track_ids):
|
||||||
|
logger.warning(f"Page {page_num}: requested {len(track_ids)} tracks but only {len(batch_tracks)} returned (some may be unavailable in your region)")
|
||||||
|
|
||||||
tracks.extend(batch_tracks)
|
tracks.extend(batch_tracks)
|
||||||
total_fetched += len(batch_tracks)
|
total_fetched += len(batch_tracks)
|
||||||
logger.info(f"Fetched {len(batch_tracks)} tracks in this batch, {total_fetched} total so far")
|
logger.info(f"Fetched {len(batch_tracks)} tracks in this batch, {total_fetched} total so far")
|
||||||
|
|
|
||||||
|
|
@ -22191,27 +22191,10 @@ def get_tidal_playlist_tracks(playlist_id):
|
||||||
try:
|
try:
|
||||||
print(f"🎵 Getting full Tidal playlist with tracks for: {playlist_id}")
|
print(f"🎵 Getting full Tidal playlist with tracks for: {playlist_id}")
|
||||||
|
|
||||||
# First check if this playlist exists in metadata list
|
# Fetch this single playlist directly — no need to re-fetch all playlists
|
||||||
try:
|
|
||||||
metadata_playlists = tidal_client.get_user_playlists_metadata_only()
|
|
||||||
target_playlist = None
|
|
||||||
for p in metadata_playlists:
|
|
||||||
if p.id == playlist_id:
|
|
||||||
target_playlist = p
|
|
||||||
break
|
|
||||||
|
|
||||||
if not target_playlist:
|
|
||||||
print(f"❌ Playlist {playlist_id} not found in user's Tidal playlists")
|
|
||||||
return jsonify({"error": "Playlist not found in your Tidal library"}), 404
|
|
||||||
|
|
||||||
print(f"🎵 Found playlist in metadata: {target_playlist.name}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ Error checking playlist metadata: {e}")
|
|
||||||
|
|
||||||
# Use same method as sync.py: tidal_client.get_playlist(playlist_id)
|
|
||||||
full_playlist = tidal_client.get_playlist(playlist_id)
|
full_playlist = tidal_client.get_playlist(playlist_id)
|
||||||
if not full_playlist:
|
if not full_playlist:
|
||||||
return jsonify({"error": "Unable to access this Tidal playlist. This may be due to privacy settings or Tidal API restrictions. Please try a different playlist."}), 403
|
return jsonify({"error": "Playlist not found or unable to access. This may be due to privacy settings or Tidal API restrictions."}), 404
|
||||||
|
|
||||||
if not full_playlist.tracks:
|
if not full_playlist.tracks:
|
||||||
return jsonify({"error": "This playlist appears to have no tracks or they cannot be accessed"}), 403
|
return jsonify({"error": "This playlist appears to have no tracks or they cannot be accessed"}), 403
|
||||||
|
|
@ -22257,17 +22240,12 @@ tidal_discovery_executor = ThreadPoolExecutor(max_workers=3, thread_name_prefix=
|
||||||
def start_tidal_discovery(playlist_id):
|
def start_tidal_discovery(playlist_id):
|
||||||
"""Start Spotify discovery process for a Tidal playlist"""
|
"""Start Spotify discovery process for a Tidal playlist"""
|
||||||
try:
|
try:
|
||||||
# Get playlist data from the initial load
|
# Get playlist data from Tidal
|
||||||
if not tidal_client or not tidal_client.is_authenticated():
|
if not tidal_client or not tidal_client.is_authenticated():
|
||||||
return jsonify({"error": "Tidal not authenticated."}), 401
|
return jsonify({"error": "Tidal not authenticated."}), 401
|
||||||
|
|
||||||
# Get playlist from tidal client
|
# Fetch this single playlist directly — no need to re-fetch all playlists
|
||||||
playlists = tidal_client.get_user_playlists_metadata_only()
|
target_playlist = tidal_client.get_playlist(playlist_id)
|
||||||
target_playlist = None
|
|
||||||
for p in playlists:
|
|
||||||
if p.id == playlist_id:
|
|
||||||
target_playlist = p
|
|
||||||
break
|
|
||||||
|
|
||||||
if not target_playlist:
|
if not target_playlist:
|
||||||
return jsonify({"error": "Tidal playlist not found"}), 404
|
return jsonify({"error": "Tidal playlist not found"}), 404
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue