🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add `played` field to Subsonic API responses. Fix #1971
Deluanca2cb26d8ed3
diff --git a/server/subsonic/browsing.go b/server/subsonic/browsing.goindex c93ba825d..a5b728272 100644--- a/server/subsonic/browsing.go+++ b/server/subsonic/browsing.go@@ -333,6 +333,9 @@ func (c *BrowsingController) buildArtistDirectory(ctx context.Context, artist *mdir.Id = artist.IDdir.Name = artist.Namedir.PlayCount = artist.PlayCount+ if artist.PlayCount > 0 {+ dir.Played = &artist.PlayDate+ }dir.AlbumCount = artist.AlbumCountdir.UserRating = artist.Ratingif artist.Starred {@@ -361,6 +364,9 @@ func (c *BrowsingController) buildAlbumDirectory(ctx context.Context, album *moddir.Name = album.Namedir.Parent = album.AlbumArtistIDdir.PlayCount = album.PlayCount+ if album.PlayCount > 0 {+ dir.Played = &album.PlayDate+ }dir.UserRating = album.Ratingdir.SongCount = album.SongCountdir.CoverArt = album.CoverArtId@@ -387,6 +393,9 @@ func (c *BrowsingController) buildAlbum(ctx context.Context, album *model.Album,dir.SongCount = album.SongCountdir.Duration = int(album.Duration)dir.PlayCount = album.PlayCount+ if album.PlayCount > 0 {+ dir.Played = &album.PlayDate+ }dir.Year = album.MaxYeardir.Genre = album.Genredir.UserRating = album.Ratingdiff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.goindex 63fd94962..e74b43e86 100644--- a/server/subsonic/helpers.go+++ b/server/subsonic/helpers.go@@ -165,6 +165,9 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Childchild.ArtistId = mf.ArtistIDchild.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.Ratingreturn child}diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.goindex f67e88a21..9593f6706 100644--- a/server/subsonic/responses/responses.go+++ b/server/subsonic/responses/responses.go@@ -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"`