From 30d3f1eda0f53c493885045ad6efa6e277ce5471 Mon Sep 17 00:00:00 2001
From: Deluan <deluan@navidrome.org>
Date: Tue, 23 Nov 2021 21:50:57 -0500
Subject: [PATCH] Add userRating to Subsonic Album/Artist responses. Closes
 #1486

---
 server/subsonic/browsing.go            |  2 ++
 server/subsonic/helpers.go             |  1 +
 server/subsonic/responses/responses.go | 28 ++++++++++++++------------
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/server/subsonic/browsing.go b/server/subsonic/browsing.go
index 7caa959f5..52a48cca3 100644
--- a/server/subsonic/browsing.go
+++ b/server/subsonic/browsing.go
@@ -267,6 +267,7 @@ func (c *BrowsingController) GetArtistInfo2(w http.ResponseWriter, r *http.Reque
 		similar.Name = s.Name
 		similar.AlbumCount = s.AlbumCount
 		similar.Starred = s.Starred
+		similar.UserRating = s.UserRating
 		similar.ArtistImageUrl = s.ArtistImageUrl
 		response.ArtistInfo2.SimilarArtist = append(response.ArtistInfo2.SimilarArtist, similar)
 	}
@@ -387,6 +388,7 @@ func (c *BrowsingController) buildAlbum(ctx context.Context, album *model.Album,
 	dir.PlayCount = album.PlayCount
 	dir.Year = album.MaxYear
 	dir.Genre = album.Genre
+	dir.UserRating = album.Rating
 	if !album.CreatedAt.IsZero() {
 		dir.Created = &album.CreatedAt
 	}
diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go
index a79442e7a..a1b9e2ff9 100644
--- a/server/subsonic/helpers.go
+++ b/server/subsonic/helpers.go
@@ -100,6 +100,7 @@ func toArtistID3(ctx context.Context, a model.Artist) responses.ArtistID3 {
 		Name:           a.Name,
 		AlbumCount:     a.AlbumCount,
 		ArtistImageUrl: a.ArtistImageUrl(),
+		UserRating:     a.Rating,
 	}
 	if a.Starred {
 		artist.Starred = &a.StarredAt
diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go
index 3b9461f1c..2e82cc82f 100644
--- a/server/subsonic/responses/responses.go
+++ b/server/subsonic/responses/responses.go
@@ -165,22 +165,24 @@ type ArtistID3 struct {
 	CoverArt       string     `xml:"coverArt,attr,omitempty"            json:"coverArt,omitempty"`
 	AlbumCount     int        `xml:"albumCount,attr,omitempty"          json:"albumCount,omitempty"`
 	Starred        *time.Time `xml:"starred,attr,omitempty"             json:"starred,omitempty"`
-	ArtistImageUrl string     `xml:"artistImageUrl,attr,omitempty"     json:"artistImageUrl,omitempty"`
+	UserRating     int        `xml:"userRating,attr,omitempty"          json:"userRating,omitempty"`
+	ArtistImageUrl string     `xml:"artistImageUrl,attr,omitempty"      json:"artistImageUrl,omitempty"`
 }
 
 type AlbumID3 struct {
-	Id        string     `xml:"id,attr"                            json:"id"`
-	Name      string     `xml:"name,attr"                          json:"name"`
-	Artist    string     `xml:"artist,attr,omitempty"              json:"artist,omitempty"`
-	ArtistId  string     `xml:"artistId,attr,omitempty"            json:"artistId,omitempty"`
-	CoverArt  string     `xml:"coverArt,attr,omitempty"            json:"coverArt,omitempty"`
-	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"`
-	Created   *time.Time `xml:"created,attr,omitempty"             json:"created,omitempty"`
-	Starred   *time.Time `xml:"starred,attr,omitempty"             json:"starred,omitempty"`
-	Year      int        `xml:"year,attr,omitempty"                json:"year,omitempty"`
-	Genre     string     `xml:"genre,attr,omitempty"               json:"genre,omitempty"`
+	Id         string     `xml:"id,attr"                            json:"id"`
+	Name       string     `xml:"name,attr"                          json:"name"`
+	Artist     string     `xml:"artist,attr,omitempty"              json:"artist,omitempty"`
+	ArtistId   string     `xml:"artistId,attr,omitempty"            json:"artistId,omitempty"`
+	CoverArt   string     `xml:"coverArt,attr,omitempty"            json:"coverArt,omitempty"`
+	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"`
+	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"`
+	Year       int        `xml:"year,attr,omitempty"                json:"year,omitempty"`
+	Genre      string     `xml:"genre,attr,omitempty"               json:"genre,omitempty"`
 }
 
 type ArtistWithAlbumsID3 struct {