Subtitle fix for companion

This commit is contained in:
WardPearce
2025-11-05 04:52:26 +13:00
parent 1a1a4e5f59
commit 16b7d43321
4 changed files with 25 additions and 36 deletions
+9
View File
@@ -106,6 +106,15 @@ http:
### Invidious Companion support
The `VITE_DEFAULT_COMPANION_INSTANCE` environment variable allows you to specify a custom [Invidious Companion](https://github.com/iv-org/invidious-companion) instance.
`public_url` **MUST** be set in Invidious under **invidious_companion** for companion to work with Materialious.
e.g.
```yml
invidious_companion:
- private_url: "http://companion:8282/companion"
public_url: "http://companion.example.com/companion"
```
To use this with Materialious, your Invidious Companion instance must be accessible with proper CORS headers. Fortunately, you can reuse the same reverse proxy configuration (with CORS modifications) that you applied to your Invidious instance—just apply it to your companion domain as well.
For example, if you're using Caddy, you can configure your companion domain like this:
+1 -9
View File
@@ -1,10 +1,2 @@
# Public instances
- [app.materialio.us](https://app.materialio.us)
- **Location:** New Zealand
- **Threads:** 6
- **IPV6 rotation:** Yes
- **Man in the Middle:** No
- **Accounts:** Yes
- **RYD-Proxy:** Yes
- **API Extended integration:** Yes
- **Self-hosted PeerJS:** No
N/A
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "Materialious",
"version": "1.11.1",
"version": "1.11.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "Materialious",
"version": "1.11.1",
"version": "1.11.2",
"license": "MIT",
"dependencies": {
"@capacitor-community/electron": "^5.0.0",
+13 -25
View File
@@ -324,16 +324,11 @@
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 (usingCorsCompanionPatch) {
if (import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE) {
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');
@@ -345,19 +340,6 @@
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 &&
@@ -370,14 +352,15 @@
}
if (data.video.captions) {
console.log(data.video.captions);
for (const caption of data.video.captions) {
let captionUrl: string;
if (!usingCorsCompanionPatch) {
if (!import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE) {
captionUrl = caption.url.startsWith('http')
? caption.url
: `${get(instanceStore)}${usingCompanion ? '/companion' : ''}${caption.url}`;
: `${get(instanceStore)}${caption.url}`;
} else {
captionUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE}/api/v1/captions/${data.video.videoId}`;
captionUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE}${caption.url}`;
}
await player.addTextTrackAsync(
@@ -732,10 +715,15 @@
try {
await loadVideo();
} catch (error: unknown) {
if (!Capacitor.isNativePlatform() || data.video.fallbackPatch === 'youtubejs') return;
showVideoRetry = true;
if (
!Capacitor.isNativePlatform() ||
data.video.fallbackPatch === 'youtubejs' ||
(error as shaka.extern.Error).code !== 1001
)
return;
if ((error as shaka.extern.Error).code === 1001 && $playerYouTubeJsFallback) {
showVideoRetry = true;
if ($playerYouTubeJsFallback) {
await reloadVideo();
}
}