Skip to content

Commit

Permalink
Allow setting fixed device ID and client token
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed Oct 2, 2023
1 parent bed0f2a commit 82fa8e4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
25 changes: 17 additions & 8 deletions cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,22 @@ func NewApp(cfg *Config) (app *App, err error) {
return nil, err
}

// FIXME: make device id persistent
deviceIdBytes := make([]byte, 20)
_, _ = rand.Read(deviceIdBytes)
app.deviceId = hex.EncodeToString(deviceIdBytes)
if len(cfg.DeviceId) == 0 {
deviceIdBytes := make([]byte, 20)
_, _ = rand.Read(deviceIdBytes)
app.deviceId = hex.EncodeToString(deviceIdBytes)
log.Infof("generated new device id: %s", app.deviceId)
} else {
app.deviceId = cfg.DeviceId
}

// FIXME: make client token persistent
app.clientToken, err = retrieveClientToken(app.deviceId)
if err != nil {
return nil, fmt.Errorf("failed obtaining client token: %w", err)
if len(cfg.ClientToken) == 0 {
app.clientToken, err = retrieveClientToken(app.deviceId)
if err != nil {
return nil, fmt.Errorf("failed obtaining client token: %w", err)
}
} else {
app.clientToken = cfg.ClientToken
}

return app, nil
Expand Down Expand Up @@ -297,8 +304,10 @@ type Config struct {
CredentialsPath string `yaml:"-"`

LogLevel string `yaml:"log_level"`
DeviceId string `yaml:"device_id"`
DeviceName string `yaml:"device_name"`
DeviceType string `yaml:"device_type"`
ClientToken string `yaml:"client_token"`
ServerPort int `yaml:"server_port"`
AudioDevice string `yaml:"audio_device"`
Bitrate int `yaml:"bitrate"`
Expand Down
10 changes: 10 additions & 0 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
],
"default": "info"
},
"device_id": {
"type": "string",
"description": "The device ID in hex",
"minLength": 40,
"maxLength": 40
},
"device_name": {
"type": "string",
"description": "The device name showed in the Spotify UI",
Expand Down Expand Up @@ -50,6 +56,10 @@
],
"default": "computer"
},
"client_token": {
"type": "string",
"description": "The Spotify client token"
},
"audio_device": {
"type": "string",
"description": "Which audio device should be used for playback, leave empty for default",
Expand Down

0 comments on commit 82fa8e4

Please sign in to comment.