2024-01-23 17:43:25 +00:00
|
|
|
using Mixonomer.Playlist;
|
|
|
|
using Mixonomer.Playlist.Sort;
|
|
|
|
using SpotifyAPI.Web;
|
|
|
|
|
|
|
|
namespace Mixonomer;
|
|
|
|
|
|
|
|
public class SpotifyRecommender: IRecommend
|
|
|
|
{
|
|
|
|
private readonly SpotifyClient _client;
|
|
|
|
|
|
|
|
public SpotifyRecommender(SpotifyClient client)
|
|
|
|
{
|
|
|
|
_client = client;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<CommonTrack>> GetRecommendations(Fire.Playlist playlist,
|
|
|
|
IEnumerable<CommonTrack> currentTrackList)
|
|
|
|
{
|
|
|
|
if (playlist.include_recommendations)
|
|
|
|
{
|
2024-06-14 07:23:25 +01:00
|
|
|
var request = new RecommendationsRequest()
|
|
|
|
{
|
|
|
|
Limit = playlist.recommendation_sample
|
|
|
|
};
|
2024-01-23 17:43:25 +00:00
|
|
|
|
|
|
|
var response = await _client.Browse.GetRecommendations(request);
|
|
|
|
|
|
|
|
return response.Tracks.Select(x => (CommonTrack) x);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Enumerable.Empty<CommonTrack>();
|
|
|
|
}
|
|
|
|
}
|