Playlists working
This commit is contained in:
@@ -32,3 +32,50 @@ func (c *PlaylistsController) GetAll() {
|
||||
response.Playlists = &responses.Playlists{Playlist: playlists}
|
||||
c.SendResponse(response)
|
||||
}
|
||||
|
||||
func (c *PlaylistsController) Get() {
|
||||
id := c.RequiredParamString("id", "id parameter required")
|
||||
|
||||
pinfo, err := c.pls.Get(id)
|
||||
switch {
|
||||
case err == engine.DataNotFound:
|
||||
beego.Error(err, "Id:", id)
|
||||
c.SendError(responses.ERROR_DATA_NOT_FOUND, "Directory not found")
|
||||
case err != nil:
|
||||
beego.Error(err)
|
||||
c.SendError(responses.ERROR_GENERIC, "Internal Error")
|
||||
}
|
||||
|
||||
response := c.NewEmpty()
|
||||
response.Playlist = c.buildPlaylist(pinfo)
|
||||
c.SendResponse(response)
|
||||
}
|
||||
|
||||
func (c *PlaylistsController) buildPlaylist(d *engine.PlaylistInfo) *responses.PlaylistWithSongs {
|
||||
pls := &responses.PlaylistWithSongs{}
|
||||
pls.Id = d.Id
|
||||
pls.Name = d.Name
|
||||
|
||||
pls.Entry = make([]responses.Child, len(d.Entries))
|
||||
for i, child := range d.Entries {
|
||||
pls.Entry[i].Id = child.Id
|
||||
pls.Entry[i].Title = child.Title
|
||||
pls.Entry[i].IsDir = child.IsDir
|
||||
pls.Entry[i].Parent = child.Parent
|
||||
pls.Entry[i].Album = child.Album
|
||||
pls.Entry[i].Year = child.Year
|
||||
pls.Entry[i].Artist = child.Artist
|
||||
pls.Entry[i].Genre = child.Genre
|
||||
pls.Entry[i].CoverArt = child.CoverArt
|
||||
pls.Entry[i].Track = child.Track
|
||||
pls.Entry[i].Duration = child.Duration
|
||||
pls.Entry[i].Size = child.Size
|
||||
pls.Entry[i].Suffix = child.Suffix
|
||||
pls.Entry[i].BitRate = child.BitRate
|
||||
pls.Entry[i].ContentType = child.ContentType
|
||||
if !child.Starred.IsZero() {
|
||||
pls.Entry[i].Starred = &child.Starred
|
||||
}
|
||||
}
|
||||
return pls
|
||||
}
|
||||
|
||||
+17
-11
@@ -6,17 +6,18 @@ import (
|
||||
)
|
||||
|
||||
type Subsonic struct {
|
||||
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
|
||||
Status string `xml:"status,attr" json:"status"`
|
||||
Version string `xml:"version,attr" json:"version"`
|
||||
Error *Error `xml:"error,omitempty" json:"error,omitempty"`
|
||||
License *License `xml:"license,omitempty" json:"license,omitempty"`
|
||||
MusicFolders *MusicFolders `xml:"musicFolders,omitempty" json:"musicFolders,omitempty"`
|
||||
Indexes *Indexes `xml:"indexes,omitempty" json:"indexes,omitempty"`
|
||||
Directory *Directory `xml:"directory,omitempty" json:"directory,omitempty"`
|
||||
User *User `xml:"user,omitempty" json:"user,omitempty"`
|
||||
AlbumList *AlbumList `xml:"albumList,omitempty" json:"albumList,omitempty"`
|
||||
Playlists *Playlists `xml:"playlists,omitempty" json:"playlists,omitempty"`
|
||||
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
|
||||
Status string `xml:"status,attr" json:"status"`
|
||||
Version string `xml:"version,attr" json:"version"`
|
||||
Error *Error `xml:"error,omitempty" json:"error,omitempty"`
|
||||
License *License `xml:"license,omitempty" json:"license,omitempty"`
|
||||
MusicFolders *MusicFolders `xml:"musicFolders,omitempty" json:"musicFolders,omitempty"`
|
||||
Indexes *Indexes `xml:"indexes,omitempty" json:"indexes,omitempty"`
|
||||
Directory *Directory `xml:"directory,omitempty" json:"directory,omitempty"`
|
||||
User *User `xml:"user,omitempty" json:"user,omitempty"`
|
||||
AlbumList *AlbumList `xml:"albumList,omitempty" json:"albumList,omitempty"`
|
||||
Playlists *Playlists `xml:"playlists,omitempty" json:"playlists,omitempty"`
|
||||
Playlist *PlaylistWithSongs `xml:"playlist,omitempty" json:"playlist,omitempty"`
|
||||
}
|
||||
|
||||
type JsonWrapper struct {
|
||||
@@ -111,6 +112,11 @@ type Playlists struct {
|
||||
Playlist []Playlist `xml:"playlist" json:"playlist,omitempty"`
|
||||
}
|
||||
|
||||
type PlaylistWithSongs struct {
|
||||
Playlist
|
||||
Entry []Child `xml:"entry" json:"entry,omitempty"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Username string `xml:"username,attr" json:"username"`
|
||||
Email string `xml:"email,attr,omitempty" json:"email,omitempty"`
|
||||
|
||||
@@ -199,6 +199,30 @@ func TestSubsonicResponses(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Playlist", func() {
|
||||
response.Playlist = &PlaylistWithSongs{}
|
||||
response.Playlist.Id = "1"
|
||||
response.Playlist.Name = "My Playlist"
|
||||
Convey("Without data", func() {
|
||||
Convey("XML", func() {
|
||||
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><playlist id="1" name="My Playlist"></playlist></subsonic-response>`)
|
||||
})
|
||||
Convey("JSON", func() {
|
||||
So(response, ShouldMatchJSON, `{"playlist":{"id":"1","name":"My Playlist"},"status":"ok","version":"1.0.0"}`)
|
||||
})
|
||||
})
|
||||
Convey("With just required data", func() {
|
||||
entry := make([]Child, 1)
|
||||
entry[0] = Child{Id: "1", Title: "title", IsDir: false}
|
||||
response.Playlist.Entry = entry
|
||||
Convey("XML", func() {
|
||||
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><playlist id="1" name="My Playlist"><entry id="1" isDir="false" title="title"></entry></playlist></subsonic-response>`)
|
||||
})
|
||||
Convey("JSON", func() {
|
||||
So(response, ShouldMatchJSON, `{"playlist":{"entry":[{"id":"1","isDir":false,"title":"title"}],"id":"1","name":"My Playlist"},"status":"ok","version":"1.0.0"}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reset(func() {
|
||||
response = &Subsonic{Status: "ok", Version: "1.0.0"}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user