Documentation
¶
Index ¶
- Constants
- Variables
- func Base62ToGid(id string) ([]byte, error)
- func Convert62(id string) []byte
- func ConvertTo62(raw []byte) string
- func GenerateDeviceId() string
- func GetCpuFamily() spotifypb.CpuFamily
- func GetOS() spotifypb.Os
- func GetPlatform() spotifypb.Platform
- func GetPlatformSpecificData() *clienttokenpb.PlatformSpecificData
- func GidToBase62(id []byte) string
- func ObfuscateUsername(username string) string
- func SaveState(path string, state *AppState) error
- func SpotifyLikeClientVersion() string
- func SystemInfoString() string
- func UserAgent() string
- func VersionNumberString() string
- func VersionString() string
- type AppState
- type DeviceType
- type GetAddressFunc
- type GetLogin5TokenFunc
- type Logger
- type NullLogger
- func (l *NullLogger) Debug(...interface{})
- func (l *NullLogger) Debugf(string, ...interface{})
- func (l *NullLogger) Error(...interface{})
- func (l *NullLogger) Errorf(string, ...interface{})
- func (l *NullLogger) Info(...interface{})
- func (l *NullLogger) Infof(string, ...interface{})
- func (l *NullLogger) Trace(...interface{})
- func (l *NullLogger) Tracef(string, ...interface{})
- func (l *NullLogger) Warn(...interface{})
- func (l *NullLogger) Warnf(string, ...interface{})
- func (l *NullLogger) WithError(error) Logger
- func (l *NullLogger) WithField(string, interface{}) Logger
- type SpotifyId
- type SpotifyIdType
Constants ¶
const ( DeviceTypeComputer = devicespb.DeviceType_COMPUTER DeviceTypeTablet = devicespb.DeviceType_TABLET DeviceTypeSmartphone = devicespb.DeviceType_SMARTPHONE DeviceTypeSpeaker = devicespb.DeviceType_SPEAKER DeviceTypeTV = devicespb.DeviceType_TV DeviceTypeAVR = devicespb.DeviceType_AVR DeviceTypeSTB = devicespb.DeviceType_STB DeviceTypeAudioDongle = devicespb.DeviceType_AUDIO_DONGLE DeviceTypeGameConsole = devicespb.DeviceType_GAME_CONSOLE DeviceTypeCastVideo = devicespb.DeviceType_CAST_VIDEO DeviceTypeCastAudio = devicespb.DeviceType_CAST_AUDIO DeviceTypeAutomobile = devicespb.DeviceType_AUTOMOBILE DeviceTypeSmartwatch = devicespb.DeviceType_SMARTWATCH DeviceTypeChromebook = devicespb.DeviceType_CHROMEBOOK DeviceTypeCarThing = devicespb.DeviceType_CAR_THING )
Device type constants re-exported from the protobuf package for convenience. Users can use these instead of importing the deeply nested protobuf package directly. For example:
spotcontrol.DeviceTypeComputer
is equivalent to:
devicespb.DeviceType_COMPUTER
const SpotifyVersionCode = 127700358
SpotifyVersionCode is the version code sent during AP key exchange.
Variables ¶
var ClientId = []byte{0x65, 0xb7, 0x08, 0x07, 0x3f, 0xc0, 0x48, 0x0e, 0xa9, 0x2a, 0x07, 0x72, 0x33, 0xca, 0x87, 0xbd}
ClientId is the Spotify client ID used for authentication. This is the well-known client ID used by official Spotify clients.
var ClientIdHex = hex.EncodeToString(ClientId)
ClientIdHex is the hex-encoded string representation of the client ID.
var UriRegexp = regexp.MustCompile(`^spotify:([a-z]+):([0-9a-zA-Z]{21,22})$`)
UriRegexp matches Spotify URIs in the form spotify:type:id.
Functions ¶
func Base62ToGid ¶
Base62ToGid converts a base62-encoded string to a 16-byte GID.
func Convert62 ¶
Convert62 converts a base62-encoded Spotify ID string to raw bytes. This is a legacy helper; prefer Base62ToGid for new code.
func ConvertTo62 ¶
ConvertTo62 converts raw bytes to a base62-encoded Spotify ID string, zero-padded to 22 characters. This is a legacy helper; prefer GidToBase62 for new code.
func GenerateDeviceId ¶
func GenerateDeviceId() string
GenerateDeviceId generates a random 40-character hex string (20 random bytes) suitable for use as a Spotify device identifier. It uses crypto/rand for cryptographically secure random bytes.
The returned string is guaranteed to be exactly 40 lowercase hex characters, which is the format required by session.Options.DeviceId.
func GetCpuFamily ¶
GetCpuFamily returns the protobuf CpuFamily enum corresponding to the current CPU architecture.
func GetPlatform ¶
GetPlatform returns the protobuf Platform enum corresponding to the current OS/arch combination.
func GetPlatformSpecificData ¶
func GetPlatformSpecificData() *clienttokenpb.PlatformSpecificData
GetPlatformSpecificData returns the platform-specific data protobuf used when retrieving client tokens.
func GidToBase62 ¶
GidToBase62 converts a raw 16-byte GID to a base62-encoded string, zero-padded to 22 characters.
func ObfuscateUsername ¶
ObfuscateUsername returns an obfuscated version of a username for logging.
func SaveState ¶
SaveState writes an AppState as pretty-printed JSON to the given path with file mode 0600 (owner read/write only) to protect credentials.
func SpotifyLikeClientVersion ¶
func SpotifyLikeClientVersion() string
SpotifyLikeClientVersion returns a version string formatted like official Spotify clients.
func SystemInfoString ¶
func SystemInfoString() string
SystemInfoString returns a system information string for use in protobuf fields.
func UserAgent ¶
func UserAgent() string
UserAgent returns the HTTP User-Agent string for spotcontrol requests.
func VersionNumberString ¶
func VersionNumberString() string
VersionNumberString returns the version number as a string. If set via ldflags, it returns that value (without leading "v"). Otherwise, it returns the first 8 characters of the commit hash, or "dev".
func VersionString ¶
func VersionString() string
VersionString returns the full version string including the project name.
Types ¶
type AppState ¶
type AppState struct {
// DeviceId is the unique device identifier for this controller instance.
DeviceId string `json:"device_id"`
// Username is the authenticated Spotify username.
Username string `json:"username,omitempty"`
// StoredCredentials is the reusable auth credential data from APWelcome.
StoredCredentials []byte `json:"stored_credentials,omitempty"`
// OAuthAccessToken is the OAuth2 access token for the Spotify Web API.
OAuthAccessToken string `json:"oauth_access_token,omitempty"`
// OAuthRefreshToken is the OAuth2 refresh token used to obtain new access
// tokens when the current one expires.
OAuthRefreshToken string `json:"oauth_refresh_token,omitempty"`
// OAuthTokenType is the token type (typically "Bearer").
OAuthTokenType string `json:"oauth_token_type,omitempty"`
// OAuthExpiry is the time at which the access token expires.
OAuthExpiry time.Time `json:"oauth_expiry,omitempty"`
}
AppState holds persisted state across sessions.
func LoadState ¶
LoadState reads an AppState from a JSON file at the given path. If the file does not exist, it returns (nil, nil) — not an error — so callers can treat a missing file as "no prior state" without extra checks.
func (*AppState) HasOAuthToken ¶
HasOAuthToken returns true if the AppState contains a persisted OAuth2 token (at minimum an access token or a refresh token).
type DeviceType ¶
type DeviceType = devicespb.DeviceType
DeviceType is a type alias for the protobuf DeviceType enum. Using a type alias (=) rather than a new type means these constants are fully interchangeable with devicespb.DeviceType values — existing code that uses the protobuf constants directly continues to compile without changes.
type GetAddressFunc ¶
GetAddressFunc is a function that returns a different address for a type of endpoint each time it is called, rotating through available addresses.
type GetLogin5TokenFunc ¶
GetLogin5TokenFunc is a function that returns an access token from Login5. If force is true, a new token will be obtained even if the current one hasn't expired.
type Logger ¶
type Logger interface {
Tracef(format string, args ...interface{})
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Trace(args ...interface{})
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
WithField(key string, value interface{}) Logger
WithError(err error) Logger
}
Logger is the interface used throughout spotcontrol for structured logging. It is compatible with logrus.Entry and similar structured loggers.
func NewSimpleLogger ¶
NewSimpleLogger returns a Logger that writes human-readable log lines to w. If w is nil, os.Stderr is used. Trace-level messages are suppressed.
This is intended as a convenient default for quick prototyping and examples. For production use, consider NewSlogLogger or a custom Logger implementation.
func NewSlogLogger ¶
NewSlogLogger returns a Logger that delegates to the provided *slog.Logger. Trace-level messages are mapped to slog.LevelDebug-4 (below Debug). Debug, Info, Warn, and Error map to their slog equivalents. WithField and WithError return new loggers with the additional attributes.
If l is nil, slog.Default() is used.
type NullLogger ¶
type NullLogger struct{}
NullLogger is a Logger implementation that discards all output.
func (*NullLogger) Debug ¶
func (l *NullLogger) Debug(...interface{})
func (*NullLogger) Debugf ¶
func (l *NullLogger) Debugf(string, ...interface{})
func (*NullLogger) Error ¶
func (l *NullLogger) Error(...interface{})
func (*NullLogger) Errorf ¶
func (l *NullLogger) Errorf(string, ...interface{})
func (*NullLogger) Info ¶
func (l *NullLogger) Info(...interface{})
func (*NullLogger) Infof ¶
func (l *NullLogger) Infof(string, ...interface{})
func (*NullLogger) Trace ¶
func (l *NullLogger) Trace(...interface{})
func (*NullLogger) Tracef ¶
func (l *NullLogger) Tracef(string, ...interface{})
func (*NullLogger) Warn ¶
func (l *NullLogger) Warn(...interface{})
func (*NullLogger) Warnf ¶
func (l *NullLogger) Warnf(string, ...interface{})
func (*NullLogger) WithError ¶
func (l *NullLogger) WithError(error) Logger
func (*NullLogger) WithField ¶
func (l *NullLogger) WithField(string, interface{}) Logger
type SpotifyId ¶
type SpotifyId struct {
// contains filtered or unexported fields
}
SpotifyId represents a Spotify resource identifier, consisting of a type and a 16-byte ID.
func SpotifyIdFromBase62 ¶
func SpotifyIdFromBase62(typ SpotifyIdType, id string) (*SpotifyId, error)
SpotifyIdFromBase62 creates a SpotifyId from a type and base62-encoded string.
func SpotifyIdFromGid ¶
func SpotifyIdFromGid(typ SpotifyIdType, id []byte) SpotifyId
SpotifyIdFromGid creates a SpotifyId from a type and raw 16-byte GID.
func SpotifyIdFromUri ¶
SpotifyIdFromUri parses a Spotify URI (e.g., "spotify:track:6rqhFgbbKwnb9MLmUQDhG6") and returns the corresponding SpotifyId.
func (SpotifyId) Base62 ¶
Base62 returns the base62-encoded string of the raw identifier, zero-padded to 22 characters.
func (SpotifyId) Type ¶
func (sid SpotifyId) Type() SpotifyIdType
Type returns the type of this Spotify ID (e.g., "track", "episode").
type SpotifyIdType ¶
type SpotifyIdType string
SpotifyIdType represents the type component of a Spotify URI.
const ( SpotifyIdTypeTrack SpotifyIdType = "track" SpotifyIdTypeEpisode SpotifyIdType = "episode" SpotifyIdTypeAlbum SpotifyIdType = "album" SpotifyIdTypeArtist SpotifyIdType = "artist" SpotifyIdTypePlaylist SpotifyIdType = "playlist" SpotifyIdTypeShow SpotifyIdType = "show" )
func InferSpotifyIdTypeFromContextUri ¶
func InferSpotifyIdTypeFromContextUri(uri string) SpotifyIdType
InferSpotifyIdTypeFromContextUri determines whether a context URI refers to episode/show content or track content.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
parsebuf
command
Command parsebuf decodes mitmproxy-captured HTTP request bodies from Spotify's connect-state player command endpoint:
|
Command parsebuf decodes mitmproxy-captured HTTP request bodies from Spotify's connect-state player command endpoint: |
|
examples
|
|
|
event-watcher
command
|
|
|
micro-controller
command
|
|
|
proto
|
|