From 628736f3d709baa74cea07ef6bd5613c2dbe2d77 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Wed, 25 Jun 2025 02:14:31 +1200 Subject: [PATCH] Fixes to API Extended on TV --- materialious/src/lib/api/index.ts | 13 +++++++++---- materialious/src/lib/components/Player.svelte | 15 +++++++++++---- materialious/src/lib/patches/youtubejs.ts | 2 +- .../src/routes/(no-layout)/tv/[slug]/+page.svelte | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/materialious/src/lib/api/index.ts b/materialious/src/lib/api/index.ts index d9d80f98..c3e40d9d 100644 --- a/materialious/src/lib/api/index.ts +++ b/materialious/src/lib/api/index.ts @@ -420,13 +420,18 @@ export async function getThumbnail( return URL.createObjectURL(await resp.blob()); } +function buildApiExtendedAuthHeaders(): Record> { + const authToken = get(authStore)?.token ?? ''; + return { headers: { Authorization: `Bearer ${authToken.replace('SID=', '')}` } }; +} + export async function getVideoProgress( videoId: string, fetchOptions: RequestInit = {} ): Promise { const resp = await fetchErrorHandle( await fetch(`${get(synciousInstanceStore)}/video/${encodeURIComponent(videoId)}`, { - ...buildAuthHeaders(), + ...buildApiExtendedAuthHeaders(), ...fetchOptions }) ); @@ -439,7 +444,7 @@ export async function saveVideoProgress( time: number, fetchOptions: RequestInit = {} ) { - const headers: Record> = buildAuthHeaders(); + const headers: Record> = buildApiExtendedAuthHeaders(); headers['headers']['Content-type'] = 'application/json'; await fetchErrorHandle( @@ -458,7 +463,7 @@ export async function deleteVideoProgress(videoId: string, fetchOptions: Request await fetchErrorHandle( await fetch(`${get(synciousInstanceStore)}/video/${videoId}`, { method: 'DELETE', - ...buildAuthHeaders(), + ...buildApiExtendedAuthHeaders(), ...fetchOptions }) ); @@ -468,7 +473,7 @@ export async function deleteAllVideoProgress(fetchOptions: RequestInit = {}) { await fetchErrorHandle( await fetch(`${get(synciousInstanceStore)}/videos`, { method: 'DELETE', - ...buildAuthHeaders(), + ...buildApiExtendedAuthHeaders(), ...fetchOptions }) ); diff --git a/materialious/src/lib/components/Player.svelte b/materialious/src/lib/components/Player.svelte index 28ee99e9..6c91c8c5 100644 --- a/materialious/src/lib/components/Player.svelte +++ b/materialious/src/lib/components/Player.svelte @@ -378,6 +378,9 @@ } } + if (watchProgressTimeout) { + clearInterval(watchProgressTimeout); + } // Auto save watch progress every minute. watchProgressTimeout = setInterval(() => savePlayerPos(), 60000); setupSponsorSkip(); @@ -588,6 +591,10 @@ return false; }); + playerElement.addEventListener('pause', async () => { + savePlayerPos(); + }); + playerElement.addEventListener('ended', async () => { if (!data.playlistId) { if ($playerAutoplayNextByDefaultStore) { @@ -719,16 +726,16 @@ } } + try { + savePlayerPos(); + } catch (error) {} + Mousetrap.unbind(['left', 'right', 'space', 'c', 'f', 'shift+left', 'shift+right']); if (watchProgressTimeout) { clearTimeout(watchProgressTimeout); } - try { - savePlayerPos(); - } catch (error) {} - HttpFetchPlugin.cacheManager.clearCache(); if (playerElementResizeObserver) { diff --git a/materialious/src/lib/patches/youtubejs.ts b/materialious/src/lib/patches/youtubejs.ts index 80cdcaaa..3f37d336 100644 --- a/materialious/src/lib/patches/youtubejs.ts +++ b/materialious/src/lib/patches/youtubejs.ts @@ -184,7 +184,7 @@ export async function patchYoutubeJs(videoId: string): Promise { formatStreams: [], recommendedVideos: recommendedVideos, authorThumbnails: authorThumbnails, - captions: captions, + captions: [], authorId: video.basic_info.channel_id || '', authorUrl: `/channel/${video.basic_info.channel_id}`, authorVerified: false, diff --git a/materialious/src/routes/(no-layout)/tv/[slug]/+page.svelte b/materialious/src/routes/(no-layout)/tv/[slug]/+page.svelte index 4556c967..2798029d 100644 --- a/materialious/src/routes/(no-layout)/tv/[slug]/+page.svelte +++ b/materialious/src/routes/(no-layout)/tv/[slug]/+page.svelte @@ -114,7 +114,7 @@
{ if (playerElement) playerElement.currentTime = timestamp.time; }}