Companion Fixes

This commit is contained in:
WardPearce
2025-11-05 04:14:25 +13:00
parent 452a280cad
commit a0055cf088
2 changed files with 34 additions and 3 deletions
+29 -3
View File
@@ -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,
@@ -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;