From e71c8280f69b158d47c6cb729d62fc681c7e88f5 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sat, 7 Sep 2024 17:01:21 +1200 Subject: [PATCH] Minor fixes --- materialious/src/lib/Api/index.ts | 2 ++ materialious/src/lib/Player.svelte | 22 ++++++++++++++-------- materialious/src/lib/Thumbnail.svelte | 3 ++- materialious/src/lib/store.ts | 17 ++++++++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/materialious/src/lib/Api/index.ts b/materialious/src/lib/Api/index.ts index 706fd5ac..5939a1f9 100644 --- a/materialious/src/lib/Api/index.ts +++ b/materialious/src/lib/Api/index.ts @@ -175,6 +175,8 @@ export async function getSubscriptions(): Promise { } export async function amSubscribed(authorId: string): Promise { + if (!get(authStore)) return false; + try { const subscriptions = (await getSubscriptions()).filter((sub) => sub.authorId === authorId); return subscriptions.length === 1; diff --git a/materialious/src/lib/Player.svelte b/materialious/src/lib/Player.svelte index c819ee80..8eb5c41a 100644 --- a/materialious/src/lib/Player.svelte +++ b/materialious/src/lib/Player.svelte @@ -4,6 +4,7 @@ import { page } from '$app/stores'; import { Capacitor } from '@capacitor/core'; import type { Page } from '@sveltejs/kit'; + import { type ParsedCaptionsResult } from 'media-captions'; import { SponsorBlock, type Category } from 'sponsorblock-api'; import { onDestroy, onMount } from 'svelte'; import { _ } from 'svelte-i18n'; @@ -26,6 +27,7 @@ sponsorBlockDisplayToastStore, sponsorBlockStore, sponsorBlockUrlStore, + synciousInstanceStore, synciousStore } from './store'; import { getDynamicTheme } from './theme'; @@ -41,6 +43,8 @@ let playerIsLive = false; let playerPosSet = false; + let transcript: ParsedCaptionsResult; + function loadTimeFromUrl(page: Page): boolean { if (player) { const timeGivenUrl = page.url.searchParams.get('time'); @@ -90,11 +94,13 @@ timestampIndex += 1; }); - player.textTracks.add({ - kind: 'chapters', - src: URL.createObjectURL(new Blob([chapterWebVTT])), - default: true - }); + if (timestampIndex > 0) { + player.textTracks.add({ + kind: 'chapters', + src: URL.createObjectURL(new Blob([chapterWebVTT])), + default: true + }); + } } player.addEventListener('pause', () => { @@ -217,7 +223,7 @@ let toSetTime = 0; - if (get(synciousStore) && get(authStore)) { + if (get(synciousStore) && get(synciousInstanceStore) && get(authStore)) { try { toSetTime = (await getVideoProgress(data.video.videoId))[0].time; } catch {} @@ -244,7 +250,7 @@ localStorage.setItem(`v_${data.video.videoId}`, player.currentTime.toString()); } catch {} - if (get(synciousStore) && get(authStore)) { + if (get(synciousStore) && get(synciousInstanceStore) && get(authStore)) { saveVideoProgress(data.video.videoId, player.currentTime); } } else { @@ -252,7 +258,7 @@ localStorage.removeItem(`v_${data.video.videoId}`); } catch {} - if (get(synciousStore) && get(authStore)) { + if (get(synciousStore) && get(synciousInstanceStore) && get(authStore)) { deleteVideoProgress(data.video.videoId); } } diff --git a/materialious/src/lib/Thumbnail.svelte b/materialious/src/lib/Thumbnail.svelte index d52c9f3f..e51d3757 100644 --- a/materialious/src/lib/Thumbnail.svelte +++ b/materialious/src/lib/Thumbnail.svelte @@ -22,6 +22,7 @@ playerSavePlaybackPositionStore, syncPartyConnectionsStore, syncPartyPeerStore, + synciousInstanceStore, synciousStore } from './store'; @@ -195,7 +196,7 @@ loading = false; }; - if (get(synciousStore) && get(authStore)) { + if (get(synciousStore) && get(synciousInstanceStore) && get(authStore)) { try { progress = (await getVideoProgress(video.videoId))[0].time.toString(); } catch {} diff --git a/materialious/src/lib/store.ts b/materialious/src/lib/store.ts index 09507886..2b7f59ce 100644 --- a/materialious/src/lib/store.ts +++ b/materialious/src/lib/store.ts @@ -1,13 +1,24 @@ import type { VideoPlay } from '$lib/Api/model'; +import { Capacitor } from '@capacitor/core'; import type Peer from 'peerjs'; import type { DataConnection } from 'peerjs'; import { persisted } from 'svelte-persisted-store'; import { writable, type Writable } from 'svelte/store'; import type { TitleCase } from './misc'; + +function platformDependentDefault(givenValue: any, defaultValue: any): any { + if (typeof givenValue !== 'undefined' || typeof givenValue !== null) { + return givenValue; + } else if (defaultValue && Capacitor.getPlatform() !== 'web') { + return defaultValue; + } +} + + export const instanceStore: Writable = persisted( "invidiousInstance", - import.meta.env.VITE_DEFAULT_INVIDIOUS_INSTANCE || 'https://invidious.materialio.us' + platformDependentDefault(import.meta.env.VITE_DEFAULT_INVIDIOUS_INSTANCE, 'https://invidious.materialio.us') ); export const authStore: Writable = persisted( @@ -34,13 +45,13 @@ export const playerAndroidBackgroundPlayStore = persisted('androidBackgroundPlay export const returnYtDislikesStore = persisted('returnYtDislikes', false); export const returnYTDislikesInstanceStore: Writable = persisted( 'returnYTDislikesInstance', - import.meta.env.VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE || 'https://ryd-proxy.materialio.us' + platformDependentDefault(import.meta.env.VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE, 'https://ryd-proxy.materialio.us') ); export const synciousStore = persisted('syncious', true); export const synciousInstanceStore: Writable = persisted( 'synciousInstance', - import.meta.env.VITE_DEFAULT_SYNCIOUS_INSTANCE || 'https://syncious.materialio.us' + platformDependentDefault(import.meta.env.VITE_DEFAULT_SYNCIOUS_INSTANCE, 'https://syncious.materialio.us') ); export const interfaceRegionStore: Writable = persisted('interfaceRegion', 'US');