Fixes to API Extended on TV

This commit is contained in:
WardPearce
2025-06-25 02:14:31 +12:00
parent be45075752
commit 628736f3d7
4 changed files with 22 additions and 10 deletions
+9 -4
View File
@@ -420,13 +420,18 @@ export async function getThumbnail(
return URL.createObjectURL(await resp.blob());
}
function buildApiExtendedAuthHeaders(): Record<string, Record<string, string>> {
const authToken = get(authStore)?.token ?? '';
return { headers: { Authorization: `Bearer ${authToken.replace('SID=', '')}` } };
}
export async function getVideoProgress(
videoId: string,
fetchOptions: RequestInit = {}
): Promise<SynciousProgressModel[]> {
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<string, Record<string, string>> = buildAuthHeaders();
const headers: Record<string, Record<string, string>> = 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
})
);
+11 -4
View File
@@ -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) {
+1 -1
View File
@@ -184,7 +184,7 @@ export async function patchYoutubeJs(videoId: string): Promise<VideoPlay> {
formatStreams: [],
recommendedVideos: recommendedVideos,
authorThumbnails: authorThumbnails,
captions: captions,
captions: [],
authorId: video.basic_info.channel_id || '',
authorUrl: `/channel/${video.basic_info.channel_id}`,
authorVerified: false,
@@ -114,7 +114,7 @@
<ContentColumn>
<article
role="presentation"
style="cursor: pointer;"
style="cursor: pointer;height: 100%;"
onclick={() => {
if (playerElement) playerElement.currentTime = timestamp.time;
}}