mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-24 07:30:57 +03:00
UserRatings for Albums and MediaFiles
This commit is contained in:
parent
5fd9da505e
commit
0b286afa08
api
engine
scanner
@ -113,5 +113,6 @@ func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
|
||||
n.AlbumId = entry.AlbumId
|
||||
n.ArtistId = entry.ArtistId
|
||||
n.Type = entry.Type
|
||||
n.UserRating = entry.UserRating
|
||||
return n
|
||||
}
|
||||
|
@ -84,10 +84,11 @@ func (c *BrowsingController) GetDirectory() {
|
||||
|
||||
func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.Directory {
|
||||
dir := &responses.Directory{
|
||||
Id: d.Id,
|
||||
Name: d.Name,
|
||||
Parent: d.Parent,
|
||||
PlayCount: d.PlayCount,
|
||||
Id: d.Id,
|
||||
Name: d.Name,
|
||||
Parent: d.Parent,
|
||||
PlayCount: d.PlayCount,
|
||||
UserRating: d.UserRating,
|
||||
}
|
||||
if !d.Starred.IsZero() {
|
||||
dir.Starred = &d.Starred
|
||||
|
@ -162,7 +162,7 @@ func TestGetMusicDirectory(t *testing.T) {
|
||||
mockAlbumRepo.SetData(`[{"Id":"A","Name":"Tardis","ArtistId":"1"}]`, 1)
|
||||
_, w := Get(AddParams("/rest/getMusicDirectory.view", "id=1"), "TestGetMusicDirectory")
|
||||
|
||||
So(w.Body, ShouldContainJSON, `"child":[{"album":"Tardis","id":"A","isDir":true,"parent":"1","title":"Tardis"}]`)
|
||||
So(w.Body, ShouldContainJSON, `"child":[{"album":"Tardis","albumId":"A","artistId":"1","id":"A","isDir":true,"parent":"1","title":"Tardis"}]`)
|
||||
})
|
||||
})
|
||||
Convey("When id matches an album with tracks", func() {
|
||||
@ -171,7 +171,7 @@ func TestGetMusicDirectory(t *testing.T) {
|
||||
mockMediaFileRepo.SetData(`[{"Id":"3","Title":"Cangote","AlbumId":"A"}]`, 1)
|
||||
_, w := Get(AddParams("/rest/getMusicDirectory.view", "id=A"), "TestGetMusicDirectory")
|
||||
|
||||
So(w.Body, ShouldContainJSON, `"child":[{"id":"3","isDir":false,"parent":"A","title":"Cangote"}]`)
|
||||
So(w.Body, ShouldContainJSON, `"child":[{"albumId":"A","id":"3","isDir":false,"parent":"A","title":"Cangote","type":"music"}]`)
|
||||
})
|
||||
Reset(func() {
|
||||
mockArtistRepo.SetData("[]", 0)
|
||||
|
@ -92,9 +92,9 @@ type Child struct {
|
||||
AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
||||
ArtistId string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||
Type string `xml:"type,attr,omitempty" json:"type,omitempty"`
|
||||
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||
/*
|
||||
<xs:attribute name="isVideo" type="xs:boolean" use="optional"/> <!-- Added in 1.4.1 -->
|
||||
<xs:attribute name="userRating" type="sub:UserRating" use="optional"/> <!-- Added in 1.6.0 -->
|
||||
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.6.0 -->
|
||||
<xs:attribute name="bookmarkPosition" type="xs:long" use="optional"/> <!-- In millis. Added in 1.10.1 -->
|
||||
<xs:attribute name="originalWidth" type="xs:int" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
@ -103,14 +103,14 @@ type Child struct {
|
||||
}
|
||||
|
||||
type Directory struct {
|
||||
Child []Child `xml:"child" json:"child,omitempty"`
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
|
||||
Child []Child `xml:"child" json:"child,omitempty"`
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
|
||||
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||
/*
|
||||
<xs:attribute name="userRating" type="sub:UserRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
*/
|
||||
}
|
||||
|
@ -54,12 +54,13 @@ func (b browser) Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.
|
||||
}
|
||||
|
||||
type DirectoryInfo struct {
|
||||
Id string
|
||||
Name string
|
||||
Entries Entries
|
||||
Parent string
|
||||
Starred time.Time
|
||||
PlayCount int32
|
||||
Id string
|
||||
Name string
|
||||
Entries Entries
|
||||
Parent string
|
||||
Starred time.Time
|
||||
PlayCount int32
|
||||
UserRating int
|
||||
}
|
||||
|
||||
func (c browser) Directory(id string) (*DirectoryInfo, error) {
|
||||
@ -100,10 +101,11 @@ func (c browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *Directo
|
||||
|
||||
func (c browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirectoryInfo {
|
||||
dir := &DirectoryInfo{
|
||||
Id: al.Id,
|
||||
Name: al.Name,
|
||||
Parent: al.ArtistId,
|
||||
PlayCount: int32(al.PlayCount),
|
||||
Id: al.Id,
|
||||
Name: al.Name,
|
||||
Parent: al.ArtistId,
|
||||
PlayCount: int32(al.PlayCount),
|
||||
UserRating: al.Rating,
|
||||
}
|
||||
if al.Starred {
|
||||
dir.Starred = al.UpdatedAt
|
||||
|
@ -31,6 +31,7 @@ type Entry struct {
|
||||
AlbumId string
|
||||
ArtistId string
|
||||
Type string
|
||||
UserRating int
|
||||
|
||||
UserName string
|
||||
MinutesAgo int
|
||||
@ -62,6 +63,7 @@ func FromAlbum(al *domain.Album) Entry {
|
||||
c.Created = al.CreatedAt
|
||||
c.AlbumId = al.Id
|
||||
c.ArtistId = al.ArtistId
|
||||
c.UserRating = al.Rating
|
||||
return c
|
||||
}
|
||||
|
||||
@ -94,5 +96,6 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
|
||||
c.AlbumId = mf.AlbumId
|
||||
c.ArtistId = mf.ArtistId
|
||||
c.Type = "music" // TODO Hardcoded for now
|
||||
c.UserRating = mf.Rating
|
||||
return c
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||
mf.Genre = unescape(t.Genre)
|
||||
mf.Compilation = t.Compilation
|
||||
mf.Starred = t.Loved
|
||||
mf.Rating = t.Rating
|
||||
mf.Rating = t.Rating / 20
|
||||
mf.PlayCount = t.PlayCount
|
||||
mf.PlayDate = t.PlayDateUTC
|
||||
mf.Year = t.Year
|
||||
@ -257,7 +257,7 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
|
||||
al.Year = t.Year
|
||||
al.Compilation = t.Compilation
|
||||
al.Starred = t.AlbumLoved
|
||||
al.Rating = t.AlbumRating
|
||||
al.Rating = t.AlbumRating / 20
|
||||
al.PlayCount += t.PlayCount
|
||||
al.Genre = mf.Genre
|
||||
al.Artist = mf.Artist
|
||||
|
Loading…
x
Reference in New Issue
Block a user