Better handling for premium content

This commit is contained in:
WardPearce
2025-07-26 19:54:45 +12:00
parent 8e06a868e6
commit 94b49eb1e9
9 changed files with 65 additions and 49 deletions
+1 -1
View File
@@ -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[];
@@ -0,0 +1,21 @@
<script lang="ts">
import { page } from '$app/state';
</script>
<div class="space"></div>
<div
style="display: flex;align-items: center;flex-direction: column;text-align: center;padding: 90px;"
>
<svg xmlns="http://www.w3.org/2000/svg" height="200" viewBox="0 -960 960 960" width="200"
><path
d="M480-420q-68 0-123.5 38.5T276-280h408q-25-63-80.5-101.5T480-420Zm-168-60 44-42 42 42 42-42-42-42 42-44-42-42-42 42-44-42-42 42 42 44-42 42 42 42Zm250 0 42-42 44 42 42-42-42-42 42-44-42-42-44 42-42-42-42 42 42 44-42 42 42 42ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Z"
/></svg
>
{#if page.error}
<article>
<code style="white-space: pre-line;word-wrap: break-word;">{page.error.message}</code>
</article>
{/if}
</div>
+23 -15
View File
@@ -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();
@@ -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",
+2 -7
View File
@@ -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<VideoPlay> {
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<VideoPlay> {
}
}
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<VideoPlay> {
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',
+5
View File
@@ -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);
+2 -26
View File
@@ -1,29 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import ErrorMsg from '$lib/components/ErrorMsg.svelte';
</script>
<div class="space"></div>
<div
style="display: flex;align-items: center;flex-direction: column;text-align: center;padding: 90px;"
>
<svg xmlns="http://www.w3.org/2000/svg" height="200" viewBox="0 -960 960 960" width="200"
><path
d="M480-420q-68 0-123.5 38.5T276-280h408q-25-63-80.5-101.5T480-420Zm-168-60 44-42 42 42 42-42-42-42 42-44-42-42-42 42-44-42-42 42 42 44-42 42 42 42Zm250 0 42-42 44 42 42-42-42-42 42-44-42-42-44 42-42-42-42 42 42 44-42 42 42 42ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Z"
/></svg
>
<h2>Oh no! You've encountered an error.</h2>
<a
href="https://github.com/WardPearce/Materialious/issues/new"
class="link"
target="_blank"
rel="noopener noreferrer"><h3>Report it here</h3></a
>
{#if $page.error}
<article>
<code style="white-space: pre-line;word-wrap: break-word;">{$page.error.message}</code>
</article>
{/if}
</div>
<ErrorMsg />
@@ -0,0 +1,5 @@
<script lang="ts">
import ErrorMsg from '$lib/components/ErrorMsg.svelte';
</script>
<ErrorMsg />
+5
View File
@@ -0,0 +1,5 @@
<script lang="ts">
import ErrorMsg from '$lib/components/ErrorMsg.svelte';
</script>
<ErrorMsg />