Skip to content

Commit

Permalink
fix: sort formats when format.qualityLabel contains more than resol…
Browse files Browse the repository at this point in the history
…ution
  • Loading branch information
fent committed Apr 11, 2020
1 parent e178fe8 commit cf1e6c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ const audioScore = format => {
* @param {Object} b
*/
exports.sortFormats = (a, b) => {
const ares = a.qualityLabel ? parseInt(a.qualityLabel.slice(0, -1)) : 0;
const bres = b.qualityLabel ? parseInt(b.qualityLabel.slice(0, -1)) : 0;
const getResolution = format => {
const result = /(\d+)p/.exec(format.qualityLabel);
return result ? parseInt(result[1]) : 0;
};
const ares = getResolution(a);
const bres = getResolution(b);
const afeats = (~~!!ares * 2) + ~~!!a.audioBitrate;
const bfeats = (~~!!bres * 2) + ~~!!b.audioBitrate;

Expand Down
2 changes: 1 addition & 1 deletion test/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const formats = [
{ itag: '17',
mimeType: 'video/3gpp; codecs="mp4v.20.3, mp4a.40.2"',
container: '3gp',
qualityLabel: '144p',
qualityLabel: '144p @ 60fps',
codecs: 'mp4v.20.3, mp4a.40.2',
bitrate: 50000,
audioBitrate: 24 },
Expand Down

0 comments on commit cf1e6c0

Please sign in to comment.