Skip to content

Commit

Permalink
fix: check if format contains url
Browse files Browse the repository at this point in the history
fixes #624

Squashed commit of the following:

commit f1f5115
Author: fent <933490+fent@users.noreply.github.com>
Date:   Tue May 19 13:44:27 2020 -0400

    test: updqate tests

commit 808c949
Merge: a802b6c df05ca7
Author: fent <933490+fent@users.noreply.github.com>
Date:   Tue May 19 13:36:33 2020 -0400

    Merge branch 'master' of github.com:rezemble/node-ytdl-core into rezemble-master

commit df05ca7
Author: rezemble <689071+rezemble@users.noreply.github.com>
Date:   Fri May 8 22:25:44 2020 +0200

    Check if format contains URL
  • Loading branch information
fent committed May 19, 2020
1 parent a802b6c commit 0d6e8e5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ exports.filterFormats = (formats, filter) => {
throw TypeError(`Given filter (${filter}) is not supported`);
}
}
return formats.filter(fn);
return formats.filter(format => !!format.url && fn(format));
};


Expand Down
51 changes: 39 additions & 12 deletions test/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,77 +10,99 @@ const formats = [
qualityLabel: '360p',
codecs: 'avc1.42001E, mp4a.40.2',
bitrate: 500000,
audioBitrate: 96 },
audioBitrate: 96,
url: 'https://googlevideo.com/',
},
{ itag: '19',
mimeType: 'audio/mp4; codecs="avc1.42001E, mp4a.40.2"',
container: 'mp4',
qualityLabel: null,
codecs: 'avc1.42001E, mp4a.40.2',
bitrate: 500000,
audioBitrate: 96 },
audioBitrate: 96,
url: 'https://googlevideo.com/',
},

{ itag: '43',
mimeType: 'video/webm; codecs="vp8.0, vorbis"',
container: 'webm',
qualityLabel: '360p',
codecs: 'vp8.0, vorbis',
bitrate: 500000,
audioBitrate: 128 },
audioBitrate: 128,
url: 'https://googlevideo.com/',
},
{ itag: '133',
mimeType: 'video/mp4; codecs="avc1.4d400d"',
container: 'mp4',
qualityLabel: '240p',
codecs: 'avc1.4d400d',
bitrate: 300000,
audioBitrate: null },
audioBitrate: null,
url: 'https://googlevideo.com/',
},
{ itag: '36',
mimeType: 'video/3gpp; codecs="mp4v.20.3, mp4a.40.2"',
container: '3gp',
qualityLabel: '240p',
codecs: 'mp4v.20.3, mp4a.40.2',
bitrate: 170000,
audioBitrate: 38 },
audioBitrate: 38,
url: 'https://googlevideo.com/',
},
{ itag: '5',
mimeType: 'video/flv; codecs="Sorenson H.283, mp3"',
container: 'flv',
qualityLabel: '240p',
codecs: 'Sorenson H.283, mp3',
bitrate: 250000,
audioBitrate: 64 },
audioBitrate: 64,
url: 'https://googlevideo.com/',
},
{ itag: '160',
mimeType: 'video/mp4; codecs="avc1.4d400c"',
container: 'mp4',
qualityLabel: '144p',
codecs: 'avc1.4d400c',
bitrate: 100000,
audioBitrate: null },
audioBitrate: null,
url: 'https://googlevideo.com/',
},
{ itag: '17',
mimeType: 'video/3gpp; codecs="mp4v.20.3, mp4a.40.2"',
container: '3gp',
qualityLabel: '144p @ 60fps',
codecs: 'mp4v.20.3, mp4a.40.2',
bitrate: 50000,
audioBitrate: 24 },
audioBitrate: 24,
url: 'https://googlevideo.com/',
},
{ itag: '140',
mimeType: 'audio/mp4; codecs="mp4a.40.2"',
container: 'mp4',
qualityLabel: null,
codecs: 'mp4a.40.2',
bitrate: null,
audioBitrate: 128 },
audioBitrate: 128,
url: 'https://googlevideo.com/',
},
{ itag: '139',
mimeType: 'audio/mp4; codecs="mp4a.40.2"',
container: 'mp4',
qualityLabel: null,
codecs: 'mp4a.40.2',
bitrate: null,
audioBitrate: null },
audioBitrate: null,
},
{ itag: '138',
mimeType: 'audio/mp4; codecs="mp4a.40.2"',
container: 'mp4',
qualityLabel: null,
codecs: 'mp4a.40.2',
bitrate: null,
audioBitrate: null },
audioBitrate: null,
url: 'https://googlevideo.com/',
},
];
const getItags = format => format.itag;

Expand Down Expand Up @@ -203,7 +225,12 @@ describe('util.filterFormats', () => {
it('Tries to find formats that match', () => {
const filter = format => format.container === 'mp4';
const itags = util.filterFormats(formats, filter).map(getItags);
assert.deepEqual(itags, ['18', '19', '133', '160', '140', '139', '138']);
assert.deepEqual(itags, ['18', '19', '133', '160', '140', '138']);
});

it('Ignores formats without a `url`', () => {
const itags = util.filterFormats(formats, () => true).map(getItags);
assert.deepEqual(itags, ['18', '19', '43', '133', '36', '5', '160', '17', '140', '138']);
});

it('Is exposed in module', () => {
Expand Down

0 comments on commit 0d6e8e5

Please sign in to comment.