@@ -74,6 +74,14 @@ type SubsonicDirectory struct {
74
74
Entities SubsonicEntities `json:"child"`
75
75
}
76
76
77
+ type SubsonicSongs struct {
78
+ Song SubsonicEntities `json:"song"`
79
+ }
80
+
81
+ type SubsonicStarred struct {
82
+ Starred SubsonicEntities `json:"starred"`
83
+ }
84
+
77
85
type SubsonicEntity struct {
78
86
Id string `json:"id"`
79
87
IsDirectory bool `json:"isDir"`
@@ -130,13 +138,15 @@ type SubsonicPlaylist struct {
130
138
}
131
139
132
140
type SubsonicResponse struct {
133
- Status string `json:"status"`
134
- Version string `json:"version"`
135
- Indexes SubsonicIndexes `json:"indexes"`
136
- Directory SubsonicDirectory `json:"directory"`
137
- Playlists SubsonicPlaylists `json:"playlists"`
138
- Playlist SubsonicPlaylist `json:"playlist"`
139
- Error SubsonicError `json:"error"`
141
+ Status string `json:"status"`
142
+ Version string `json:"version"`
143
+ Indexes SubsonicIndexes `json:"indexes"`
144
+ Directory SubsonicDirectory `json:"directory"`
145
+ RandomSongs SubsonicSongs `json:"randomSongs"`
146
+ Starred SubsonicSongs `json:"starred"`
147
+ Playlists SubsonicPlaylists `json:"playlists"`
148
+ Playlist SubsonicPlaylist `json:"playlist"`
149
+ Error SubsonicError `json:"error"`
140
150
}
141
151
142
152
type responseWrapper struct {
@@ -192,6 +202,52 @@ func (connection *SubsonicConnection) GetMusicDirectory(id string) (*SubsonicRes
192
202
return resp , nil
193
203
}
194
204
205
+ func (connection * SubsonicConnection ) GetRandomSongs () (* SubsonicResponse , error ) {
206
+ query := defaultQuery (connection )
207
+ // Let's get 50 random songs, default is 10
208
+ query .Set ("size" , "50" )
209
+ requestUrl := connection .Host + "/rest/getRandomSongs" + "?" + query .Encode ()
210
+ resp , err := connection .getResponse ("GetRandomSongs" , requestUrl )
211
+ if err != nil {
212
+ return resp , err
213
+ }
214
+ return resp , nil
215
+ }
216
+
217
+ func (connection * SubsonicConnection ) GetStarred () (* SubsonicResponse , error ) {
218
+ query := defaultQuery (connection )
219
+ requestUrl := connection .Host + "/rest/getStarred" + "?" + query .Encode ()
220
+ resp , err := connection .getResponse ("GetStarred" , requestUrl )
221
+ if err != nil {
222
+ return resp , err
223
+ }
224
+ return resp , nil
225
+ }
226
+
227
+ func (connection * SubsonicConnection ) ToggleStar (id string , starredItems map [string ]struct {}) (* SubsonicResponse , error ) {
228
+ query := defaultQuery (connection )
229
+ query .Set ("id" ,id )
230
+
231
+ _ , ok := starredItems [id ]
232
+ var action = "star"
233
+ // If the key exists, we're unstarring
234
+ if ok {
235
+ action = "unstar"
236
+ }
237
+
238
+ requestUrl := connection .Host + "/rest/" + action + "?" + query .Encode ()
239
+ resp , err := connection .getResponse ("ToggleStar" , requestUrl )
240
+ if err != nil {
241
+ if (ok ) {
242
+ delete (starredItems , id )
243
+ } else {
244
+ starredItems [id ] = struct {}{}
245
+ }
246
+ return resp , err
247
+ }
248
+ return resp , nil
249
+ }
250
+
195
251
func (connection * SubsonicConnection ) GetPlaylists () (* SubsonicResponse , error ) {
196
252
query := defaultQuery (connection )
197
253
requestUrl := connection .Host + "/rest/getPlaylists" + "?" + query .Encode ()
0 commit comments