Skip to content

Commit

Permalink
fix: sort formats that are playlist or have contentLength higher
Browse files Browse the repository at this point in the history
closes #163
closes #705

BREAKING CHANGES:
default format sorting has changed. with no options, you may no
longer get one that has both audio and video on some videos.
  • Loading branch information
fent committed Oct 25, 2020
1 parent f7b4e3b commit 0d27df3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const sortFormatsByAudio = (a, b) => sortFormatsBy(a, b, [
*/
exports.sortFormats = (a, b) => sortFormatsBy(a, b, [
// Formats with both video and audio are ranked highest.
format => +!!format.isHLS,
format => +!!format.isDashMPD,
format => +(format.contentLength > 0),
format => +(format.hasVideo && format.hasAudio),
format => +format.hasVideo,
format => parseInt(format.qualityLabel) || 0,
Expand Down
14 changes: 12 additions & 2 deletions test/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const formats = [
codecs: 'mp4a.40.2',
videoCodec: null,
audioCodec: 'avc1.42001E, mp4a.40.2',
bitrate: 500000,
bitrate: null,
audioBitrate: 96,
url: 'https://googlevideo.com/',
hasVideo: false,
Expand Down Expand Up @@ -157,7 +157,17 @@ describe('util.sortFormats()', () => {
sortedFormats.sort(util.sortFormats);
const itags = sortedFormats.map(getItags);
assert.deepEqual(itags, [
'43', '18', '5', '36', '17', '133', '160', '19', '140', '139', '138',
'43',
'18',
'5',
'36',
'17',
'133',
'160',
'140',
'19',
'139',
'138',
]);
});
});
Expand Down

0 comments on commit 0d27df3

Please sign in to comment.