Skip to content

Commit

Permalink
feat(subsonic): return playCount in album responses
Browse files Browse the repository at this point in the history
closes #458
  • Loading branch information
sentriz committed Jan 18, 2024
1 parent 87943ea commit ec55f3b
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 143 deletions.
1 change: 1 addition & 0 deletions db/db.go
Expand Up @@ -339,6 +339,7 @@ type Album struct {
AlbumStar *AlbumStar
AlbumRating *AlbumRating
AverageRating float64 `sql:"default: null"`
Play *Play
}

func (a *Album) SID() *specid.ID {
Expand Down
9 changes: 7 additions & 2 deletions server/ctrlsubsonic/handlers_by_tags.go
Expand Up @@ -117,6 +117,8 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response {
}).
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID).
Preload("Play", "user_id=?", user.ID).
First(album, id.Value).
Error
if errors.Is(err, gorm.ErrRecordNotFound) {
Expand Down Expand Up @@ -199,6 +201,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
Preload("Artists").
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID).
Preload("Play", "user_id=?", user.ID).
Find(&albums)
sub := spec.NewResponse()
sub.AlbumsTwo = &spec.Albums{
Expand Down Expand Up @@ -256,7 +259,8 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
Preload("Artists").
Preload("Genres").
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID)
Preload("AlbumRating", "user_id=?", user.ID).
Preload("Play", "user_id=?", user.ID)
for _, s := range queries {
q = q.Where(`tag_title LIKE ? OR tag_title_u_dec LIKE ?`, s, s)
}
Expand Down Expand Up @@ -517,7 +521,8 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
Order("album_stars.star_date DESC").
Preload("Artists").
Preload("AlbumStar", "user_id=?", user.ID).
Preload("AlbumRating", "user_id=?", user.ID)
Preload("AlbumRating", "user_id=?", user.ID).
Preload("Play", "user_id=?", user.ID)
if m := getMusicFolder(c.musicPaths, params); m != "" {
q = q.Where("albums.root_dir=?", m)
}
Expand Down
3 changes: 3 additions & 0 deletions server/ctrlsubsonic/spec/construct_by_tags.go
Expand Up @@ -51,6 +51,9 @@ func NewAlbumByTags(a *db.Album, artists []*db.Artist) *Album {
for _, g := range a.Genres {
ret.Genres = append(ret.Genres, &GenreRef{Name: g.Name})
}
if a.Play != nil {
ret.PlayCount = a.Play.Count
}
return ret
}

Expand Down
1 change: 1 addition & 0 deletions server/ctrlsubsonic/spec/spec.go
Expand Up @@ -144,6 +144,7 @@ type Album struct {
Name string `xml:"name,attr" json:"name"`
TrackCount int `xml:"songCount,attr" json:"songCount"`
Duration int `xml:"duration,attr" json:"duration"`
PlayCount int `xml:"playCount,attr" json:"playCount"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
Genres []*GenreRef `xml:"genres,omitempty" json:"genres,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
Expand Down
27 changes: 18 additions & 9 deletions server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist
Expand Up @@ -20,7 +20,8 @@
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-4",
Expand All @@ -35,7 +36,8 @@
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-5",
Expand All @@ -50,7 +52,8 @@
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-7",
Expand All @@ -65,7 +68,8 @@
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-8",
Expand All @@ -80,7 +84,8 @@
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-9",
Expand All @@ -95,7 +100,8 @@
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-11",
Expand All @@ -110,7 +116,8 @@
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-12",
Expand All @@ -125,7 +132,8 @@
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-13",
Expand All @@ -140,7 +148,8 @@
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
}
]
}
Expand Down
27 changes: 18 additions & 9 deletions server/ctrlsubsonic/testdata/test_get_album_list_alpha_name
Expand Up @@ -20,7 +20,8 @@
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-7",
Expand All @@ -35,7 +36,8 @@
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-11",
Expand All @@ -50,7 +52,8 @@
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-4",
Expand All @@ -65,7 +68,8 @@
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-8",
Expand All @@ -80,7 +84,8 @@
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-12",
Expand All @@ -95,7 +100,8 @@
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-5",
Expand All @@ -110,7 +116,8 @@
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-9",
Expand All @@ -125,7 +132,8 @@
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-13",
Expand All @@ -140,7 +148,8 @@
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
}
]
}
Expand Down
27 changes: 18 additions & 9 deletions server/ctrlsubsonic/testdata/test_get_album_list_newest
Expand Up @@ -20,7 +20,8 @@
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-4",
Expand All @@ -35,7 +36,8 @@
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-5",
Expand All @@ -50,7 +52,8 @@
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-7",
Expand All @@ -65,7 +68,8 @@
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-8",
Expand All @@ -80,7 +84,8 @@
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-9",
Expand All @@ -95,7 +100,8 @@
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-11",
Expand All @@ -110,7 +116,8 @@
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-12",
Expand All @@ -125,7 +132,8 @@
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
},
{
"id": "al-13",
Expand All @@ -140,7 +148,8 @@
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300
"duration": 300,
"playCount": 0
}
]
}
Expand Down

0 comments on commit ec55f3b

Please sign in to comment.