Skip to content

Commit c32cbc9

Browse files
committed
fix(youtube): YouTube changed it back, check for both cases
1 parent 39f16e2 commit c32cbc9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

background/sources/videos/youtube.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ export default {
6868
data: { 'flow': 2 },
6969
responseType: 'text',
7070
});
71-
const key = 'window["ytInitialData"] = JSON.parse("';
72-
let response = body;
73-
response = response.slice(response.indexOf(key) + key.length);
74-
response = response.slice(0, response.indexOf('");\n'));
75-
response = response.replace(/\\([\\"])/g, '$1');
71+
let match = /window\["ytInitialData"\] = (JSON\.parse\(")?(.+?)(?:"\))?;\n/
72+
.exec(body);
73+
if (!match) {
74+
throw Error('Unable to find youtube data');
75+
}
76+
let response = match[2];
77+
if (match[1]) {
78+
response = response.replace(/\\([\\"])/g, '$1');
79+
}
7680
try {
7781
response = JSON.parse(response);
7882
} catch (err) {

0 commit comments

Comments
 (0)