#!/usr/bin/env python3 """ Simple test server to verify frontend data structure expectations """ from flask import Flask, jsonify from flask_cors import CORS app = Flask(__name__) CORS(app, origins=["http://localhost:5144"]) # Mock data with the exact structure expected by the frontend mock_discovery_data = { "for_you": { "title": "Made For You", "description": "Based on your listening history", "tracks": [ { "Id": "track1", "Name": "Test Track 1", "Type": "Audio", "Artists": ["Test Artist 1"], "Album": "Test Album 1", "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "UserData": {"IsFavorite": False} } ] }, "new_releases": { "title": "New Releases", "description": "Fresh music to discover", "tracks": [ { "Id": "newtrack1", "Name": "New Release Track 1", "Type": "Audio", "Artists": ["New Artist 1"], "Album": "New Album 1", "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "UserData": {"IsFavorite": False} } ] }, "trending": { "title": "Trending Now", "description": "Popular tracks everyone is listening to", "tracks": [ { "Id": "trending1", "Name": "Trending Track 1", "Type": "Audio", "Artists": ["Trending Artist 1"], "Album": "Trending Album 1", "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "UserData": {"IsFavorite": False} } ] }, "trending_albums": { "title": "Popular Albums", "description": "Popular albums everyone is listening to", "albums": [ { "Id": "album1", "Name": "Popular Album 1", "Type": "MusicAlbum", "Artists": ["Popular Artist 1"], "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "ChildCount": 12, "UserData": {"IsFavorite": False} } ] }, "new_albums": { "title": "New Album Releases", "description": "Fresh albums released recently", "albums": [ { "Id": "newalbum1", "Name": "New Album Release 1", "Type": "MusicAlbum", "Artists": ["New Album Artist 1"], "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "ChildCount": 10, "UserData": {"IsFavorite": False} }, { "Id": "newalbum2", "Name": "New Album Release 2", "Type": "MusicAlbum", "Artists": ["New Album Artist 2"], "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "ChildCount": 8, "UserData": {"IsFavorite": False} } ] }, "genres": [ { "genre": "Hip-Hop", "title": "Hip-Hop Picks", "tracks": [ { "Id": "hiphop1", "Name": "Hip-Hop Track 1", "Type": "Audio", "Artists": ["Hip-Hop Artist 1"], "Album": "Hip-Hop Album 1", "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "UserData": {"IsFavorite": False} } ] } ] } @app.route('/api/discover', methods=['GET']) def discover(): print("Mock server: /api/discover endpoint called") print(f"Returning data with {len(mock_discovery_data)} sections") print(f"new_albums section has {len(mock_discovery_data['new_albums']['albums'])} albums") return jsonify(mock_discovery_data) @app.route('/api/discover/genres', methods=['GET']) def discover_genres(): extended_genres = [] genre_names = [ 'Hip-Hop', 'Pop', 'Rock', 'R&B', 'Electronic', 'Indie', 'Reggae', 'Dancehall', 'Afrobeats', 'Soca', 'Jazz', 'Blues', 'Country', 'Folk', 'Classical', 'Latin', 'Funk', 'Soul', 'Disco', 'House', 'Techno', 'Dubstep', 'Drum-and-Bass', 'Ambient', 'Punk', 'Metal', 'Alternative', 'Grunge', 'Ska', 'Reggaeton', 'Trap', 'Grime', 'World-Music', 'Gospel', 'New-Age', 'Experimental', 'Progressive', 'Post-Rock', 'Singer-Songwriter', 'Acoustic', 'Instrumental', 'Soundtrack', 'Comedy', 'Spoken-Word' ] for genre in genre_names: extended_genres.append({ "genre": genre, "title": f"{genre} Picks", "tracks": [ { "Id": f"{genre.lower()}1", "Name": f"{genre} Track 1", "Type": "Audio", "Artists": [f"{genre} Artist 1"], "Album": f"{genre} Album 1", "ImageTags": {"Primary": "spotify_image"}, "SpotifyImage": "https://via.placeholder.com/300", "UserData": {"IsFavorite": False} } ] }) print(f"Mock server: /api/discover/genres endpoint called - returning {len(extended_genres)} genres") return jsonify(extended_genres) if __name__ == '__main__': print("Starting mock discovery server on port 5140...") print("This will test:") print("1. Whether 'New Albums' section displays when data is available") print("2. Whether all genres show up when more are provided") app.run(host='127.0.0.1', port=5140, debug=False, threaded=True)