add similar songs fallback when server returns none
This commit is contained in:
@@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/dweymouth/go-jellyfin"
|
"github.com/dweymouth/go-jellyfin"
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
|
"github.com/dweymouth/supersonic/backend/mediaprovider/helpers"
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -480,5 +481,12 @@ func (j *jellyfinMediaProvider) GetSongRadio(trackID string, count int) ([]*medi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
return sharedutil.MapSlice(tr, toTrack), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/dweymouth/go-subsonic/subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
|
"github.com/dweymouth/supersonic/backend/mediaprovider/helpers"
|
||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -622,5 +623,12 @@ func (s *subsonicMediaProvider) GetSongRadio(trackID string, count int) ([]*medi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
return sharedutil.MapSlice(tr, toTrack), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user