Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/api/player.go b/api/player.go
- index e54910e..e29fb17 100644
- --- a/api/player.go
- +++ b/api/player.go
- @@ -43,6 +43,13 @@ type PlayerOptions struct {
- URIs []string `json:"uris,omitempty" url:"uris,omitempty"`
- Offset *PlayerOffsetOptions `json:"offset,omitempty" url:"offset,omitempty"`
- }
- +// The PlayerOptions struct describes options that are specific to the /me/player endpoints
- +type PlayerOptions2 struct {
- + DeviceID []string `json:"device_ids,omitempty" url:"device_ids,omitempty"`
- + ContextURI string `json:"context_uri,omitempty" url:"context_uri,omitempty"`
- + URIs []string `json:"uris,omitempty" url:"uris,omitempty"`
- + Offset *PlayerOffsetOptions `json:"offset,omitempty" url:"offset,omitempty"`
- +}
- // The PlayerOffsetOptions describes how to set the offset within a context when controlling playback
- // For example, you can use Position to specify track number within an album OR you can use the URI to point to that same track directly
- @@ -190,6 +197,36 @@ func StartPlayback(opts *PlayerOptions) error {
- return err
- }
- +// TransferPlayback can resume playback or change playback to a new URI/context
- +func TransferPlayback(opts *PlayerOptions2) error {
- + v, err := query.Values(nil) // Don't pass anything here because if we do and we start playback with a large list URIs they will be put in the query string and give us an error
- +
- + if err != nil {
- + return err
- + }
- +
- + j, err := json.Marshal(opts)
- +
- + if err != nil {
- + log.Fatal("fatal", err)
- + }
- +
- + b := bytes.NewBuffer(j)
- +
- + t := getAccessToken()
- +
- + r := buildRequest("PUT", apiURLBase+"me/player", v, b)
- + r.Header.Add("Authorization", "Bearer "+t)
- +
- + err = makeRequest(r, nil)
- + // TODO: Handle error here
- + if err != nil {
- + log.Fatal("fatal", err)
- + }
- +
- + return err
- +}
- +
- // SkipToNext skips to the next song within the current context
- func SkipToNext(opts *Options) error {
- v, err := query.Values(opts)
- diff --git a/cmd/transfer.go b/cmd/transfer.go
- index beae37e..5d46a8b 100644
- --- a/cmd/transfer.go
- +++ b/cmd/transfer.go
- @@ -8,8 +8,9 @@ import (
- )
- func transferDevice(cmd *cobra.Command, args []string) {
- - p := api.PlayerOptions{DeviceID: args[0]}
- - err := api.StartPlayback(&p)
- + deviceid := []string{args[0]}
- + p := api.PlayerOptions2{DeviceID: deviceid}
- + err := api.TransferPlayback(&p)
- if err != nil {
- fmt.Printf("Couldn't transfer playback. Is the device ID supplied correct? Is Spotify active on that device? Have you authenticated with the 'auth' command?\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement