diff --git a/materialious/src/lib/api/model.ts b/materialious/src/lib/api/model.ts index 55feb8dc..bd1cdc60 100644 --- a/materialious/src/lib/api/model.ts +++ b/materialious/src/lib/api/model.ts @@ -100,7 +100,7 @@ export interface VideoPlay extends Video { genre: string; genreUrl: string; hlsUrl?: string; - dashUrl: string; + dashUrl?: string; adaptiveFormats: AdaptiveFormats[]; formatStreams: FormatStreams[]; recommendedVideos: VideoBase[]; diff --git a/materialious/src/lib/components/ErrorMsg.svelte b/materialious/src/lib/components/ErrorMsg.svelte new file mode 100644 index 00000000..48abe3b0 --- /dev/null +++ b/materialious/src/lib/components/ErrorMsg.svelte @@ -0,0 +1,21 @@ + + +
+ +
+ + + {#if page.error} +
+ {page.error.message} +
+ {/if} +
diff --git a/materialious/src/lib/components/Player.svelte b/materialious/src/lib/components/Player.svelte index 3144cab9..7ab39c19 100644 --- a/materialious/src/lib/components/Player.svelte +++ b/materialious/src/lib/components/Player.svelte @@ -8,7 +8,7 @@ import { ScreenOrientation, type ScreenOrientationResult } from '@capacitor/screen-orientation'; import { StatusBar, Style } from '@capacitor/status-bar'; import { NavigationBar } from '@hugotomazi/capacitor-navigation-bar'; - import { type Page } from '@sveltejs/kit'; + import { error, type Page } from '@sveltejs/kit'; import { HttpFetchPlugin } from '$lib/sabr/shakaHttpPlugin'; import ui from 'beercss'; import ISO6391 from 'iso-639-1'; @@ -385,7 +385,7 @@ watchProgressTimeout = setInterval(() => savePlayerPos(), 60000); setupSponsorSkip(); - let dashUrl: string = ''; + let dashUrl: string; // Due to CORs issues with redirects, hosted instances of Materialious // dirctly provide the companion instance @@ -393,6 +393,10 @@ if (import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE && Capacitor.getPlatform() === 'web') { dashUrl = `${import.meta.env.VITE_DEFAULT_COMPANION_INSTANCE}/api/manifest/dash/id/${data.video.videoId}`; } else { + if (!data.video.dashUrl) { + error(500, 'No dash manifest found'); + return; + } dashUrl = data.video.dashUrl; } @@ -403,6 +407,10 @@ await player.load(dashUrl, await getLastPlayPos()); } else { if (data.video.fallbackPatch === 'youtubejs') { + if (!data.video.dashUrl) { + error(500, 'No dash manifest found'); + return; + } await player.load(data.video.dashUrl); } else { await player.load(data.video.hlsUrl + '?local=true'); @@ -590,22 +598,22 @@ playerElement.playbackRate = playerElement.playbackRate + 0.25; return false; }); - + Mousetrap.bind(',', () => { - if (!playerElement) return - - const currentTrack = player.getVariantTracks().find(track => track.active) - const frameTime = 1/(currentTrack?.frameRate || 30) - playerElement.currentTime -= frameTime - }) + if (!playerElement) return; + + const currentTrack = player.getVariantTracks().find((track) => track.active); + const frameTime = 1 / (currentTrack?.frameRate || 30); + playerElement.currentTime -= frameTime; + }); Mousetrap.bind('.', () => { - if (!playerElement) return - - const currentTrack = player.getVariantTracks().find(track => track.active) - const frameTime = 1/(currentTrack?.frameRate || 30) - playerElement.currentTime += frameTime - }) + if (!playerElement) return; + + const currentTrack = player.getVariantTracks().find((track) => track.active); + const frameTime = 1 / (currentTrack?.frameRate || 30); + playerElement.currentTime += frameTime; + }); playerElement.addEventListener('pause', async () => { savePlayerPos(); diff --git a/materialious/src/lib/i18n/locales/en.json b/materialious/src/lib/i18n/locales/en.json index e081e293..d796d3ae 100644 --- a/materialious/src/lib/i18n/locales/en.json +++ b/materialious/src/lib/i18n/locales/en.json @@ -1,6 +1,7 @@ { "enabled": "Enabled", "disabled": "Disabled", + "premium": "Premium YouTube content can't be watched on Materialious.", "copyUrl": "Copy URL", "loadMore": "Load more", "views": "views", diff --git a/materialious/src/lib/patches/youtubejs.ts b/materialious/src/lib/patches/youtubejs.ts index c77086db..8c512a1a 100644 --- a/materialious/src/lib/patches/youtubejs.ts +++ b/materialious/src/lib/patches/youtubejs.ts @@ -7,7 +7,6 @@ import type { VideoBase, VideoPlay } from '$lib/api/model'; -import { numberWithCommas } from '$lib/numbers'; import { fromFormat } from '$lib/sabr/formatKeyUtils'; import { interfaceRegionStore, poTokenCacheStore } from '$lib/store'; import { Capacitor } from '@capacitor/core'; @@ -77,8 +76,6 @@ export async function patchYoutubeJs(videoId: string): Promise { throw new Error('Unable to pull video info from youtube.js'); } - console.log(video); - let dashUri: string | undefined; if (video.streaming_data) { @@ -103,8 +100,6 @@ export async function patchYoutubeJs(videoId: string): Promise { } } - if (!dashUri) throw Error('Unable to find suitable dash manifest'); - const descString = video.secondary_info.description?.toString() || ''; let authorThumbnails: Image[]; @@ -206,9 +201,9 @@ export async function patchYoutubeJs(videoId: string): Promise { premiereTimestamp: 0, hlsUrl: video.streaming_data?.hls_manifest_url || undefined, liveNow: video.basic_info.is_live || false, - premium: false, + premium: video?.playability_status?.status === 'UNPLAYABLE', storyboards: storyboard, - isUpcoming: false, + isUpcoming: video?.playability_status?.status !== 'OK', videoId: videoId, videoThumbnails: video.basic_info.thumbnail as Thumbnail[], author: video.basic_info.author || 'Unknown', diff --git a/materialious/src/lib/watch.ts b/materialious/src/lib/watch.ts index d0979319..38299bee 100644 --- a/materialious/src/lib/watch.ts +++ b/materialious/src/lib/watch.ts @@ -16,6 +16,7 @@ import { import { phaseDescription } from '$lib/timestamps'; import { error } from '@sveltejs/kit'; import { get } from 'svelte/store'; +import { _ } from './i18n'; export async function getWatchDetails(videoId: string, url: URL) { let video; @@ -25,6 +26,10 @@ export async function getWatchDetails(videoId: string, url: URL) { error(500, errorMessage); } + if (video.premium) { + error(400, get(_)('premium')); + } + let personalPlaylists; if (get(authStore)) { postHistory(video.videoId); diff --git a/materialious/src/routes/(app)/+error.svelte b/materialious/src/routes/(app)/+error.svelte index 9ebfd8a5..bee7c6b6 100644 --- a/materialious/src/routes/(app)/+error.svelte +++ b/materialious/src/routes/(app)/+error.svelte @@ -1,29 +1,5 @@ -
- -
- -

Oh no! You've encountered an error.

- -

Report it here

- - {#if $page.error} -
- {$page.error.message} -
- {/if} -
+ diff --git a/materialious/src/routes/(no-layout)/tv/[slug]/+error.svelte b/materialious/src/routes/(no-layout)/tv/[slug]/+error.svelte new file mode 100644 index 00000000..bee7c6b6 --- /dev/null +++ b/materialious/src/routes/(no-layout)/tv/[slug]/+error.svelte @@ -0,0 +1,5 @@ + + + diff --git a/materialious/src/routes/+error.svelte b/materialious/src/routes/+error.svelte new file mode 100644 index 00000000..bee7c6b6 --- /dev/null +++ b/materialious/src/routes/+error.svelte @@ -0,0 +1,5 @@ + + +