File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
background/sources/videos Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff 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 = / w i n d o w \[ " y t I n i t i a l D a t a " \] = ( J S O N \. p a r s e \( " ) ? ( .+ ?) (?: " \) ) ? ; \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 ) {
You can’t perform that action at this time.
0 commit comments