diff options
| author | Max Isom <[email protected]> | 2021-05-30 15:01:11 -0500 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2021-05-30 15:01:11 -0500 |
| commit | cf75afd4bc1d54223ffa59ec9ddb8a7c255facf6 (patch) | |
| tree | 4e2abbdbf6386be791aadc7878f472cd006b279c /src | |
| parent | d61107aedd5a7108cd3dc1eb6a542ed38f551e00 (diff) | |
| download | muse-cf75afd4bc1d54223ffa59ec9ddb8a7c255facf6.tar.xz muse-cf75afd4bc1d54223ffa59ec9ddb8a7c255facf6.zip | |
Fix shuffle bug for long Spotify playlists
A random sample of 50 songs is taken for long playlists since mapping Spotify -> YouTube is expensive.
However, the function used previously allowed for duplicates within that sample of 50.
Diffstat (limited to 'src')
| -rw-r--r-- | src/services/get-songs.ts | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index d3e951d..c7d37ea 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -6,7 +6,7 @@ import spotifyURI from 'spotify-uri'; import Spotify from 'spotify-web-api-node'; import YouTube, {YoutubePlaylistItem} from 'youtube.ts'; import pLimit from 'p-limit'; -import uniqueRandomArray from 'unique-random-array'; +import shuffle from 'array-shuffle'; import {QueuedSong, QueuedPlaylist} from '../services/player'; import {TYPES} from '../types'; @@ -182,12 +182,9 @@ export default class { const originalNSongs = tracks.length; if (tracks.length > 50) { - const random = uniqueRandomArray(tracks); + const shuffled = shuffle(tracks); - tracks = []; - for (let i = 0; i < 50; i++) { - tracks.push(random()); - } + tracks = shuffled.slice(0, 50); } // Limit concurrency so hopefully we don't get banned for searching |
