-
Notifications
You must be signed in to change notification settings - Fork 14
/
playlist.go
76 lines (70 loc) · 2.49 KB
/
playlist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package subsonic
import "errors"
// GetPlaylists returns all playlists a user is allowed to play.
//
// Optional Parameters:
// user: get playlists visible to this username rather than the current user. Must have admin permission.
func (s *Client) GetPlaylists(parameters map[string]string) ([]*Playlist, error) {
resp, err := s.Get("getPlaylists", parameters)
if err != nil {
return nil, err
}
return resp.Playlists.Playlist, nil
}
// GetPlaylist returns a listing of files in a saved playlist.
func (s *Client) GetPlaylist(id string) (*Playlist, error) {
resp, err := s.Get("getPlaylist", map[string]string{"id": id})
if err != nil {
return nil, err
}
return resp.Playlist, nil
}
// CreatePlaylist creates (or updates) a playlist.
//
// Optional Parameters:
// songId: ID of a song in the playlist. Use one songId parameter for each song in the playlist.
// Mutually Exclusive Parameters:
// playlistId: The playlist ID.
// name: The human-readable name of the playlist.
//
// This returns a Playlist object in Subsonic > 1.14.0, so it cannot consistently return a *Playlist
func (s *Client) CreatePlaylist(parameters map[string]string) error {
_, idPresent := parameters["playlistId"]
_, namePresent := parameters["name"]
if !(idPresent || namePresent) {
return errors.New("One of name or playlistId is mandatory, to create or update a playlist respectively")
}
_, err := s.Get("createPlaylist", parameters)
if err != nil {
return err
}
return nil
}
// UpdatePlaylist updates a playlist. Only the owner of a playlist is allowed to update it.
//
// Optional Parameters:
// name: The human-readable name of the playlist.
// comment: The playlist comment.
// public: true if the playlist should be visible to all users, false otherwise.
// songIdToAdd: Add this song with this ID to the playlist. Multiple parameters allowed.
// songIndexToRemove: Remove the song at this position in the playlist. Multiple parameters allowed.
func (s *Client) UpdatePlaylist(playlistId string, parameters map[string]string) error {
params := make(map[string]string)
for k, v := range parameters {
params[k] = v
}
params["playlistId"] = playlistId
_, err := s.Get("updatePlaylist", params)
if err != nil {
return err
}
return nil
}
// DeletePlaylist deletes a saved playlist.
func (s *Client) DeletePlaylist(playlistId string) error {
_, err := s.Get("deletePlaylist", map[string]string{"id": playlistId})
if err != nil {
return err
}
return nil
}