@@ -22,7 +22,7 @@ const TRACKING_PARAM_NAMES = [
2222
2323if ( process . env . SUPPORTS_LOCAL_API ) {
2424 Platform . shim . eval = ( data , env ) => {
25- return new Promise ( ( resolve ) => {
25+ return new Promise ( ( resolve , reject ) => {
2626 const properties = [ ]
2727
2828 if ( env . n ) {
@@ -43,23 +43,31 @@ if (process.env.SUPPORTS_LOCAL_API) {
4343 ? crypto . randomUUID ( )
4444 : `${ Date . now ( ) } -${ Math . floor ( Math . random ( ) * 10000 ) } `
4545
46- const iframe = document . getElementById ( 'sigFrame' )
46+ if ( process . env . IS_ELECTRON ) {
47+ const iframe = document . getElementById ( 'sigFrame' )
4748
48- /** @param {MessageEvent } event */
49- const listener = ( event ) => {
50- if ( event . source === iframe . contentWindow && typeof event . data === 'string' ) {
51- const data = JSON . parse ( event . data )
49+ /** @param {MessageEvent } event */
50+ const listener = ( event ) => {
51+ if ( event . source === iframe . contentWindow && typeof event . data === 'string' ) {
52+ const data = JSON . parse ( event . data )
5253
53- if ( data . id === messageId ) {
54- window . removeEventListener ( 'message' , listener )
54+ if ( data . id === messageId ) {
55+ window . removeEventListener ( 'message' , listener )
5556
56- resolve ( data . result )
57+ if ( data . error ) {
58+ reject ( data . error )
59+ } else {
60+ resolve ( data . result )
61+ }
62+ }
5763 }
5864 }
59- }
6065
61- window . addEventListener ( 'message' , listener )
62- iframe . contentWindow . postMessage ( JSON . stringify ( { id : messageId , code } ) , '*' )
66+ window . addEventListener ( 'message' , listener )
67+ iframe . contentWindow . postMessage ( JSON . stringify ( { id : messageId , code } ) , '*' )
68+ } else {
69+ reject ( new Error ( 'Please setup the eval function for the n/sig deciphering' ) )
70+ }
6371 } )
6472 }
6573}
@@ -285,23 +293,20 @@ export async function getLocalSearchContinuation(continuationData) {
285293export async function getLocalVideoInfo ( id ) {
286294 const webInnertube = await createInnertube ( { withPlayer : true , generateSessionLocally : false } )
287295
288- // based on the videoId (added to the body of the /player request and to caption URLs)
296+ // based on the videoId
289297 let contentPoToken
290- // based on the visitor data (added to the streaming URLs)
291- let sessionPoToken
292298
293299 if ( process . env . IS_ELECTRON ) {
294300 const { ipcRenderer } = require ( 'electron' )
295301
296302 try {
297- ( { contentPoToken, sessionPoToken } = await ipcRenderer . invoke (
298- IpcChannels . GENERATE_PO_TOKENS ,
303+ contentPoToken = await ipcRenderer . invoke (
304+ IpcChannels . GENERATE_PO_TOKEN ,
299305 id ,
300- webInnertube . session . context . client . visitorData ,
301306 JSON . stringify ( webInnertube . session . context )
302- ) )
307+ )
303308
304- webInnertube . session . player . po_token = sessionPoToken
309+ webInnertube . session . player . po_token = contentPoToken
305310 } catch ( error ) {
306311 console . error ( 'Local API, poToken generation failed' , error )
307312 throw error
@@ -400,9 +405,9 @@ export async function getLocalVideoInfo(id) {
400405 let url = info . streaming_data . dash_manifest_url
401406
402407 if ( url . includes ( '?' ) ) {
403- url += `&pot=${ encodeURIComponent ( sessionPoToken ) } &mpd_version=7`
408+ url += `&pot=${ encodeURIComponent ( contentPoToken ) } &mpd_version=7`
404409 } else {
405- url += `${ url . endsWith ( '/' ) ? '' : '/' } pot/${ encodeURIComponent ( sessionPoToken ) } /mpd_version/7`
410+ url += `${ url . endsWith ( '/' ) ? '' : '/' } pot/${ encodeURIComponent ( contentPoToken ) } /mpd_version/7`
406411 }
407412
408413 info . streaming_data . dash_manifest_url = url
0 commit comments