Files
Bose-SoundTouch/examples/introspect/README.md
T
Tobias Gesellchen 7ec4ee67af feat: implement /introspect and /recents endpoints with full CLI support
🔥 NEW ENDPOINTS IMPLEMENTED:

📊 /introspect endpoint:
- Get detailed music service state and capabilities data
- Support for SPOTIFY, PANDORA, TUNEIN, AMAZON, DEEZER services
- Service state tracking (Active, Inactive, InactiveUnselected)
- Playback capabilities (skip, seek, resume, data collection)
- Authentication token status and user account information
- Subscription type and content history metadata

📚 /recents endpoint:
- Retrieve recently played content history
- Support for all music sources (Spotify, Local, TuneIn, Pandora, etc.)
- Rich filtering by source type and content type
- Content classification (tracks, stations, playlists, albums)
- Presetable item identification and artwork metadata
- Timestamp tracking with UTC time support

 CLIENT API:
- client.Introspect(source, sourceAccount) method
- client.IntrospectSpotify(sourceAccount) convenience method
- client.GetRecents() method with comprehensive filtering
- Complete error handling and validation
- Rich helper methods for content analysis

🖥️ CLI COMMANDS:
- soundtouch-cli source introspect --source <SERVICE>
- soundtouch-cli source introspect-spotify
- soundtouch-cli source introspect-all (bulk introspect)
- soundtouch-cli recents list [--detailed] [--limit N]
- soundtouch-cli recents filter --source <SRC> --type <TYPE>
- soundtouch-cli recents latest (most recent item)
- soundtouch-cli recents stats (detailed analytics)

📦 MODELS & FEATURES:
- IntrospectRequest/Response with service-specific handling
- RecentsResponse with RecentsResponseItem for individual items
- Rich filtering: GetSpotifyItems(), GetTracks(), GetPresetableItems()
- Content type detection: IsTrack(), IsStation(), IsPlaylist()
- Source classification: IsStreamingContent(), IsLocalContent()
- Full XML marshalling/unmarshalling with proper attribute handling

🧪 COMPREHENSIVE TESTING:
- Unit tests for models with XML parsing validation
- Integration tests for real device communication
- CLI command tests with mock server responses
- Error condition testing and edge case handling
- Performance tests and timeout validation

📖 DOCUMENTATION & EXAMPLES:
- Updated API endpoints overview marking endpoints as implemented
- Comprehensive CLI reference with usage examples
- Removed endpoints from unimplemented list
- Updated wiki implementation plan status
- Complete example applications with README guides
- Real-world usage patterns and best practices

 KEY FEATURES:
- Service health monitoring and diagnostics
- Recently played content discovery and analysis
- Preset candidate identification
- Content statistics and usage analytics
- Time-based filtering and relative timestamps
- Rich emoji-based CLI output formatting
- Cross-service compatibility and error handling

This implements two critical missing endpoints from the SoundTouch API,
providing essential functionality for music service management and
recently played content analysis with full programmatic and CLI access.
2026-02-02 16:26:40 +01:00

5.0 KiB

Introspect Endpoint Example

This example demonstrates how to use the /introspect endpoint to get detailed information about music service states and capabilities on your SoundTouch device.

What is the Introspect Endpoint?

The introspect endpoint provides detailed information about music services (like Spotify, Pandora, TuneIn) including:

  • Service State: Active, Inactive, or InactiveUnselected
  • User Information: Associated account names
  • Playback Status: Currently playing content and URIs
  • Service Capabilities: Skip, seek, resume support
  • Token Information: Authentication token status
  • Content History: History size limits
  • Subscription Details: Premium/free account status

Usage

# Basic usage - check Spotify status
go run main.go -host 192.168.1.100

# Check specific service with account
go run main.go -host 192.168.1.100 -source SPOTIFY -account "your_spotify_username"

# Check Pandora service
go run main.go -host 192.168.1.100 -source PANDORA

# Check TuneIn radio
go run main.go -host 192.168.1.100 -source TUNEIN

# Custom timeout
go run main.go -host 192.168.1.100 -timeout 5s

Command Line Options

  • -host - Required: SoundTouch device IP address
  • -source - Music service to introspect (default: SPOTIFY)
    • Supported: SPOTIFY, PANDORA, TUNEIN, AMAZON, DEEZER, etc.
  • -account - Source account name (optional)
  • -timeout - Request timeout (default: 10s)

Example Output

Getting introspect data for SPOTIFY

=== SPOTIFY Service Introspect Data ===
State: InactiveUnselected
User: SpotifyConnectUserName
Currently Playing: false
Current Content: 
Shuffle Mode: OFF
Subscription Type: 

=== Service State ===
❌ Service is INACTIVE

=== Service Capabilities ===
❌ Skip Previous not supported
❌ Seek not supported
✅ Resume supported
✅ Data collection enabled

=== Content History ===
Max History Size: 10 items

=== Technical Details ===
Token Last Changed: 1702566495 seconds
Token Microseconds: 427884
Play Status State: 2
Received Playback Request: false

=== Service Availability Check ===
✅ Spotify is available on this device

Done!

Understanding the Output

Service States

  • Active: Service is currently selected and active
  • Inactive: Service is available but not currently active
  • InactiveUnselected: Service is available but never been used

Capabilities

  • Skip Previous: Can skip to previous track
  • Seek: Can seek within tracks (scrub timeline)
  • Resume: Can resume paused playback
  • Data Collection: Service collects usage analytics

Technical Fields

  • Token Last Changed: Unix timestamp of last authentication
  • Play Status State: Internal playback state code
  • Current URI: Unique identifier for currently playing content

Common Use Cases

1. Check if Spotify is Logged In

response, err := client.Introspect("SPOTIFY", "")
if err != nil {
    log.Fatal(err)
}

if response.HasUser() && response.IsActive() {
    fmt.Println("Spotify is logged in and active")
} else {
    fmt.Println("Spotify needs authentication or activation")
}

2. Verify Service Capabilities Before Playback Control

response, err := client.IntrospectSpotify("")
if err != nil {
    log.Fatal(err)
}

if response.SupportsSeek() {
    // Safe to use seek controls
    fmt.Println("Seek controls available")
}

if response.SupportsSkipPrevious() {
    // Safe to use previous track
    fmt.Println("Previous track control available")
}

3. Monitor Service Health

response, err := client.Introspect("PANDORA", "my_pandora_user")
if err != nil {
    log.Fatal(err)
}

if !response.IsActive() {
    fmt.Println("Pandora service needs activation")
}

if response.HasSubscription() {
    fmt.Printf("Premium account: %s\n", response.SubscriptionType)
}
  • client.GetServiceAvailability() - Check which services are available
  • client.SelectSource(source, account) - Activate a music service
  • client.GetNowPlaying() - Get current playback information

Error Handling

The introspect endpoint may fail if:

  • Service is not supported on the device
  • Invalid source name provided
  • Network connectivity issues
  • Device is in standby mode

Always check for errors and handle gracefully:

response, err := client.Introspect("SPOTIFY", "")
if err != nil {
    if strings.Contains(err.Error(), "failed to get introspect data") {
        fmt.Println("Service may not be configured or available")
        return
    }
    log.Fatal(err)
}

Integration with Other Examples

This introspect data is useful before:

API Documentation

For complete API documentation, see: