From d329dd4fe8aff4b0f2f950b09b2f80f0330927b7 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Wed, 11 Mar 2026 13:50:53 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20Tidal=20playlist=20endpoints=20redundantl?= =?UTF-8?q?y=20re-fetching=20all=20playlists=20=E2=80=94=20use=20direct=20?= =?UTF-8?q?single-playlist=20fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/tidal_client.py | 3 +++ web_server.py | 40 +++++++++------------------------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/core/tidal_client.py b/core/tidal_client.py index 6ac6ebf1..543241ba 100644 --- a/core/tidal_client.py +++ b/core/tidal_client.py @@ -795,6 +795,9 @@ class TidalClient: # Continue pagination — we lose this batch but can still get remaining 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) total_fetched += len(batch_tracks) logger.info(f"Fetched {len(batch_tracks)} tracks in this batch, {total_fetched} total so far") diff --git a/web_server.py b/web_server.py index 56249650..530e77d2 100644 --- a/web_server.py +++ b/web_server.py @@ -22190,28 +22190,11 @@ def get_tidal_playlist_tracks(playlist_id): return jsonify({"error": "Tidal not authenticated."}), 401 try: print(f"🎵 Getting full Tidal playlist with tracks for: {playlist_id}") - - # First check if this playlist exists in metadata list - 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) + + # Fetch this single playlist directly — no need to re-fetch all playlists full_playlist = tidal_client.get_playlist(playlist_id) 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: return jsonify({"error": "This playlist appears to have no tracks or they cannot be accessed"}), 403 @@ -22257,21 +22240,16 @@ tidal_discovery_executor = ThreadPoolExecutor(max_workers=3, thread_name_prefix= def start_tidal_discovery(playlist_id): """Start Spotify discovery process for a Tidal playlist""" try: - # Get playlist data from the initial load + # Get playlist data from Tidal if not tidal_client or not tidal_client.is_authenticated(): return jsonify({"error": "Tidal not authenticated."}), 401 - - # Get playlist from tidal client - playlists = tidal_client.get_user_playlists_metadata_only() - target_playlist = None - for p in playlists: - if p.id == playlist_id: - target_playlist = p - break - + + # Fetch this single playlist directly — no need to re-fetch all playlists + target_playlist = tidal_client.get_playlist(playlist_id) + if not target_playlist: return jsonify({"error": "Tidal playlist not found"}), 404 - + if not target_playlist.tracks: return jsonify({"error": "Playlist has no tracks"}), 400