mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-09 20:02:22 +03:00
Supporting starred in getMusicDirectory.view
This commit is contained in:
parent
cc31366cc1
commit
848809d0df
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
"github.com/deluan/gosonic/utils"
|
"github.com/deluan/gosonic/utils"
|
||||||
"github.com/karlkfi/inject"
|
"github.com/karlkfi/inject"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetMusicDirectoryController struct {
|
type GetMusicDirectoryController struct {
|
||||||
@ -54,6 +55,11 @@ func (c *GetMusicDirectoryController) buildArtistDir(a *domain.Artist, albums []
|
|||||||
dir.Child[i].Artist = al.Artist
|
dir.Child[i].Artist = al.Artist
|
||||||
dir.Child[i].Genre = al.Genre
|
dir.Child[i].Genre = al.Genre
|
||||||
dir.Child[i].CoverArt = al.CoverArtId
|
dir.Child[i].CoverArt = al.CoverArtId
|
||||||
|
if al.Starred {
|
||||||
|
t := time.Now()
|
||||||
|
dir.Child[i].Starred = &t
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
@ -75,6 +81,9 @@ func (c *GetMusicDirectoryController) buildAlbumDir(al *domain.Album, tracks []d
|
|||||||
dir.Child[i].Size = mf.Size
|
dir.Child[i].Size = mf.Size
|
||||||
dir.Child[i].Suffix = mf.Suffix
|
dir.Child[i].Suffix = mf.Suffix
|
||||||
dir.Child[i].BitRate = mf.BitRate
|
dir.Child[i].BitRate = mf.BitRate
|
||||||
|
if mf.Starred {
|
||||||
|
dir.Child[i].Starred = &mf.UpdatedAt
|
||||||
|
}
|
||||||
if mf.HasCoverArt {
|
if mf.HasCoverArt {
|
||||||
dir.Child[i].CoverArt = mf.Id
|
dir.Child[i].CoverArt = mf.Id
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package responses
|
package responses
|
||||||
|
|
||||||
import "encoding/xml"
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Subsonic struct {
|
type Subsonic struct {
|
||||||
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
|
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
|
||||||
@ -19,7 +22,7 @@ type JsonWrapper struct {
|
|||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Code int `xml:"code,attr" json:"code"`
|
Code int `xml:"code,attr" json:"code"`
|
||||||
Message string `xml:"message,attr" json: "message"`
|
Message string `xml:"message,attr" json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type License struct {
|
type License struct {
|
||||||
@ -52,22 +55,23 @@ type Indexes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Child struct {
|
type Child struct {
|
||||||
Id string `xml:"id,attr" json:"id"`
|
Id string `xml:"id,attr" json:"id"`
|
||||||
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
||||||
Title string `xml:"title,attr" json:"title"`
|
Title string `xml:"title,attr" json:"title"`
|
||||||
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
||||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||||
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
|
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
|
||||||
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
|
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
|
||||||
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
||||||
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||||
Size string `xml:"size,attr,omitempty" json:"size,omitempty"`
|
Size string `xml:"size,attr,omitempty" json:"size,omitempty"`
|
||||||
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
|
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
|
||||||
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
|
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
|
||||||
TranscodedContentType string `xml:"transcodedContentType,attr,omitempty" json:"transcodedContentType,omitempty"`
|
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||||
TranscodedSuffix string `xml:"transcodedSuffix,attr,omitempty" json:"transcodedSuffix,omitempty"`
|
TranscodedContentType string `xml:"transcodedContentType,attr,omitempty" json:"transcodedContentType,omitempty"`
|
||||||
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
TranscodedSuffix string `xml:"transcodedSuffix,attr,omitempty" json:"transcodedSuffix,omitempty"`
|
||||||
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
|
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
||||||
|
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Directory struct {
|
type Directory struct {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
. "github.com/deluan/gosonic/tests"
|
. "github.com/deluan/gosonic/tests"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSubsonicResponses(t *testing.T) {
|
func TestSubsonicResponses(t *testing.T) {
|
||||||
@ -106,18 +107,19 @@ func TestSubsonicResponses(t *testing.T) {
|
|||||||
})
|
})
|
||||||
Convey("With all data", func() {
|
Convey("With all data", func() {
|
||||||
child := make([]Child, 1)
|
child := make([]Child, 1)
|
||||||
|
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
|
||||||
child[0] = Child{
|
child[0] = Child{
|
||||||
Id: "1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1,
|
Id: "1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1,
|
||||||
Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac",
|
Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac",
|
||||||
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
|
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
|
||||||
Duration: 146, BitRate: 320,
|
Duration: 146, BitRate: 320, Starred: &t,
|
||||||
}
|
}
|
||||||
response.Directory.Child = child
|
response.Directory.Child = child
|
||||||
Convey("XML", func() {
|
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() {
|
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"}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -112,7 +112,7 @@ func parseTrack(t *Track) (*domain.MediaFile, *domain.Album, *domain.Artist) {
|
|||||||
Name: t.Album,
|
Name: t.Album,
|
||||||
Year: t.Year,
|
Year: t.Year,
|
||||||
Compilation: t.Compilation,
|
Compilation: t.Compilation,
|
||||||
Starred: t.Loved,
|
Starred: t.AlbumLoved,
|
||||||
Genre: t.Genre,
|
Genre: t.Genre,
|
||||||
Artist: t.Artist,
|
Artist: t.Artist,
|
||||||
AlbumArtist: t.AlbumArtist,
|
AlbumArtist: t.AlbumArtist,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user