From fd5c516b8084542f0f5db95dfbddbe668b326b56 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Fri, 30 May 2025 23:22:12 +1200 Subject: [PATCH] Force SABR unless is live --- materialious/electron/package-lock.json | 4 +- materialious/package-lock.json | 16 ++-- materialious/package.json | 4 +- ...4.13.0.patch => shaka-player+4.11.7.patch} | 21 ++--- materialious/src/lib/components/Player.svelte | 88 +++++++------------ 5 files changed, 57 insertions(+), 76 deletions(-) rename materialious/patches/{shaka-player+4.13.0.patch => shaka-player+4.11.7.patch} (66%) diff --git a/materialious/electron/package-lock.json b/materialious/electron/package-lock.json index 357d004c..3effef41 100644 --- a/materialious/electron/package-lock.json +++ b/materialious/electron/package-lock.json @@ -1,12 +1,12 @@ { "name": "Materialious", - "version": "1.8.6", + "version": "1.8.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Materialious", - "version": "1.8.6", + "version": "1.8.7", "license": "MIT", "dependencies": { "@capacitor-community/electron": "^5.0.0", diff --git a/materialious/package-lock.json b/materialious/package-lock.json index a525dfcf..ea02225a 100644 --- a/materialious/package-lock.json +++ b/materialious/package-lock.json @@ -1,12 +1,12 @@ { "name": "materialious", - "version": "1.8.6", + "version": "1.8.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "materialious", - "version": "1.8.6", + "version": "1.8.7", "hasInstallScript": true, "dependencies": { "@capacitor-community/electron": "^5.0.1", @@ -32,7 +32,7 @@ "media-captions": "^1.0.4", "mousetrap": "^1.6.5", "peerjs": "^1.5.4", - "shaka-player": "^4.13.0", + "shaka-player": "^4.11.7", "sponsorblock-api": "^0.2.4", "svelte-i18n": "^4.0.1", "svelte-infinite-loading": "^1.4.0", @@ -11379,15 +11379,15 @@ } }, "node_modules/shaka-player": { - "version": "4.13.0", - "resolved": "https://registry.npmjs.org/shaka-player/-/shaka-player-4.13.0.tgz", - "integrity": "sha512-FZToyYl7IXvt1oMEWVbU0tjWJpJ+oSYpUibNMxSqVQx2pLfSBDfEuodGJV+pRgiydYQ58+VFLftAylDx/Qvfdw==", + "version": "4.11.7", + "resolved": "https://registry.npmjs.org/shaka-player/-/shaka-player-4.11.7.tgz", + "integrity": "sha512-jNsdQd4pa24w2QwXHGNBs8MQ33YajYiZclWaSuGt+dLJ7/D9+NG1LJQGnTrGd0G1aDdbEzmEpppG3ic4OsGpyw==", "license": "Apache-2.0", "dependencies": { - "eme-encryption-scheme-polyfill": "^2.2.0" + "eme-encryption-scheme-polyfill": "^2.1.5" }, "engines": { - "node": ">=18" + "node": ">=14" } }, "node_modules/sharp": { diff --git a/materialious/package.json b/materialious/package.json index 911b0e87..ca71130b 100644 --- a/materialious/package.json +++ b/materialious/package.json @@ -63,7 +63,7 @@ "media-captions": "^1.0.4", "mousetrap": "^1.6.5", "peerjs": "^1.5.4", - "shaka-player": "^4.13.0", + "shaka-player": "^4.11.7", "sponsorblock-api": "^0.2.4", "svelte-i18n": "^4.0.1", "svelte-infinite-loading": "^1.4.0", @@ -71,4 +71,4 @@ "terser": "^5.34.1", "youtubei.js": "^13.4.0" } -} \ No newline at end of file +} diff --git a/materialious/patches/shaka-player+4.13.0.patch b/materialious/patches/shaka-player+4.11.7.patch similarity index 66% rename from materialious/patches/shaka-player+4.13.0.patch rename to materialious/patches/shaka-player+4.11.7.patch index 316e5cd5..359f2e50 100644 --- a/materialious/patches/shaka-player+4.13.0.patch +++ b/materialious/patches/shaka-player+4.11.7.patch @@ -1,31 +1,31 @@ diff --git a/node_modules/shaka-player/dist/shaka-player.compiled.d.ts b/node_modules/shaka-player/dist/shaka-player.compiled.d.ts -index 0971e58..9d5c515 100644 +index 19c0930..cc0a3fd 100644 --- a/node_modules/shaka-player/dist/shaka-player.compiled.d.ts +++ b/node_modules/shaka-player/dist/shaka-player.compiled.d.ts -@@ -5266,3 +5266,5 @@ declare namespace shaka.extern { +@@ -5117,3 +5117,5 @@ declare namespace shaka.extern { declare namespace shaka.extern { type TransmuxerPlugin = ( ) => shaka.extern.Transmuxer ; } + +export default shaka; diff --git a/node_modules/shaka-player/dist/shaka-player.ui.d.ts b/node_modules/shaka-player/dist/shaka-player.ui.d.ts -index 460e009..41bab00 100644 +index 1618ca0..a6076c6 100644 --- a/node_modules/shaka-player/dist/shaka-player.ui.d.ts +++ b/node_modules/shaka-player/dist/shaka-player.ui.d.ts -@@ -6011,3 +6011,5 @@ declare namespace shaka.extern { - declare namespace shaka.ui.Watermark { - type Options = { alpha : number , color : string , displayDuration : number , interval : number , position : string , size : number , skip : number , text : string , transitionDuration : number , type : string } ; +@@ -5830,3 +5830,5 @@ declare namespace shaka.extern { + declare namespace shaka.extern { + type UIVolumeBarColors = { base : string , level : string } ; } + +export default shaka; diff --git a/node_modules/shaka-player/index.d.ts b/node_modules/shaka-player/index.d.ts new file mode 100644 -index 0000000..79f4829 +index 0000000..3ebfd96 --- /dev/null +++ b/node_modules/shaka-player/index.d.ts @@ -0,0 +1,2 @@ -+ -+ ++/// ++/// \ No newline at end of file diff --git a/node_modules/shaka-player/ui.d.ts b/node_modules/shaka-player/ui.d.ts new file mode 100644 @@ -35,4 +35,5 @@ index 0000000..84a3be0 @@ -0,0 +1,3 @@ +import shaka from 'shaka-player/dist/shaka-player.ui' +export * from 'shaka-player/dist/shaka-player.ui' -+export default shaka; \ No newline at end of file ++export default shaka; +\ No newline at end of file \ No newline at end of file diff --git a/materialious/src/lib/components/Player.svelte b/materialious/src/lib/components/Player.svelte index f9ee5fc2..fd09788f 100644 --- a/materialious/src/lib/components/Player.svelte +++ b/materialious/src/lib/components/Player.svelte @@ -76,7 +76,6 @@ '' ); let isLive = false; - let isPostLiveDVR = false; let videoPlaybackUstreamerConfig: string | undefined; let serverAbrStreamingUrl: URL | undefined = undefined; let drmParams: string | undefined; @@ -186,16 +185,10 @@ enabled: true, restrictions: { maxWidth: 1920, - maxHeight: 1080, - maxBandwidth: data.video.ytjs - ? Number( - data.video.ytjs?.video.page[0].player_config?.stream_selection_config.max_bitrate - ) - : -1 + maxHeight: 1080 } }, streaming: { - autoLowLatencyMode: true, bufferingGoal: 120, rebufferingGoal: 0.01, bufferBehind: 300, @@ -262,7 +255,6 @@ if (data.video.fallbackPatch === 'youtubejs' && data.video.ytjs) { isLive = !!data.video.ytjs.video.basic_info.is_live; - isPostLiveDVR = !!data.video.ytjs.video.basic_info.is_post_live_dvr; if ( data.video.ytjs.rawApiResponse.data.streamingData && @@ -305,6 +297,11 @@ lastActionMs = Date.now(); }); + player.addEventListener('error', (event) => { + const error = (event as CustomEvent).detail as shaka.util.Error; + console.error('Player error:', error); + }); + const networkingEngine = player.getNetworkingEngine(); if (!networkingEngine) return; @@ -337,10 +334,7 @@ type === shaka.net.NetworkingEngine.RequestType.SEGMENT && url.pathname.includes('videoplayback') ) { - const isUmp = url.searchParams.get('ump') === '1'; - const isSabr = url.searchParams.get('sabr') === '1'; - - if (isSabr) { + if (!isLive) { const currentFormat = formatList.find( (format) => fromFormat(format) === (new URL(request.uris[0]).searchParams.get('___key') || '') @@ -493,18 +487,9 @@ // @NOTE: Not a real header. See the http plugin code for more info. request.headers['X-Streaming-Context'] = btoa(JSON.stringify(sabrStreamingContext)); delete headers.Range; - } else if (isUmp) { - if (!isLive && !isPostLiveDVR) { - url.searchParams.set('ump', '1'); - url.searchParams.set('srfvp', '1'); - if (headers.Range) { - url.searchParams.set('range', headers.Range?.split('=')[1]); - delete headers.Range; - } - } else { - url.pathname += '/ump/1'; - url.pathname += '/srfvp/1'; - } + } else { + url.pathname += '/ump/1'; + url.pathname += '/srfvp/1'; request.headers['X-Streaming-Context'] = btoa( JSON.stringify({ @@ -512,23 +497,11 @@ isSABR: false }) ); + + url.pathname += '/pot/' + get(poTokenCacheStore); } request.method = 'POST'; - - if (!isSabr) { - request.body = new Uint8Array([120, 0]); - const poToken = get(poTokenCacheStore); - - if (poToken) { - // Set Proof of Origin Token - if (isLive || isPostLiveDVR) { - url.pathname += '/pot/' + poToken; - } else { - url.searchParams.set('pot', poToken); - } - } - } } else if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) { const wrapped = {} as Record; wrapped.context = data.video.ytjs?.innertube.session.context; @@ -567,7 +540,7 @@ const sabrStreamingContext = response.headers['X-Streaming-Context']; if (sabrStreamingContext) { - const { streamInfo, isSABR, format, byteRange } = JSON.parse( + const { streamInfo, format, byteRange } = JSON.parse( atob(sabrStreamingContext) ) as SabrStreamingContext; @@ -582,11 +555,8 @@ if (sabrRedirect?.url && !response.data.byteLength) { let redirectUrl = new URL(sabrRedirect.url); - // For SABR, create a fake URL so we can identify it in the request filter. - if (isSABR) { - serverAbrStreamingUrl = redirectUrl; - redirectUrl = new URL(`https://sabr?___key=${fromFormat(format) || ''}`); - } + serverAbrStreamingUrl = redirectUrl; + redirectUrl = new URL(`https://sabr?___key=${fromFormat(format) || ''}`); const retryParameters = player!.getConfiguration().streaming.retryParameters; @@ -596,7 +566,7 @@ ); // Keep range so we can slice the response (only if it's the init segment). - if (isSABR && byteRange) { + if (typeof byteRange !== 'undefined') { redirectRequest.headers['Range'] = `bytes=${byteRange.start}-${byteRange.end}`; } @@ -982,12 +952,6 @@ } onDestroy(async () => { - HttpFetchPlugin.cacheManager.clearCache(); - - if (playerElementResizeObserver) { - playerElementResizeObserver.disconnect(); - } - if (Capacitor.getPlatform() === 'android') { if (originalOrigination) { await StatusBar.setOverlaysWebView({ overlay: false }); @@ -1003,9 +967,25 @@ try { savePlayerPos(); } catch (error) {} - await player.destroy(); - await shakaUi.destroy(); playerPosSet = false; + HttpFetchPlugin.cacheManager.clearCache(); + + if (playerElementResizeObserver) { + playerElementResizeObserver.disconnect(); + } + + if (playerElement) { + playerElement.src = ''; + playerElement.load(); + } + + if (player) { + player.destroy(); + } + + if (shakaUi) { + shakaUi.destroy(); + } });