fix(subsonic): getRandomSongs with genre filter

fix https://github.com/dweymouth/supersonic/issues/577

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2025-03-12 17:34:39 -04:00
parent 0bb4b881e9
commit 7c13878075
2 changed files with 10 additions and 18 deletions

View file

@ -4,7 +4,6 @@ import (
"context"
"time"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/id"
@ -53,17 +52,6 @@ var _ = Describe("MediaRepository", func() {
Expect(err).To(MatchError(model.ErrNotFound))
})
XIt("filters by genre", func() {
Expect(mr.GetAll(model.QueryOptions{
Sort: "genre.name asc, title asc",
Filters: squirrel.Eq{"genre.name": "Rock"},
})).To(Equal(model.MediaFiles{
songDayInALife,
songAntenna,
songComeTogether,
}))
})
Context("Annotations", func() {
It("increments play count when the tracks does not have annotations", func() {
id := "incplay.firsttime"

View file

@ -95,7 +95,7 @@ func SongsByRandom(genre string, fromYear, toYear int) Options {
}
ff := And{}
if genre != "" {
ff = append(ff, Eq{"genre.name": genre})
ff = append(ff, filterByGenre(genre))
}
if fromYear != 0 {
ff = append(ff, GtOrEq{"year": fromYear})
@ -118,11 +118,15 @@ func SongWithLyrics(artist, title string) Options {
func ByGenre(genre string) Options {
return addDefaultFilters(Options{
Sort: "name asc",
Filters: persistence.Exists("json_tree(tags)", And{
Like{"value": genre},
NotEq{"atom": nil},
}),
Sort: "name asc",
Filters: filterByGenre(genre),
})
}
func filterByGenre(genre string) Sqlizer {
return persistence.Exists("json_tree(tags)", And{
Like{"value": genre},
NotEq{"atom": nil},
})
}