Skip to content

Commit

Permalink
fix: fix unexpected token ) in JSON error
Browse files Browse the repository at this point in the history
fixes #727
  • Loading branch information
fent committed Oct 16, 2020
1 parent bc5156a commit dd582ae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/info.js
Expand Up @@ -60,6 +60,10 @@ exports.getBasicInfo = async(id, options) => {
let body = await miniget(jsonEndpointURL, reqOptions).text();
let info;
try {
let jsonClosingChars = /^[)\]}'\s]+/;
if (jsonClosingChars.test(body)) {
body = body.replace(jsonClosingChars, '');
}
let parsedBody = JSON.parse(body);
if (parsedBody.reload === 'now' && !reqOptions.headers['x-youtube-identity-token']) {
await setIdentityToken('browser');
Expand Down
2 changes: 2 additions & 0 deletions test/files/videos/with-cookie/watch-reload-now-2.json
@@ -0,0 +1,2 @@
)]}'
{"reload":"now"}
2 changes: 1 addition & 1 deletion test/info-test.js
Expand Up @@ -270,7 +270,7 @@ describe('ytdl.getInfo()', () => {
const id = '99_Y8iEy95c';
const scope = nock(id, {
type: 'with-cookie',
watch: 'reload-now',
watch: 'reload-now-2',
watchHtml: true,
player: true,
dashmpd: true,
Expand Down

0 comments on commit dd582ae

Please sign in to comment.