From a0055cf08831e539644c9169a992bd5db5499692 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Wed, 5 Nov 2025 04:14:25 +1300 Subject: [PATCH] Companion Fixes --- materialious/src/lib/components/Player.svelte | 32 +++++++++++++++++-- .../src/lib/css/shaka-player-theme.css | 5 +++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/materialious/src/lib/components/Player.svelte b/materialious/src/lib/components/Player.svelte index 6c2c5b52..e887a7fa 100644 --- a/materialious/src/lib/components/Player.svelte +++ b/materialious/src/lib/components/Player.svelte @@ -324,15 +324,19 @@ let dashUrl: string; + let usingCorsCompanionPatch = + import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE && Capacitor.getPlatform() === 'web'; + let usingCompanion = false; + // Due to CORs issues with redirects, hosted instances of Materialious // dirctly provide the companion instance // while clients can just use the reirect provided by Invidious' API - if (import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE && Capacitor.getPlatform() === 'web') { + if (usingCorsCompanionPatch) { dashUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE}/api/manifest/dash/id/${data.video.videoId}`; + usingCompanion = true; } else { if (!data.video.dashUrl) { error(500, 'No dash manifest found'); - return; } dashUrl = data.video.dashUrl; } @@ -341,6 +345,19 @@ dashUrl += '?local=true'; } + if (!usingCorsCompanionPatch) { + const dashUrlObject = new URL(dashUrl); + if (!dashUrlObject.pathname.includes('companion')) { + dashUrlObject.pathname = `/companion${dashUrlObject.pathname}`; + + const companionTestResp = await fetch(dashUrlObject, { method: 'HEAD' }); + if (companionTestResp.ok) { + dashUrl = dashUrlObject.toString(); + usingCompanion = true; + } + } + } + if ( Capacitor.getPlatform() === 'android' && $playerProxyVideosStore && @@ -354,8 +371,17 @@ if (data.video.captions) { for (const caption of data.video.captions) { + let captionUrl: string; + if (!usingCorsCompanionPatch) { + captionUrl = caption.url.startsWith('http') + ? caption.url + : `${get(instanceStore)}${usingCompanion ? '/companion' : ''}${caption.url}`; + } else { + captionUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE}/api/v1/captions/${data.video.videoId}`; + } + await player.addTextTrackAsync( - caption.url.startsWith('http') ? caption.url : `${get(instanceStore)}${caption.url}`, + captionUrl, caption.language_code, 'captions', undefined, diff --git a/materialious/src/lib/css/shaka-player-theme.css b/materialious/src/lib/css/shaka-player-theme.css index 75feabaf..fd9e9b85 100644 --- a/materialious/src/lib/css/shaka-player-theme.css +++ b/materialious/src/lib/css/shaka-player-theme.css @@ -7,6 +7,11 @@ color: var(--on-surface) !important; } +.shaka-current-time { + color: #fff !important; + opacity: 1 !important; +} + .player-theme .shaka-video-container * { font-family: var(--font) !important; color: var(--on-surface) !important;