Added region support

This commit is contained in:
WardPearce
2024-05-18 19:50:42 +12:00
parent 7943ef942f
commit 75473c3368
9 changed files with 69 additions and 15 deletions
+12 -2
View File
@@ -1,12 +1,12 @@
{
"name": "materialious",
"version": "1.0.10",
"version": "1.0.11",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "materialious",
"version": "1.0.10",
"version": "1.0.11",
"dependencies": {
"@capacitor-community/electron": "^5.0.1",
"@capacitor/android": "^6.0.0",
@@ -17,6 +17,7 @@
"beercss": "^3.5.5",
"fuse.js": "^7.0.0",
"human-number": "^2.0.4",
"iso-3166": "^4.3.0",
"material-dynamic-colors": "^1.1.0",
"media-icons": "^0.10.0",
"mousetrap": "^1.6.5",
@@ -7870,6 +7871,15 @@
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
},
"node_modules/iso-3166": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/iso-3166/-/iso-3166-4.3.0.tgz",
"integrity": "sha512-H4kM/sVbxTjSl9xnQCYOrNWdpN0R8Uz26j1BuXI9E6U+kw5wmd3HyPgr/v4+NCuvV/NcvwTfZxd5XZ4lPKvBNA==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
}
},
"node_modules/jake": {
"version": "10.9.1",
"resolved": "https://registry.npmjs.org/jake/-/jake-10.9.1.tgz",
+2 -1
View File
@@ -46,6 +46,7 @@
"beercss": "^3.5.5",
"fuse.js": "^7.0.0",
"human-number": "^2.0.4",
"iso-3166": "^4.3.0",
"material-dynamic-colors": "^1.1.0",
"media-icons": "^0.10.0",
"mousetrap": "^1.6.5",
@@ -56,4 +57,4 @@
"svelte-persisted-store": "^0.9.2",
"vidstack": "^1.11.21"
}
}
}
+21 -10
View File
@@ -4,6 +4,7 @@ import {
deArrowInstanceStore,
deArrowThumbnailInstanceStore,
instanceStore,
interfaceRegionStore,
returnYTDislikesInstanceStore,
synciousInstanceStore
} from '../store';
@@ -25,8 +26,18 @@ import type {
VideoPlay
} from './model';
export function buildPath(path: string): string {
return `${get(instanceStore)}/api/v1/${path}`;
export function buildPath(path: string): URL {
return new URL(`${get(instanceStore)}/api/v1/${path}`);
}
export function setRegion(url: URL): URL {
const region = get(interfaceRegionStore);
if (region) {
url.searchParams.set('region', region);
}
return url;
}
export async function fetchErrorHandle(response: Response): Promise<Response> {
@@ -47,7 +58,7 @@ export function buildAuthHeaders(): { headers: { Authorization: string; }; } {
}
export async function getTrending(): Promise<Video[]> {
const resp = await fetchErrorHandle(await fetch(buildPath('trending')));
const resp = await fetchErrorHandle(await fetch(setRegion(buildPath('trending'))));
return await resp.json();
}
@@ -57,7 +68,7 @@ export async function getPopular(): Promise<Video[]> {
}
export async function getVideo(videoId: string, local: boolean = false): Promise<VideoPlay> {
const resp = await fetchErrorHandle(await fetch(buildPath(`videos/${videoId}?local=${local}`)));
const resp = await fetchErrorHandle(await fetch(setRegion(buildPath(`videos/${videoId}?local=${local}`))));
return await resp.json();
}
@@ -84,7 +95,7 @@ export async function getComments(
parameters.source = 'youtube';
}
const path = new URL(buildPath(`comments/${videoId}`));
const path = buildPath(`comments/${videoId}`);
path.search = new URLSearchParams(parameters).toString();
const resp = await fetchErrorHandle(await fetch(path));
return await resp.json();
@@ -104,7 +115,7 @@ export async function getChannelContent(
): Promise<ChannelContentVideos | ChannelContentPlaylists> {
if (typeof parameters.type === 'undefined') parameters.type = 'videos';
const url = new URL(buildPath(`channels/${channelId}/${parameters.type}`));
const url = buildPath(`channels/${channelId}/${parameters.type}`);
if (typeof parameters.continuation !== 'undefined')
url.searchParams.set('continuation', parameters.continuation);
@@ -114,7 +125,7 @@ export async function getChannelContent(
}
export async function getSearchSuggestions(search: string): Promise<SearchSuggestion> {
const path = new URL(buildPath('search/suggestions'));
const path = buildPath('search/suggestions');
path.search = new URLSearchParams({ q: search }).toString();
const resp = await fetchErrorHandle(await fetch(path));
return await resp.json();
@@ -140,14 +151,14 @@ export async function getSearch(
options.page = '1';
}
const path = new URL(buildPath('search'));
const path = buildPath('search');
path.search = new URLSearchParams({ ...options, q: search }).toString();
const resp = await fetchErrorHandle(await fetch(path));
const resp = await fetchErrorHandle(await fetch(setRegion(path)));
return await resp.json();
}
export async function getFeed(maxResults: number, page: number): Promise<Feed> {
const path = new URL(buildPath('auth/feed'));
const path = buildPath('auth/feed');
path.search = new URLSearchParams({
max_results: maxResults.toString(),
page: page.toString()
+18 -1
View File
@@ -1,9 +1,10 @@
<script lang="ts">
import { bookmarkletSaveToUrl } from '$lib/externalSettings';
import { Capacitor } from '@capacitor/core';
import { iso31661 } from 'iso-3166';
import { _ } from 'svelte-i18n';
import { get } from 'svelte/store';
import { ensureNoTrailingSlash } from './misc';
import { ensureNoTrailingSlash, truncate } from './misc';
import {
authStore,
darkModeStore,
@@ -12,6 +13,7 @@
deArrowThumbnailInstanceStore,
instanceStore,
interfacePreviewVideoOnHoverStore,
interfaceRegionStore,
interfaceSearchSuggestionsStore,
playerAlwaysLoopStore,
playerAndroidBackgroundPlayStore,
@@ -43,6 +45,8 @@
let deArrowUrl = get(deArrowInstanceStore);
let deArrowThumbnailUrl = get(deArrowThumbnailInstanceStore);
let region = get(interfaceRegionStore);
const sponsorCategories = [
{ name: $_('layout.sponsors.sponsor'), category: 'sponsor' },
{ name: $_('layout.sponsors.unpaidSelfPromotion'), category: 'selfpromo' },
@@ -131,6 +135,7 @@
<div class="settings">
<h6>Interface</h6>
<div class="field no-margin">
<nav class="no-padding">
<div class="max">
@@ -163,6 +168,18 @@
</label>
</nav>
</div>
<div class="field label no-margin suffix border">
<select name="region" bind:value={region} on:change={() => interfaceRegionStore.set(region)}>
{#each iso31661 as region}
<option selected={$interfaceRegionStore === region.alpha2} value={region.alpha2}
>{region.alpha2} - {truncate(region.name, 13)}</option
>
{/each}
</select>
<label for="region">{$_('region')}</label>
<i>arrow_drop_down</i>
</div>
</div>
<div class="settings">
+1 -1
View File
@@ -11,7 +11,7 @@
class="row"
href="#copy"
on:click={async () =>
await navigator.clipboard.writeText(`${location.origin}watch/${video.videoId}`)}
await navigator.clipboard.writeText(`${location.origin}/watch/${video.videoId}`)}
>
<div class="min">{$_('player.share.materialiousLink')}</div></a
>
+6
View File
@@ -5,6 +5,7 @@ import {
deArrowInstanceStore,
deArrowThumbnailInstanceStore,
interfacePreviewVideoOnHoverStore,
interfaceRegionStore,
interfaceSearchSuggestionsStore,
playerAlwaysLoopStore,
playerAutoPlayStore,
@@ -141,6 +142,11 @@ const persistedStores = [
name: 'synciousInstance',
store: synciousInstanceStore,
type: 'string'
},
{
name: 'region',
store: interfaceRegionStore,
type: 'string'
}
];
@@ -12,6 +12,7 @@
"deleteAllHistory": "Delete all history",
"skipping": "Skipping",
"replies": "replies",
"region": "Region",
"hideReplies": "Hide replies",
"hideVideo": "Hide video",
"syncParty": {
+4
View File
@@ -6,6 +6,10 @@ import { get } from 'svelte/store';
import type { Image } from './Api/model';
import { instanceStore } from './store';
export type titleCase = 'uppercase' | 'lowercase' | 'sentence case' | 'title case' | null;
export function truncate(value: string, maxLength: number = 50): string {
return value.length > maxLength ? `${value.substring(0, maxLength)}...` : value;
}
+4
View File
@@ -3,6 +3,7 @@ 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';
export const instanceStore: Writable<string> = persisted(
"invidiousInstance",
@@ -42,8 +43,10 @@ export const synciousInstanceStore: Writable<string | null | undefined> = persis
import.meta.env.VITE_DEFAULT_SYNCIOUS_INSTANCE || 'https://syncious.materialio.us'
);
export const interfaceRegionStore: Writable<string> = persisted('interfaceRegion', 'US');
export const interfaceSearchSuggestionsStore = persisted('searchSuggestions', true);
export const interfacePreviewVideoOnHoverStore = persisted('previewVideoOnHover', true);
export const interfaceForceCase: Writable<titleCase> = persisted('forceCase', null);
export const sponsorBlockStore = persisted('sponsorBlock', true);
export const sponsorBlockUrlStore: Writable<string | null | undefined> = persisted(
@@ -73,3 +76,4 @@ export const playlistSettingsStore: Writable<Record<string, { shuffle: boolean;
export const miniPlayerSrcStore: Writable<{ video: VideoPlay; time: number; } | null> =
writable(null);