Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.58 KB | None | 0 0
  1. diff --git a/api/player.go b/api/player.go
  2. index e54910e..e29fb17 100644
  3. --- a/api/player.go
  4. +++ b/api/player.go
  5. @@ -43,6 +43,13 @@ type PlayerOptions struct {
  6.     URIs       []string             `json:"uris,omitempty" url:"uris,omitempty"`
  7.     Offset     *PlayerOffsetOptions `json:"offset,omitempty" url:"offset,omitempty"`
  8.  }
  9. +// The PlayerOptions struct describes options that are specific to the /me/player endpoints
  10. +type PlayerOptions2 struct {
  11. +   DeviceID   []string               `json:"device_ids,omitempty" url:"device_ids,omitempty"`
  12. +   ContextURI string               `json:"context_uri,omitempty" url:"context_uri,omitempty"`
  13. +   URIs       []string             `json:"uris,omitempty" url:"uris,omitempty"`
  14. +   Offset     *PlayerOffsetOptions `json:"offset,omitempty" url:"offset,omitempty"`
  15. +}
  16.  
  17.  // The PlayerOffsetOptions describes how to set the offset within a context when controlling playback
  18.  // 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
  19. @@ -190,6 +197,36 @@ func StartPlayback(opts *PlayerOptions) error {
  20.     return err
  21.  }
  22.  
  23. +// TransferPlayback can resume playback or change playback to a new URI/context
  24. +func TransferPlayback(opts *PlayerOptions2) error {
  25. +   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
  26. +
  27. +   if err != nil {
  28. +       return err
  29. +   }
  30. +
  31. +   j, err := json.Marshal(opts)
  32. +
  33. +   if err != nil {
  34. +       log.Fatal("fatal", err)
  35. +   }
  36. +
  37. +   b := bytes.NewBuffer(j)
  38. +
  39. +   t := getAccessToken()
  40. +
  41. +   r := buildRequest("PUT", apiURLBase+"me/player", v, b)
  42. +   r.Header.Add("Authorization", "Bearer "+t)
  43. +
  44. +   err = makeRequest(r, nil)
  45. +   // TODO: Handle error here
  46. +   if err != nil {
  47. +       log.Fatal("fatal", err)
  48. +   }
  49. +
  50. +   return err
  51. +}
  52. +
  53.  // SkipToNext skips to the next song within the current context
  54.  func SkipToNext(opts *Options) error {
  55.     v, err := query.Values(opts)
  56. diff --git a/cmd/transfer.go b/cmd/transfer.go
  57. index beae37e..5d46a8b 100644
  58. --- a/cmd/transfer.go
  59. +++ b/cmd/transfer.go
  60. @@ -8,8 +8,9 @@ import (
  61.  )
  62.  
  63.  func transferDevice(cmd *cobra.Command, args []string) {
  64. -   p := api.PlayerOptions{DeviceID: args[0]}
  65. -   err := api.StartPlayback(&p)
  66. +   deviceid := []string{args[0]}
  67. +   p := api.PlayerOptions2{DeviceID: deviceid}
  68. +   err := api.TransferPlayback(&p)
  69.  
  70.     if err != nil {
  71.         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