Add played field to Subsonic API responses. Fix #1971

This is not an "official" field in the specification, but I guess it does not hurt to expose this ;)
This commit is contained in:
Deluan 2022-11-02 11:20:51 -04:00
parent 081cfe5a9f
commit ca2cb26d8e
3 changed files with 18 additions and 0 deletions

View File

@ -333,6 +333,9 @@ func (c *BrowsingController) buildArtistDirectory(ctx context.Context, artist *m
dir.Id = artist.ID
dir.Name = artist.Name
dir.PlayCount = artist.PlayCount
if artist.PlayCount > 0 {
dir.Played = &artist.PlayDate
}
dir.AlbumCount = artist.AlbumCount
dir.UserRating = artist.Rating
if artist.Starred {
@ -361,6 +364,9 @@ func (c *BrowsingController) buildAlbumDirectory(ctx context.Context, album *mod
dir.Name = album.Name
dir.Parent = album.AlbumArtistID
dir.PlayCount = album.PlayCount
if album.PlayCount > 0 {
dir.Played = &album.PlayDate
}
dir.UserRating = album.Rating
dir.SongCount = album.SongCount
dir.CoverArt = album.CoverArtId
@ -387,6 +393,9 @@ func (c *BrowsingController) buildAlbum(ctx context.Context, album *model.Album,
dir.SongCount = album.SongCount
dir.Duration = int(album.Duration)
dir.PlayCount = album.PlayCount
if album.PlayCount > 0 {
dir.Played = &album.PlayDate
}
dir.Year = album.MaxYear
dir.Genre = album.Genre
dir.UserRating = album.Rating

View File

@ -165,6 +165,9 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
child.ArtistId = mf.ArtistID
child.Type = "music"
child.PlayCount = mf.PlayCount
if mf.PlayCount > 0 {
child.Played = &mf.PlayDate
}
if mf.Starred {
child.Starred = &mf.StarredAt
}
@ -211,6 +214,9 @@ func childFromAlbum(ctx context.Context, al model.Album) responses.Child {
child.Starred = &al.StarredAt
}
child.PlayCount = al.PlayCount
if al.PlayCount > 0 {
child.Played = &al.PlayDate
}
child.UserRating = al.Rating
return child
}

View File

@ -116,6 +116,7 @@ type Child struct {
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playCount,omitempty"`
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
@ -141,6 +142,7 @@ type Directory struct {
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playCount,omitempty"`
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
// ID3
@ -178,6 +180,7 @@ type AlbumID3 struct {
SongCount int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playCount,omitempty"`
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`