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.
This commit is contained in:
Max Isom 2021-05-30 15:01:11 -05:00
parent d61107aedd
commit cf75afd4bc
No known key found for this signature in database
GPG key ID: 25C9B1A7F6798880
4 changed files with 17 additions and 23 deletions

View file

@ -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