From a230f605f1e5028bef766956a1da3c4b5824aaf1 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Mon, 4 Oct 2021 10:39:20 -0700 Subject: [PATCH] Remove invalid songs from getRandomSongs --- src/components/player/NowPlayingView.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/player/NowPlayingView.tsx b/src/components/player/NowPlayingView.tsx index be345eb..1c3c09f 100644 --- a/src/components/player/NowPlayingView.tsx +++ b/src/components/player/NowPlayingView.tsx @@ -179,16 +179,31 @@ const NowPlayingView = () => { return notifyToast('error', errorMessages(res)[0]); } + const cleanedSongs = res.song.filter((song: any) => { + // Remove invalid songs that may break the player + return song.bitRate && song.duration; + }); + + const difference = res.song.length - cleanedSongs.length; + if (action === 'play') { - dispatch(setPlayQueue({ entries: res.song })); + dispatch(setPlayQueue({ entries: cleanedSongs })); dispatch(setStatus('PLAYING')); - notifyToast('info', `Playing ${res.song.length} song(s)`); + notifyToast( + 'info', + `Playing ${cleanedSongs.length} ${ + difference !== 0 ? `(-${difference} invalid)` : '' + } song(s)` + ); } else { - dispatch(appendPlayQueue({ entries: res.song })); + dispatch(appendPlayQueue({ entries: cleanedSongs })); if (playQueue.entry.length < 1) { dispatch(setStatus('PLAYING')); } - notifyToast('info', `Added ${res.song.length} song(s) to the queue`); + notifyToast( + 'info', + `Added ${cleanedSongs.length} ${difference !== 0 ? `(-${difference} invalid)` : ''} song(s)` + ); } setIsLoadingRandom(false);