Skip to content

Commit d65bdcf

Browse files
chore: simplify filter logic
1 parent 4148711 commit d65bdcf

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

src/playlist-loader.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -555,39 +555,23 @@ export default class PlaylistLoader extends EventTarget {
555555
}
556556

557557
filterAudioOnlyVariants_(playlists) {
558-
let resolutionFound = false;
559-
let videoCodecFound = false;
560-
let audioCodecFound = false;
558+
// helper function
559+
const hasVideo = (playlist) => {
560+
const { width, height } = playlist.attributes.RESOLUTION || {};
561561

562-
for (const playlist of playlists) {
563-
const hasResolution = Boolean(playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width && playlist.attributes.RESOLUTION.height);
564-
565-
if (hasResolution) {
566-
resolutionFound = true;
567-
}
568-
569-
const { audio, video } = unwrapCodecList(getCodecs(playlist));
570-
571-
if (video) {
572-
videoCodecFound = true;
573-
}
574-
575-
if (audio) {
576-
audioCodecFound = true;
562+
if (width && height) {
563+
return true;
577564
}
578-
}
579565

580-
if ((resolutionFound || videoCodecFound) && audioCodecFound) {
581-
// return only playlists with resolution or video codec available
582-
return playlists.filter((playlist) => {
583-
const hasResolution = Boolean(playlist.attributes.RESOLUTION && playlist.attributes.RESOLUTION.width && playlist.attributes.RESOLUTION.height);
584-
const { video } = unwrapCodecList(getCodecs(playlist));
566+
// parse codecs string from playlist attributes
567+
const codecsList = getCodecs(playlist) || [];
568+
// unwrap list
569+
const codecsInfo = unwrapCodecList(codecsList);
585570

586-
return hasResolution || Boolean(video);
587-
});
588-
}
571+
return Boolean(codecsInfo.video);
572+
};
589573

590-
return playlists;
574+
return playlists.some(hasVideo) ? playlists.filter(hasVideo) : playlists;
591575
}
592576

593577
/**

0 commit comments

Comments
 (0)