adding recommendations to playlist generation, trying aot

This commit is contained in:
Andy Pack 2024-06-14 08:07:56 +01:00
parent 97cf1839c0
commit 3882771ddd
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
5 changed files with 15 additions and 7 deletions

View File

@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>default</LangVersion>
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>

View File

@ -54,6 +54,7 @@ public class RunUserPlaylistStartup : FunctionsStartup
services.AddTransient<SpotifyNetworkProvider>()
.AddTransient<PlaylistGenerator>()
.AddTransient<PartTreeWalker>()
.AddSingleton<UserRepo>();
}
}

View File

@ -57,10 +57,10 @@ public class PlaylistGenerator
var combinedTracks = CollapseContextToCommonTracks(context);
// var recommender = new SpotifyRecommender(spotifyClient);
// var recommendations = await recommender.GetRecommendations(dbPlaylist, combinedTracks);
//
// combinedTracks = combinedTracks.Concat(recommendations);
var recommender = new SpotifyRecommender(spotifyClient);
var recommendations = await recommender.GetRecommendations(dbPlaylist, combinedTracks);
combinedTracks = combinedTracks.Concat(recommendations);
// combinedTracks = combinedTracks.DistinctBy(x => (x.TrackName, string.Join(':', x.ArtistNames.Order())));
// combinedTracks = combinedTracks.DistinctBy(x => x.TrackUri);

View File

@ -5,14 +5,14 @@ public static class SortExtensions
private static Random _rng = new Random();
public static IOrderedEnumerable<CommonTrack> OrderByArtistAlbumTrackNumber(this IEnumerable<CommonTrack> input) =>
input.OrderBy(x => x.AlbumArtistNames.First())
input.OrderBy(x => x.AlbumArtistNames.FirstOrDefault())
.ThenBy(x => x.AlbumName)
.ThenBy(x => x.DiscNumber)
.ThenBy(x => x.TrackNumber);
public static IOrderedEnumerable<CommonTrack> OrderByReleaseDate(this IEnumerable<CommonTrack> input) =>
input.OrderByDescending(x => x.ReleaseDate)
.ThenBy(x => x.AlbumArtistNames.First())
.ThenBy(x => x.AlbumArtistNames.FirstOrDefault())
.ThenBy(x => x.AlbumName)
.ThenBy(x => x.DiscNumber)
.ThenBy(x => x.TrackNumber);

View File

@ -1,3 +1,4 @@
using Mixonomer.Extensions;
using Mixonomer.Playlist;
using Mixonomer.Playlist.Sort;
using SpotifyAPI.Web;
@ -23,11 +24,16 @@ public class SpotifyRecommender: IRecommend
Limit = playlist.recommendation_sample
};
foreach (var track in currentTrackList.Shuffle().Take(5))
{
request.SeedTracks.Add(track.TrackUri.UriToId());
}
var response = await _client.Browse.GetRecommendations(request);
return response.Tracks.Select(x => (CommonTrack) x);
}
return Enumerable.Empty<CommonTrack>();
return [];
}
}