#!/usr/bin/env python3 """ Debug Spotify response to see what fields are actually available """ import json import logging import sys import os # Add the src directory to the path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) def debug_spotify_response(): """Debug what fields are actually in Spotify response""" logger.info("šŸ” Debugging Spotify response fields...") try: from swingmusic.services.spotify_web_player_client import get_spotify_web_player_client client = get_spotify_web_player_client() # Ensure we have a token if not client._ensure_token(): logger.error("āŒ Failed to get token") return False if not client._token.client_token: if not client._get_client_token(): logger.error("āŒ Failed to get client token") return False # Make a direct GraphQL query to see the raw response payload = { "variables": { "uri": "spotify:track:4iV5W9uYEdYUVa79Axb7Rh" }, "operationName": "getTrack", "extensions": { "persistedQuery": { "version": 1, "sha256Hash": "612585ae06ba435ad26369870deaae23b5c8800a256cd8a57e08eddc25a37294" } } } headers = { "Authorization": f"Bearer {client._token.access_token}", "Client-Token": client._token.client_token, "Spotify-App-Version": client._token.client_version, "Content-Type": "application/json", } response = client.session.post( "https://api-partner.spotify.com/pathfinder/v1/query", json=payload, headers=headers, timeout=30 ) if response.status_code == 200: data = response.json() track_data = data.get("data", {}).get("trackUnion", {}) logger.info("šŸ“Š Available fields in Spotify response:") logger.info(f"Track Type: {track_data.get('__typename', 'Unknown')}") # Print all available fields for key, value in track_data.items(): if key != "__typename": if isinstance(value, (str, int, float, bool)): logger.info(f" {key}: {value}") elif isinstance(value, dict): logger.info(f" {key}: [dict with {len(value)} keys]") if len(value) <= 5: for sub_key, sub_value in value.items(): logger.info(f" {sub_key}: {sub_value}") elif isinstance(value, list): logger.info(f" {key}: [list with {len(value)} items]") else: logger.info(f" {key}: {type(value)}") # Look specifically for play count and popularity logger.info("\nšŸŽÆ Looking for play count and popularity:") logger.info(f" playcount: {track_data.get('playcount', 'NOT FOUND')}") logger.info(f" popularity: {track_data.get('popularity', 'NOT FOUND')}") logger.info(f" playCount: {track_data.get('playCount', 'NOT FOUND')}") logger.info(f" popularityScore: {track_data.get('popularityScore', 'NOT FOUND')}") # Check nested objects logger.info("\nšŸ” Checking nested objects:") # Check visualIdentity visual_identity = track_data.get("visualIdentity", {}) logger.info(f" visualIdentity keys: {list(visual_identity.keys())}") # Check playability playability = track_data.get("playability", {}) logger.info(f" playability keys: {list(playability.keys())}") # Check contentRating content_rating = track_data.get("contentRating", {}) logger.info(f" contentRating keys: {list(content_rating.keys())}") return True else: logger.error(f"āŒ Request failed: {response.status_code}") logger.error(f"Response: {response.text}") return False except Exception as e: logger.error(f"āŒ Debug failed: {e}") import traceback traceback.print_exc() return False def main(): print("=" * 80) print("šŸ” SPOTIFY RESPONSE DEBUG") print("=" * 80) success = debug_spotify_response() print("\n" + "=" * 80) if success: print("āœ… Debug completed - check output for available fields") else: print("āŒ Debug failed") print("=" * 80) if __name__ == "__main__": main()