Supporting starred in getMusicDirectory.view

This commit is contained in:
Deluan 2016-03-03 15:41:24 -05:00
parent cc31366cc1
commit 848809d0df
4 changed files with 37 additions and 22 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject"
"time"
)
type GetMusicDirectoryController struct {
@ -54,6 +55,11 @@ func (c *GetMusicDirectoryController) buildArtistDir(a *domain.Artist, albums []
dir.Child[i].Artist = al.Artist
dir.Child[i].Genre = al.Genre
dir.Child[i].CoverArt = al.CoverArtId
if al.Starred {
t := time.Now()
dir.Child[i].Starred = &t
}
}
return dir
}
@ -75,6 +81,9 @@ func (c *GetMusicDirectoryController) buildAlbumDir(al *domain.Album, tracks []d
dir.Child[i].Size = mf.Size
dir.Child[i].Suffix = mf.Suffix
dir.Child[i].BitRate = mf.BitRate
if mf.Starred {
dir.Child[i].Starred = &mf.UpdatedAt
}
if mf.HasCoverArt {
dir.Child[i].CoverArt = mf.Id
}

View File

@ -1,6 +1,9 @@
package responses
import "encoding/xml"
import (
"encoding/xml"
"time"
)
type Subsonic struct {
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
@ -19,7 +22,7 @@ type JsonWrapper struct {
type Error struct {
Code int `xml:"code,attr" json:"code"`
Message string `xml:"message,attr" json: "message"`
Message string `xml:"message,attr" json:"message"`
}
type License struct {
@ -52,22 +55,23 @@ type Indexes struct {
}
type Child struct {
Id string `xml:"id,attr" json:"id"`
IsDir bool `xml:"isDir,attr" json:"isDir"`
Title string `xml:"title,attr" json:"title"`
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Size string `xml:"size,attr,omitempty" json:"size,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
TranscodedContentType string `xml:"transcodedContentType,attr,omitempty" json:"transcodedContentType,omitempty"`
TranscodedSuffix string `xml:"transcodedSuffix,attr,omitempty" json:"transcodedSuffix,omitempty"`
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
Id string `xml:"id,attr" json:"id"`
IsDir bool `xml:"isDir,attr" json:"isDir"`
Title string `xml:"title,attr" json:"title"`
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Size string `xml:"size,attr,omitempty" json:"size,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
TranscodedContentType string `xml:"transcodedContentType,attr,omitempty" json:"transcodedContentType,omitempty"`
TranscodedSuffix string `xml:"transcodedSuffix,attr,omitempty" json:"transcodedSuffix,omitempty"`
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
}
type Directory struct {

View File

@ -5,6 +5,7 @@ import (
. "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
"time"
)
func TestSubsonicResponses(t *testing.T) {
@ -106,18 +107,19 @@ func TestSubsonicResponses(t *testing.T) {
})
Convey("With all data", func() {
child := make([]Child, 1)
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
child[0] = Child{
Id: "1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1,
Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac",
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
Duration: 146, BitRate: 320,
Duration: 146, BitRate: 320, Starred: &t,
}
response.Directory.Child = child
Convey("XML", func() {
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><child id="1" isDir="true" title="title" album="album" artist="artist" track="1" year="1985" genre="Rock" coverArt="1" size="8421341" contentType="audio/flac" suffix="flac" transcodedContentType="audio/mpeg" transcodedSuffix="mp3" duration="146" bitRate="320"></child></directory></subsonic-response>`)
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><child id="1" isDir="true" title="title" album="album" artist="artist" track="1" year="1985" genre="Rock" coverArt="1" size="8421341" contentType="audio/flac" suffix="flac" starred="2016-03-02T20:30:00Z" transcodedContentType="audio/mpeg" transcodedSuffix="mp3" duration="146" bitRate="320"></child></directory></subsonic-response>`)
})
Convey("JSON", func() {
So(response, ShouldMatchJSON, `{"directory":{"child":[{"album":"album","artist":"artist","bitRate":320,"contentType":"audio/flac","coverArt":"1","duration":146,"genre":"Rock","id":"1","isDir":true,"size":"8421341","suffix":"flac","title":"title","track":1,"transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","year":1985}],"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`)
So(response, ShouldMatchJSON, `{"directory":{"child":[{"album":"album","artist":"artist","bitRate":320,"contentType":"audio/flac","coverArt":"1","duration":146,"genre":"Rock","id":"1","isDir":true,"size":"8421341","starred":"2016-03-02T20:30:00Z","suffix":"flac","title":"title","track":1,"transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","year":1985}],"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`)
})
})
})

View File

@ -112,7 +112,7 @@ func parseTrack(t *Track) (*domain.MediaFile, *domain.Album, *domain.Artist) {
Name: t.Album,
Year: t.Year,
Compilation: t.Compilation,
Starred: t.Loved,
Starred: t.AlbumLoved,
Genre: t.Genre,
Artist: t.Artist,
AlbumArtist: t.AlbumArtist,