mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Fix whole playlist fails when one song is unavailable (#489)
Co-authored-by: Max Isom <hi@maxisom.me>
This commit is contained in:
parent
c89bd278d3
commit
9daf126680
|
@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Queueing Spotify playlists could sometimes fail when a song wasn't found on YouTube
|
||||
|
||||
## [0.5.0] - 2022-01-21
|
||||
### Changed
|
||||
|
|
|
@ -255,14 +255,17 @@ export default class {
|
|||
tracks = shuffled.slice(0, playlistLimit);
|
||||
}
|
||||
|
||||
let songs = await Promise.all(tracks.map(async track => this.spotifyToYouTube(track, playlist)));
|
||||
const searchResults = await Promise.allSettled(tracks.map(async track => this.spotifyToYouTube(track)));
|
||||
|
||||
let nSongsNotFound = 0;
|
||||
|
||||
// Get rid of null values
|
||||
songs = songs.reduce((accum: SongMetadata[], song) => {
|
||||
if (song) {
|
||||
accum.push(song);
|
||||
// Count songs that couldn't be found
|
||||
const songs: SongMetadata[] = searchResults.reduce((accum: SongMetadata[], result) => {
|
||||
if (result.status === 'fulfilled') {
|
||||
accum.push({
|
||||
...result.value,
|
||||
...(playlist ? {playlist} : {}),
|
||||
});
|
||||
} else {
|
||||
nSongsNotFound++;
|
||||
}
|
||||
|
@ -270,10 +273,10 @@ export default class {
|
|||
return accum;
|
||||
}, []);
|
||||
|
||||
return [songs as SongMetadata[], nSongsNotFound, originalNSongs];
|
||||
return [songs, nSongsNotFound, originalNSongs];
|
||||
}
|
||||
|
||||
private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified, _: QueuedPlaylist | null): Promise<SongMetadata> {
|
||||
private async spotifyToYouTube(track: SpotifyApi.TrackObjectSimplified): Promise<SongMetadata> {
|
||||
return this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue