Fix radio for playlists < 5 items. (#1401)
authorMarvin Schenkel <marvinschenkel@gmail.com>
Sun, 23 Jun 2024 09:46:11 +0000 (11:46 +0200)
committerGitHub <noreply@github.com>
Sun, 23 Jun 2024 09:46:11 +0000 (11:46 +0200)
music_assistant/server/controllers/media/playlists.py

index 6df7e2085c3210efe9125eb64559bbff62599ccc..ef205a569fdbdc4081f507c020f0564601f44b67 100644 (file)
@@ -427,9 +427,10 @@ class PlaylistController(MediaControllerBase[Playlist]):
         # to account for playlists with mixed content we grab suggestions from a few
         # random playlist tracks to prevent getting too many tracks of one of the
         # source playlist's genres.
+        sample_size = min(len(playlist_tracks), 5)
         while len(final_items) < limit:
             # grab 5 random tracks from the playlist
-            base_tracks = random.sample(playlist_tracks, 5)
+            base_tracks = random.sample(playlist_tracks, sample_size)
             # add the source/base playlist tracks to the final list...
             final_items.extend(base_tracks)
             # get 5 suggestions for one of the base tracks