Skip to content

Spotify Integration

Setup

  1. Create Spotify Developer Account
  2. Go to Spotify Developer Dashboard
  3. Log in with your Spotify account or create one
  4. Click "Create an App"
  5. Fill in the app name and description

  6. Generate API Credentials

  7. From your app's dashboard, click "Settings"
  8. Note your Client ID and Client Secret
  9. Add your redirect URI (if using remote server, can be chosen default)
  10. Set app permissions under "Scopes"

  11. Configure Environment Variables Add these to your .env file:

    SPOTIFY_CLIENT_ID=your_client_id_here
    SPOTIFY_CLIENT_SECRET=your_client_secret_here
    

Basic Setup

from src.tools.spotify import SpotifyTool

# Initialize Spotify client
spotify = SpotifyTool()

# Authenticate and get access token
access_token = await spotify.authenticate()

# Search for songs
songs = await spotify.search_song(
    access_token=access_token,
    query="Never Gonna Give You Up",
    limit=1
)

# Get user playlists
playlists = await spotify.get_user_playlists(
    access_token=access_token
)

# Control playback
await spotify.control_playback(
    access_token=access_token,
    action="play"  # or "pause", "skip"
)

Features

  • Client Credentials OAuth2 authentication
  • Search for songs with customizable result limits
  • Retrieve user playlists and details
  • Control music playback (play, pause, skip)
  • Error handling with custom SpotifyError class
  • Async/await support for better performance
  • Secure API communication with proper authentication

TODOs for Future Enhancements:

  • Add support for real-time listening session tracking
  • Implement (collaborative) playlist creation and management
  • Add track analysis and audio features
  • Support for podcast playback
  • Implement device management: handle multi-device playback scenarios
  • Implement recommendation engine

Reference

For implementation details, see: src/tools/spotify.py

The implementation uses the official Spotify Web API. For more information, refer to: - Spotify Web API Documentation - Spotify Authorization Guide