UserRatings for Albums and MediaFiles
This commit is contained in:
@@ -113,5 +113,6 @@ func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
|
|||||||
n.AlbumId = entry.AlbumId
|
n.AlbumId = entry.AlbumId
|
||||||
n.ArtistId = entry.ArtistId
|
n.ArtistId = entry.ArtistId
|
||||||
n.Type = entry.Type
|
n.Type = entry.Type
|
||||||
|
n.UserRating = entry.UserRating
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.
|
|||||||
Name: d.Name,
|
Name: d.Name,
|
||||||
Parent: d.Parent,
|
Parent: d.Parent,
|
||||||
PlayCount: d.PlayCount,
|
PlayCount: d.PlayCount,
|
||||||
|
UserRating: d.UserRating,
|
||||||
}
|
}
|
||||||
if !d.Starred.IsZero() {
|
if !d.Starred.IsZero() {
|
||||||
dir.Starred = &d.Starred
|
dir.Starred = &d.Starred
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ func TestGetMusicDirectory(t *testing.T) {
|
|||||||
mockAlbumRepo.SetData(`[{"Id":"A","Name":"Tardis","ArtistId":"1"}]`, 1)
|
mockAlbumRepo.SetData(`[{"Id":"A","Name":"Tardis","ArtistId":"1"}]`, 1)
|
||||||
_, w := Get(AddParams("/rest/getMusicDirectory.view", "id=1"), "TestGetMusicDirectory")
|
_, 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() {
|
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)
|
mockMediaFileRepo.SetData(`[{"Id":"3","Title":"Cangote","AlbumId":"A"}]`, 1)
|
||||||
_, w := Get(AddParams("/rest/getMusicDirectory.view", "id=A"), "TestGetMusicDirectory")
|
_, 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() {
|
Reset(func() {
|
||||||
mockArtistRepo.SetData("[]", 0)
|
mockArtistRepo.SetData("[]", 0)
|
||||||
|
|||||||
@@ -92,9 +92,9 @@ type Child struct {
|
|||||||
AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
||||||
ArtistId string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
ArtistId string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||||
Type string `xml:"type,attr,omitempty" json:"type,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="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="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="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 -->
|
<xs:attribute name="originalWidth" type="xs:int" use="optional"/> <!-- Added in 1.13.0 -->
|
||||||
@@ -109,8 +109,8 @@ type Directory struct {
|
|||||||
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||||
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,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 -->
|
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ type DirectoryInfo struct {
|
|||||||
Parent string
|
Parent string
|
||||||
Starred time.Time
|
Starred time.Time
|
||||||
PlayCount int32
|
PlayCount int32
|
||||||
|
UserRating int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c browser) Directory(id string) (*DirectoryInfo, error) {
|
func (c browser) Directory(id string) (*DirectoryInfo, error) {
|
||||||
@@ -104,6 +105,7 @@ func (c browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *Dire
|
|||||||
Name: al.Name,
|
Name: al.Name,
|
||||||
Parent: al.ArtistId,
|
Parent: al.ArtistId,
|
||||||
PlayCount: int32(al.PlayCount),
|
PlayCount: int32(al.PlayCount),
|
||||||
|
UserRating: al.Rating,
|
||||||
}
|
}
|
||||||
if al.Starred {
|
if al.Starred {
|
||||||
dir.Starred = al.UpdatedAt
|
dir.Starred = al.UpdatedAt
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Entry struct {
|
|||||||
AlbumId string
|
AlbumId string
|
||||||
ArtistId string
|
ArtistId string
|
||||||
Type string
|
Type string
|
||||||
|
UserRating int
|
||||||
|
|
||||||
UserName string
|
UserName string
|
||||||
MinutesAgo int
|
MinutesAgo int
|
||||||
@@ -62,6 +63,7 @@ func FromAlbum(al *domain.Album) Entry {
|
|||||||
c.Created = al.CreatedAt
|
c.Created = al.CreatedAt
|
||||||
c.AlbumId = al.Id
|
c.AlbumId = al.Id
|
||||||
c.ArtistId = al.ArtistId
|
c.ArtistId = al.ArtistId
|
||||||
|
c.UserRating = al.Rating
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,5 +96,6 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
|
|||||||
c.AlbumId = mf.AlbumId
|
c.AlbumId = mf.AlbumId
|
||||||
c.ArtistId = mf.ArtistId
|
c.ArtistId = mf.ArtistId
|
||||||
c.Type = "music" // TODO Hardcoded for now
|
c.Type = "music" // TODO Hardcoded for now
|
||||||
|
c.UserRating = mf.Rating
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
|||||||
mf.Genre = unescape(t.Genre)
|
mf.Genre = unescape(t.Genre)
|
||||||
mf.Compilation = t.Compilation
|
mf.Compilation = t.Compilation
|
||||||
mf.Starred = t.Loved
|
mf.Starred = t.Loved
|
||||||
mf.Rating = t.Rating
|
mf.Rating = t.Rating / 20
|
||||||
mf.PlayCount = t.PlayCount
|
mf.PlayCount = t.PlayCount
|
||||||
mf.PlayDate = t.PlayDateUTC
|
mf.PlayDate = t.PlayDateUTC
|
||||||
mf.Year = t.Year
|
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.Year = t.Year
|
||||||
al.Compilation = t.Compilation
|
al.Compilation = t.Compilation
|
||||||
al.Starred = t.AlbumLoved
|
al.Starred = t.AlbumLoved
|
||||||
al.Rating = t.AlbumRating
|
al.Rating = t.AlbumRating / 20
|
||||||
al.PlayCount += t.PlayCount
|
al.PlayCount += t.PlayCount
|
||||||
al.Genre = mf.Genre
|
al.Genre = mf.Genre
|
||||||
al.Artist = mf.Artist
|
al.Artist = mf.Artist
|
||||||
|
|||||||
Reference in New Issue
Block a user