🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add local TopSongs
Deluan8f0d00292227
diff --git a/consts/consts.go b/consts/consts.goindex aabf8c865..972705869 100644--- a/consts/consts.go+++ b/consts/consts.go@@ -48,7 +48,7 @@ const (ServerReadHeaderTimeout = 3 * time.Second- ArtistInfoTimeToLive = time.Second+ ArtistInfoTimeToLive = time.Second // TODO Revert//ArtistInfoTimeToLive = 24 * time.HourI18nFolder = "i18n"diff --git a/core/agents/local_agent.go b/core/agents/local_agent.goindex 9c25b1227..2727c4962 100644--- a/core/agents/local_agent.go+++ b/core/agents/local_agent.go@@ -3,6 +3,7 @@ package agentsimport ("context"+ "github.com/Masterminds/squirrel""github.com/navidrome/navidrome/model")@@ -12,10 +13,12 @@ const (localBiography = "Biography not available")-type localAgent struct{}+type localAgent struct {+ ds model.DataStore+}-func localsConstructor(_ model.DataStore) Interface {- return &localAgent{}+func localsConstructor(ds model.DataStore) Interface {+ return &localAgent{ds}}func (p *localAgent) AgentName() string {@@ -27,7 +30,29 @@ func (p *localAgent) GetBiography(ctx context.Context, id, name, mbid string) (s}func (p *localAgent) GetTopSongs(ctx context.Context, id, artistName, mbid string, count int) ([]Song, error) {- return nil, nil // TODO return 5-stars and liked songs sorted by playCount+ top, err := p.ds.MediaFile(ctx).GetAll(model.QueryOptions{+ Sort: "playCount",+ Order: "desc",+ Max: count,+ Filters: squirrel.And{+ squirrel.Eq{"artist_id": id},+ squirrel.Or{+ squirrel.Eq{"starred": true},+ squirrel.Eq{"rating": 5},+ },+ },+ })+ if err != nil {+ return nil, err+ }+ var result []Song+ for _, s := range top {+ result = append(result, Song{+ Name: s.Title,+ MBID: s.MbzReleaseTrackID,+ })+ }+ return result, nil}func init() {