mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-10 03:55:29 +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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Fixed
|
||||||
|
- Queueing Spotify playlists could sometimes fail when a song wasn't found on YouTube
|
||||||
|
|
||||||
## [0.5.0] - 2022-01-21
|
## [0.5.0] - 2022-01-21
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -255,14 +255,17 @@ export default class {
|
||||||
tracks = shuffled.slice(0, playlistLimit);
|
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;
|
let nSongsNotFound = 0;
|
||||||
|
|
||||||
// Get rid of null values
|
// Count songs that couldn't be found
|
||||||
songs = songs.reduce((accum: SongMetadata[], song) => {
|
const songs: SongMetadata[] = searchResults.reduce((accum: SongMetadata[], result) => {
|
||||||
if (song) {
|
if (result.status === 'fulfilled') {
|
||||||
accum.push(song);
|
accum.push({
|
||||||
|
...result.value,
|
||||||
|
...(playlist ? {playlist} : {}),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
nSongsNotFound++;
|
nSongsNotFound++;
|
||||||
}
|
}
|
||||||
|
@ -270,10 +273,10 @@ export default class {
|
||||||
return accum;
|
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}"`);
|
return this.youtubeVideoSearch(`"${track.name}" "${track.artists[0].name}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue