Skip to content

Commit

Permalink
fix(youtube): YouTube changed it back, check for both cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Jul 12, 2019
1 parent 39f16e2 commit c32cbc9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions background/sources/videos/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ export default {
data: { 'flow': 2 },
responseType: 'text',
});
const key = 'window["ytInitialData"] = JSON.parse("';
let response = body;
response = response.slice(response.indexOf(key) + key.length);
response = response.slice(0, response.indexOf('");\n'));
response = response.replace(/\\([\\"])/g, '$1');
let match = /window\["ytInitialData"\] = (JSON\.parse\(")?(.+?)(?:"\))?;\n/
.exec(body);
if (!match) {
throw Error('Unable to find youtube data');
}
let response = match[2];
if (match[1]) {
response = response.replace(/\\([\\"])/g, '$1');
}
try {
response = JSON.parse(response);
} catch (err) {
Expand Down

0 comments on commit c32cbc9

Please sign in to comment.