Skip to content

Commit

Permalink
fix: improve audio filter when no language is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalygashkov committed Nov 20, 2024
1 parent c087ece commit 7424292
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ const createAudioCodecFilter = (audios) => createCodecFilter(audios);
const createAudioLanguageFilter = (audios) => {
return (languages = [], maxTracksPerLanguage) => {
if (!languages.length) {
for (const audio of audios) {
const alreadyAdded = languages.includes(audio.language);
if (!alreadyAdded) languages.push(audio.language);
const audiosWithLanguage = audios.filter((track) => track.language);
if (audiosWithLanguage.length) {
for (const audio of audiosWithLanguage) {
const alreadyAdded = languages.includes(audio.language);
if (!alreadyAdded) languages.push(audio.language);
}
} else {
audios.sort((a, b) => b.bitrate.bps - a.bitrate.bps);
return audios.slice(0, maxTracksPerLanguage);
}
}
const filtered = [];
Expand Down

0 comments on commit 7424292

Please sign in to comment.