Skip to content

Commit

Permalink
feat(subsonic): expose all album genres in a list of subsonic api
Browse files Browse the repository at this point in the history
expose album genres from getArtist
  • Loading branch information
sentriz committed Sep 11, 2023
1 parent d6b35f8 commit 749233d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/ctrlsubsonic/handlers_by_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (c *Controller) ServeGetArtist(r *http.Request) *spec.Response {
Group("albums.id")
}).
Preload("Albums.Artists").
Preload("Albums.Genres").
Preload("ArtistStar", "user_id=?", user.ID).
Preload("ArtistRating", "user_id=?", user.ID).
First(artist, id.Value)
Expand Down
7 changes: 6 additions & 1 deletion server/ctrlsubsonic/spec/construct_by_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func NewAlbumByTags(a *db.Album, artists []*db.Artist) *Album {
Name: a.TagTitle,
Year: a.TagYear,
TrackCount: a.ChildCount,
Genre: strings.Join(a.GenreStrings(), ", "),
Duration: a.Duration,
AverageRating: formatRating(a.AverageRating),
}
Expand All @@ -41,6 +40,12 @@ func NewAlbumByTags(a *db.Album, artists []*db.Artist) *Album {
Name: a.Name,
})
}
if len(a.Genres) > 0 {
ret.Genre = a.Genres[0].Name
}
for _, g := range a.Genres {
ret.Genres = append(ret.Genres, g.Name)
}
return ret
}

Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type Album struct {
TrackCount int `xml:"songCount,attr" json:"songCount"`
Duration int `xml:"duration,attr" json:"duration"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
Genres []string `xml:"genres,omitempty" json:"genres,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Tracks []*TrackChild `xml:"song,omitempty" json:"song,omitempty"`
// star / rating
Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/testdata/test_get_album_with_cover
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021,
"song": [
{
Expand Down
6 changes: 6 additions & 0 deletions server/ctrlsubsonic/testdata/test_get_artist_id_one
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"name": "album-0",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -36,6 +38,8 @@
"name": "album-1",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -50,6 +54,8 @@
"name": "album-2",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
}
]
Expand Down
6 changes: 6 additions & 0 deletions server/ctrlsubsonic/testdata/test_get_artist_id_three
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"name": "album-0",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -36,6 +38,8 @@
"name": "album-1",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -50,6 +54,8 @@
"name": "album-2",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
}
]
Expand Down
6 changes: 6 additions & 0 deletions server/ctrlsubsonic/testdata/test_get_artist_id_two
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"name": "album-0",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -36,6 +38,8 @@
"name": "album-1",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -50,6 +54,8 @@
"name": "album-2",
"songCount": 3,
"duration": 300,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
}
]
Expand Down
9 changes: 9 additions & 0 deletions server/ctrlsubsonic/testdata/test_search_three_q_alb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -34,6 +35,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -49,6 +51,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -64,6 +67,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -79,6 +83,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -94,6 +99,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -109,6 +115,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -124,6 +131,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
},
{
Expand All @@ -139,6 +147,7 @@
"songCount": 0,
"duration": 0,
"genre": "Unknown Genre",
"genres": ["Unknown Genre"],
"year": 2021
}
]
Expand Down

0 comments on commit 749233d

Please sign in to comment.