#!/usr/bin/env python3 """ Quick fix to add missing Spotify IDs to search results. This addresses the root cause of download tracking issues. """ import re def fix_spotify_ids(): """Add missing Spotify IDs to the backend search results parsing""" app_file = "/Volumes/SamMgmt/Containers/SamCloud Music App/server/app.py" print("🔧 Fixing missing Spotify IDs in backend search results...") # Read the current file with open(app_file, 'r') as f: content = f.read() # Fix 1: Add ID to tracks tracks_pattern = r'(parsed_results\["tracks"\]\.append\({\s*)"type": "track",' tracks_replacement = r'\1"id": item["id"],\n "type": "track",' if re.search(tracks_pattern, content): content = re.sub(tracks_pattern, tracks_replacement, content) print("✅ Added ID field to track parsing") else: print("❌ Could not find track parsing section") # Fix 2: Add ID to albums albums_pattern = r'(parsed_results\["albums"\]\.append\({\s*)"type": "album",' albums_replacement = r'\1"id": item["id"],\n "type": "album",' if re.search(albums_pattern, content): content = re.sub(albums_pattern, albums_replacement, content) print("✅ Added ID field to album parsing") else: print("❌ Could not find album parsing section") # Fix 3: Add ID to artists artists_pattern = r'(parsed_results\["artists"\]\.append\({\s*)"type": "artist",' artists_replacement = r'\1"id": item["id"],\n "type": "artist",' if re.search(artists_pattern, content): content = re.sub(artists_pattern, artists_replacement, content) print("✅ Added ID field to artist parsing") else: print("❌ Could not find artist parsing section") # Fix 4: Add ID to playlists playlists_pattern = r'(parsed_results\["playlists"\]\.append\({\s*)"type": "playlist",' playlists_replacement = r'\1"id": item["id"],\n "type": "playlist",' if re.search(playlists_pattern, content): content = re.sub(playlists_pattern, playlists_replacement, content) print("✅ Added ID field to playlist parsing") else: print("❌ Could not find playlist parsing section") # Write the fixed content back with open(app_file, 'w') as f: f.write(content) print("🎯 Backend fix applied! Spotify IDs will now be included in search results.") print(" This should fix the download tracking issues.") if __name__ == "__main__": fix_spotify_ids()