diff --git a/backend/mediaprovider/helpers/similar.go b/backend/mediaprovider/helpers/similar.go new file mode 100644 index 00000000..b238ba26 --- /dev/null +++ b/backend/mediaprovider/helpers/similar.go @@ -0,0 +1,22 @@ +package helpers + +import ( + "github.com/dweymouth/supersonic/backend/mediaprovider" + "github.com/dweymouth/supersonic/sharedutil" +) + +func GetSimilarSongsFallback(mp mediaprovider.MediaProvider, track *mediaprovider.Track, count int) []*mediaprovider.Track { + var tracks []*mediaprovider.Track + if len(track.ArtistIDs) > 0 { + tracks, _ = mp.GetSimilarTracks(track.ArtistIDs[0], count) + if len(tracks) > 0 { + return tracks + } + } + tracks, _ = mp.GetRandomTracks(track.Genre, count) + + // make sure to exclude the song itself from the similar list + return sharedutil.FilterSlice(tracks, func(t *mediaprovider.Track) bool { + return t.ID != track.ID + }) +} diff --git a/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go b/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go index a303e69f..8ad33edd 100644 --- a/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go +++ b/backend/mediaprovider/jellyfin/jellyfinmediaprovider.go @@ -10,6 +10,7 @@ import ( "github.com/dweymouth/go-jellyfin" "github.com/dweymouth/supersonic/backend/mediaprovider" + "github.com/dweymouth/supersonic/backend/mediaprovider/helpers" "github.com/dweymouth/supersonic/sharedutil" ) @@ -480,5 +481,12 @@ func (j *jellyfinMediaProvider) GetSongRadio(trackID string, count int) ([]*medi if err != nil { return nil, err } + if len(tr) == 0 { + track, err := j.GetTrack(trackID) + if err != nil { + return nil, err + } + return helpers.GetSimilarSongsFallback(j, track, count), nil + } return sharedutil.MapSlice(tr, toTrack), nil } diff --git a/backend/mediaprovider/subsonic/subsonicmediaprovider.go b/backend/mediaprovider/subsonic/subsonicmediaprovider.go index 6d66c49b..28fff34e 100644 --- a/backend/mediaprovider/subsonic/subsonicmediaprovider.go +++ b/backend/mediaprovider/subsonic/subsonicmediaprovider.go @@ -14,6 +14,7 @@ import ( "github.com/dweymouth/go-subsonic/subsonic" "github.com/dweymouth/supersonic/backend/mediaprovider" + "github.com/dweymouth/supersonic/backend/mediaprovider/helpers" "github.com/dweymouth/supersonic/sharedutil" ) @@ -622,5 +623,12 @@ func (s *subsonicMediaProvider) GetSongRadio(trackID string, count int) ([]*medi if err != nil { return nil, err } + if len(tr) == 0 { + track, err := s.GetTrack(trackID) + if err != nil { + return nil, err + } + return helpers.GetSimilarSongsFallback(s, track, count), nil + } return sharedutil.MapSlice(tr, toTrack), nil }