diff --git a/backend/mediaprovider/helpers/other.go b/backend/mediaprovider/helpers/other.go index a0ce453..dd70978 100644 --- a/backend/mediaprovider/helpers/other.go +++ b/backend/mediaprovider/helpers/other.go @@ -2,6 +2,7 @@ package helpers import ( "fmt" + "sort" "github.com/dweymouth/supersonic/backend/mediaprovider" "github.com/dweymouth/supersonic/sharedutil" @@ -37,3 +38,17 @@ func GetArtistTracks(mp mediaprovider.MediaProvider, artistID string) ([]*mediap } return allTracks, nil } + +func GetTopTracksFallback(mp mediaprovider.MediaProvider, artistID string, count int) ([]*mediaprovider.Track, error) { + tracks, err := GetArtistTracks(mp, artistID) + if err != nil { + return nil, err + } + sort.Slice(tracks, func(i, j int) bool { + return tracks[i].PlayCount > tracks[j].PlayCount + }) + if len(tracks) > count { + return tracks[:count], nil + } + return tracks, nil +} diff --git a/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go b/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go index 8f2742b..ea5586d 100644 --- a/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go +++ b/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go @@ -182,6 +182,9 @@ func (j *jellyfinMediaProvider) GetTopTracks(artist mediaprovider.Artist, limit if err != nil { return nil, err } + if len(tr) == 0 { + return helpers.GetTopTracksFallback(j, artist.ID, limit) + } return sharedutil.MapSlice(tr, toTrack), nil } diff --git a/backend/mediaprovider/subsonic/subsonicmediaprovider.go b/backend/mediaprovider/subsonic/subsonicmediaprovider.go index 7f17cae..8ca96af 100644 --- a/backend/mediaprovider/subsonic/subsonicmediaprovider.go +++ b/backend/mediaprovider/subsonic/subsonicmediaprovider.go @@ -248,6 +248,9 @@ func (s *subsonicMediaProvider) GetTopTracks(artist mediaprovider.Artist, count if err != nil { return nil, err } + if len(tr) == 0 { + return helpers.GetTopTracksFallback(s, artist.ID, count) + } return sharedutil.MapSlice(tr, toTrack), nil }