Preferences / Web App (#79)
* Add basic router * Add a preferences file * small changes * Basic settings navigation menu * Lint fix * Add bunch of controls * Lint fix * StringControl * Lint fix * Add description to keyboard * Settings saving and loading * Lint fix * Settings migration stuff * GET web api * Lint fix * PUT and DELETE (I really fucking hate BrightScript) * plug in sponsorblock settings * autoplay, quality, and video proxying * Remove unused stuff * Lint fix * Invidious instance stuff * cache public instances on start * Start loading home screen after fetching instances * Move web app out of settings to its own screen * picture in picture when in settings * Web app (#80) * Update instance stuff * Update dependencies * Add basic layout * Info and settings page, missing styling * Navbar fixes * Settings page formatting * Theme stuff * Feedback link * Fix username badge * Fix svelte warnings * A wip search page * Add a couple of api functions * Wip home screen * user country code * Expose token and proxy auth calls * Use auth requests server side * Some cleanup * Add svelte vs code extension * remove old web app * More layout stuff * Tweak for string control * Filter out old search suggestions * Search history stuff * img size for lazy loading * Basic modal to play video * Lint fix * Dependencies bump * Add video duration and LIVE indicator to cell * Delete legacy stuff * Add dev menu * Lint fix * Video cell layout * Cell stuff * prefs visibility * Modal layout * Drag and drop functionality * Clear search history * Move web calls to main app * changelog * changelog * Mostly comments * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
9a631aab51
commit
8f8c7d38a8
91 files changed
+3979
-1787
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
import HomeIcon from "../assets/home-icon.svg.svelte";
|
||||
import InfoIcon from "../assets/info-icon.svg.svelte";
|
||||
import SearchIcon from "../assets/search-icon.svg.svelte";
|
||||
import SettingsIcon from "../assets/settings-icon.svg.svelte";
|
||||
import { appStateStore } from "./Stores";
|
||||
import type { AppState } from "./Types";
|
||||
|
||||
function setScreen(screen: AppState["screen"]) {
|
||||
appStateStore.update((state) => {
|
||||
state.screen = screen;
|
||||
return state;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="btm-nav">
|
||||
<button
|
||||
on:click={() => setScreen("search")}
|
||||
class={$appStateStore.screen === "search" ? "active" : ""}
|
||||
>
|
||||
<div class="h-6">
|
||||
<SearchIcon />
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
on:click={() => setScreen("home")}
|
||||
class={$appStateStore.screen === "home" ? "active" : ""}
|
||||
>
|
||||
<div class="h-6">
|
||||
<HomeIcon />
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
on:click={() => setScreen("settings")}
|
||||
class={$appStateStore.screen === "settings" ? "active" : ""}
|
||||
>
|
||||
<div class="h-6">
|
||||
<SettingsIcon />
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
on:click={() => setScreen("info")}
|
||||
class={$appStateStore.screen === "info" ? "active" : ""}
|
||||
>
|
||||
<div class="h-6">
|
||||
<InfoIcon />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
@@ -1,11 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
|
||||
const clearSearchHistory = async () => {
|
||||
await PlayletApi.clearSearchHistory();
|
||||
};
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<button class="btn" on:click={clearSearchHistory}>Clear search history</button>
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script>
|
||||
import { onMount } from "svelte";
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
|
||||
let selectedRelease = ''
|
||||
let releases = [];
|
||||
onMount(async () => {
|
||||
releases = await fetchReleaseTags();
|
||||
});
|
||||
|
||||
async function fetchReleaseTags() {
|
||||
const response = await fetch(
|
||||
"https://api.github.com/repos/iBicha/playlet/releases"
|
||||
);
|
||||
const releases = await response.json();
|
||||
return releases.map((release) => {
|
||||
return {
|
||||
name: release.tag_name,
|
||||
enabled:
|
||||
release.assets.filter((asset) => asset.name === "playlet-lib.zip")
|
||||
.length > 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
await PlayletApi.setPlayletLibVersion(selectedRelease);
|
||||
alert("Playlet Library version set. Restart playlet to apply changes.");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="m-5">
|
||||
<div class="text-2xl">Developer settings</div>
|
||||
<div class="text-xs text-gray-500">
|
||||
Options for Playlet developers. Do not change unless you "know what you're
|
||||
doing"™
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="m-5">
|
||||
<div class="text-lg">Playlet Library version</div>
|
||||
<div class="text-xs text-gray-500">
|
||||
The version of Playlet Lib to use. These correspond to tagged releases on
|
||||
Github. Releases that do not have a playlet-lib.zip file are disabled.
|
||||
</div>
|
||||
|
||||
<div class="join w-full m-1">
|
||||
<select bind:value={selectedRelease} class="select select-bordered join-item w-full mr-1">
|
||||
<option selected value="">latest (default)</option>
|
||||
{#each releases as release}
|
||||
<option disabled={!release.enabled} value={release.name}
|
||||
>{release.name}</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
<button class="join-item btn" on:click={apply}>Apply</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,33 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
import { playletStateStore } from "./Stores";
|
||||
|
||||
let selectedInstance;
|
||||
let inputInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
selectedInstance = value?.invidious?.selected_instance ?? "N/A";
|
||||
inputInstance = selectedInstance;
|
||||
});
|
||||
|
||||
const updateInstance = async () => {
|
||||
await PlayletApi.updateInstances([inputInstance]);
|
||||
// TODO: reload state
|
||||
window.location.reload();
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="form-control">
|
||||
<label class="input-group">
|
||||
<span>Invidious Instance</span>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="http://my-instance.com"
|
||||
class="input input-bordered"
|
||||
bind:value={inputInstance}
|
||||
/>
|
||||
{#if inputInstance !== selectedInstance}
|
||||
<button class="btn" on:click={updateInstance}>Update</button>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
@@ -0,0 +1,128 @@
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
|
||||
export class InvidiousApi {
|
||||
public instance: string;
|
||||
public endpoints: any;
|
||||
public isLoggedIn: boolean = false;
|
||||
public userCountryCode: string = 'US';
|
||||
|
||||
responseHandlers: any;
|
||||
|
||||
constructor() {
|
||||
// Note: AuthFeedHandler and AuthPlaylistsHandler are not needed, since it is handled server side
|
||||
this.responseHandlers = {
|
||||
"DefaultHandler": (requestData, response) => this.DefaultHandler(requestData, response),
|
||||
"PlaylistHandler": (requestData, response) => this.PlaylistHandler(requestData, response),
|
||||
}
|
||||
}
|
||||
|
||||
public async searchSuggestions(query: string) {
|
||||
const response = await fetch(`${this.instance}/api/v1/search/suggestions?q=${encodeURIComponent(query)}®ion=${this.userCountryCode}`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async search(query: string) {
|
||||
const response = await fetch(`${this.instance}/api/v1/search?q=${encodeURIComponent(query)}®ion=${this.userCountryCode}`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async getVideoMetadata(videoId: string) {
|
||||
const response = await fetch(`${this.instance}/api/v1/videos/${videoId}`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
public async makeRequest(requestData: any) {
|
||||
if (!requestData || !this.instance || !this.endpoints) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let endpoint = this.endpoints[requestData.endpoint];
|
||||
if (!endpoint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let url = this.instance + endpoint.url
|
||||
let queryParams = {}
|
||||
let headers = {}
|
||||
|
||||
if (endpoint.authenticated) {
|
||||
// Authenticated requests on the web app would be blocked by CORS, so we use the Playlet API as a proxy
|
||||
if (!this.isLoggedIn) {
|
||||
return null;
|
||||
}
|
||||
return await PlayletApi.invidiousAuthenticatedRequest(requestData);
|
||||
}
|
||||
|
||||
if (endpoint.queryParams !== undefined) {
|
||||
for (let queryParamKey in endpoint.queryParams) {
|
||||
let queryParam = endpoint.queryParams[queryParamKey];
|
||||
if (queryParam.default !== undefined) {
|
||||
if (queryParam.type === "string") {
|
||||
queryParams[queryParamKey] = queryParam.default;
|
||||
} else if (queryParam.type === "#ISO3166") {
|
||||
if (queryParam.default === "GetUserCountryCode") {
|
||||
queryParams[queryParamKey] = this.userCountryCode;
|
||||
} else {
|
||||
queryParams[queryParamKey] = queryParam.default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (requestData.queryParams !== undefined) {
|
||||
queryParams = { ...queryParams, ...requestData.queryParams };
|
||||
}
|
||||
|
||||
if (requestData.pathParams !== undefined) {
|
||||
for (let param in requestData.pathParams) {
|
||||
url = url.replace(`:${param}`, requestData.pathParams[param]);
|
||||
}
|
||||
}
|
||||
|
||||
url = this.makeUrl(url, queryParams);
|
||||
const response = await fetch(url, { headers: headers });
|
||||
|
||||
let responseHandler = endpoint.responseHandler !== undefined ? this.responseHandlers[endpoint.responseHandler] : this.responseHandlers["DefaultHandler"];
|
||||
if (!responseHandler) {
|
||||
return null;
|
||||
}
|
||||
return await responseHandler(requestData, response);
|
||||
}
|
||||
|
||||
private async DefaultHandler(requestData, response) {
|
||||
const json = await response.json();
|
||||
return [{ title: requestData.title, videos: json }]
|
||||
}
|
||||
|
||||
private async PlaylistHandler(requestData, response) {
|
||||
const playlist = await response.json();
|
||||
return [this.ProcessPlaylist(requestData, playlist)]
|
||||
}
|
||||
|
||||
private ProcessPlaylist(requestData, playlist) {
|
||||
const title = this.ProcessTemplate(requestData.title, playlist)
|
||||
return { title: title, videos: playlist.videos }
|
||||
}
|
||||
|
||||
private ProcessTemplate(template: string, data) {
|
||||
let result = template;
|
||||
for (let key in data) {
|
||||
result = result.replace(`%${key}%`, `${data[key]}`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private makeUrl(url: string, params: any) {
|
||||
const encodedUrl = new URL(url);
|
||||
const existingParams = new URLSearchParams(encodedUrl.search);
|
||||
|
||||
let mergedParams = new URLSearchParams({
|
||||
...Object.fromEntries(existingParams),
|
||||
...params
|
||||
});
|
||||
|
||||
encodedUrl.search = mergedParams.toString();
|
||||
return encodedUrl.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { getHost } from "./Host";
|
||||
|
||||
const goToLegacyUI = async () => {
|
||||
window.location.href = `http://${getHost()}`
|
||||
};
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<button class="btn" on:click={goToLegacyUI}>Legacy UI</button>
|
||||
</div>
|
||||
@@ -0,0 +1,152 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
import { playletStateStore } from "./Stores";
|
||||
import { InvidiousApi } from "./InvidiousApi";
|
||||
|
||||
let modal;
|
||||
let isDragging;
|
||||
let isLoading;
|
||||
let dragEndTimeout;
|
||||
|
||||
let videoMetadata;
|
||||
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
let invidiousApi = new InvidiousApi();
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousApi.instance = invidiousInstance =
|
||||
value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
onMount(async () => {
|
||||
document.body.addEventListener("drop", onDrop);
|
||||
document.body.addEventListener("dragover", onDragOver);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
document.body.removeEventListener("drop", onDrop);
|
||||
document.body.removeEventListener("dragover", onDragOver);
|
||||
});
|
||||
|
||||
async function onDrop(event) {
|
||||
event.preventDefault();
|
||||
modal.close();
|
||||
|
||||
isDragging = false;
|
||||
for (var i in event.dataTransfer.items) {
|
||||
let item = event.dataTransfer.items[i];
|
||||
if (item.kind === "string" && item.getAsString) {
|
||||
let dataString = await new Promise((resolve) =>
|
||||
item.getAsString(resolve)
|
||||
);
|
||||
if (IsValidHttpUrl(dataString)) {
|
||||
const videoId = GetVideoId(dataString);
|
||||
if (videoId) {
|
||||
searchForVideoById(videoId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function searchForVideoById(videoId) {
|
||||
try {
|
||||
isLoading = true;
|
||||
videoMetadata = await invidiousApi.getVideoMetadata(videoId);
|
||||
modal.showModal();
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onDragOver(event) {
|
||||
modal.close();
|
||||
clearTimeout(dragEndTimeout);
|
||||
dragEndTimeout = setTimeout(() => {
|
||||
isDragging = false;
|
||||
}, 200);
|
||||
isDragging = true;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function IsValidHttpUrl(string) {
|
||||
let url;
|
||||
try {
|
||||
url = new URL(string);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
return url.protocol === "http:" || url.protocol === "https:";
|
||||
}
|
||||
|
||||
function GetVideoId(url) {
|
||||
// Share/Short url
|
||||
// TODO: use regex, and support timestamped videos
|
||||
const YoutubeUrls = [
|
||||
"https://youtu.be/",
|
||||
"http://youtu.be/",
|
||||
"https://www.youtu.be/",
|
||||
"http://www.youtu.be/",
|
||||
"https://youtube.com/shorts/",
|
||||
"http://youtube.com/shorts/",
|
||||
"https://www.youtube.com/shorts/",
|
||||
"http://www.youtube.com/shorts/",
|
||||
];
|
||||
for (var i in YoutubeUrls) {
|
||||
let youtubeUrl = YoutubeUrls[i];
|
||||
if (url.startsWith(youtubeUrl)) {
|
||||
url = url.replace(youtubeUrl, "");
|
||||
if (url.includes("?")) {
|
||||
url = url.substring(0, url.indexOf("?"));
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
// regular url
|
||||
url = new URL(url);
|
||||
const urlSearchParams = new URLSearchParams(url.search);
|
||||
return urlSearchParams.get("v");
|
||||
}
|
||||
|
||||
async function playVideoOnTv() {
|
||||
await PlayletApi.playVideo(videoMetadata?.videoId);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
window.open(`${invidiousInstance}/watch?v=${videoMetadata?.videoId}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="{isDragging || isLoading
|
||||
? ''
|
||||
: 'hidden'} absolute w-full h-full bg-base-100/80 z-50 flex justify-center items-center"
|
||||
>
|
||||
{#if isDragging}
|
||||
<div class="text-2xl font-bold">Drop a Youtube link here</div>
|
||||
{:else if isLoading}
|
||||
<span class="loading loading-spinner loading-md" />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<dialog bind:this={modal} id="modal_video_drag_drop" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<h3 class="text-lg m-5">{videoMetadata?.title}</h3>
|
||||
<div class="flex flex-col">
|
||||
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button>
|
||||
<button class="btn m-2" on:click={openInvidiousInNewTab}
|
||||
>Open in Invidious</button
|
||||
>
|
||||
<button class="btn m-2">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -1,50 +1,83 @@
|
||||
<script lang="ts">
|
||||
import playletLogo from "../assets/logo-dark.svg";
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
import { playletStateStore } from "./Stores";
|
||||
import playletLogoDark from "../assets/logo-dark.svg";
|
||||
import playletLogoLight from "../assets/logo-light.svg";
|
||||
import userIcon from "../assets/user.png";
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
import { appThemeStore, playletStateStore } from "./Stores";
|
||||
import ThemeSelect from "./ThemeToggle.svelte";
|
||||
|
||||
let version;
|
||||
let loggedIn = false;
|
||||
let auth_url;
|
||||
let selectedInstance;
|
||||
let loggedInInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
version = value?.app?.version ?? "";
|
||||
loggedIn = value?.invidious?.logged_in;
|
||||
auth_url = value?.invidious?.auth_url;
|
||||
selectedInstance = value?.invidious?.selected_instance;
|
||||
loggedInInstance = value?.invidious?.logged_in_instance;
|
||||
});
|
||||
let version;
|
||||
let loggedIn = false;
|
||||
let auth_url;
|
||||
let currentInstance;
|
||||
let loggedInInstance;
|
||||
let username;
|
||||
|
||||
const login = () => {
|
||||
if (!auth_url) {
|
||||
alert("Error with login, please refresh the page.");
|
||||
return;
|
||||
}
|
||||
window.location = auth_url;
|
||||
};
|
||||
const logout = async () => {
|
||||
await PlayletApi.logout();
|
||||
// TODO: reload state
|
||||
window.location.reload();
|
||||
};
|
||||
playletStateStore.subscribe((value) => {
|
||||
version = value?.app?.lib_version ?? "";
|
||||
loggedIn = value?.invidious?.logged_in;
|
||||
auth_url = value?.invidious?.auth_url;
|
||||
currentInstance = value?.invidious?.current_instance;
|
||||
loggedInInstance = value?.invidious?.logged_in_instance;
|
||||
username = value?.invidious?.logged_in_username;
|
||||
});
|
||||
|
||||
const login = () => {
|
||||
if (!auth_url) {
|
||||
alert("Error with login, please refresh the page.");
|
||||
return;
|
||||
}
|
||||
window.location = auth_url;
|
||||
};
|
||||
const logout = async () => {
|
||||
await PlayletApi.logout();
|
||||
// TODO: reload state
|
||||
window.location.reload();
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="navbar bg-base-100">
|
||||
<div class="flex-1">
|
||||
<img src={playletLogo} class="h-12" alt="Playlet Logo" />
|
||||
<h4 class="label brightness-75">{version}</h4>
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<div class="navbar bg-base-100 sticky top-0 z-40">
|
||||
<div class="flex-1">
|
||||
<img src={$appThemeStore === 'dark' ? playletLogoDark : playletLogoLight} class="h-8" alt="Playlet Logo" />
|
||||
<h4 class="label brightness-75">{version}</h4>
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<ThemeSelect />
|
||||
{#if loggedIn && username}
|
||||
<div class="badge badge-outline">
|
||||
<span>{username}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="dropdown dropdown-end">
|
||||
<div tabindex="-1" class="btn btn-ghost btn-circle avatar">
|
||||
<div class="w-8 rounded-full">
|
||||
<img src={userIcon} alt="User" />
|
||||
</div>
|
||||
</div>
|
||||
<ul
|
||||
tabindex="-1"
|
||||
class="menu menu-sm dropdown-content mt-3 p-2 shadow bg-base-100 rounded-box"
|
||||
>
|
||||
{#if loggedIn}
|
||||
<div class="tooltip tooltip-left" data-tip={loggedInInstance}>
|
||||
<button class="btn" on:click={logout}>Logout</button>
|
||||
<li>
|
||||
<div
|
||||
class="tooltip tooltip-left"
|
||||
data-tip={`Logout from ${loggedInInstance}`}
|
||||
>
|
||||
<button on:click={logout}>Logout</button>
|
||||
</div>
|
||||
</li>
|
||||
{:else}
|
||||
<div class="tooltip tooltip-left" data-tip={selectedInstance}>
|
||||
<button class="btn" on:click={login}>Login</button>
|
||||
<li>
|
||||
<div
|
||||
class="tooltip tooltip-left"
|
||||
data-tip={`Login using ${currentInstance}`}
|
||||
>
|
||||
<button on:click={login}>Login</button>
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,69 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
|
||||
let videoId;
|
||||
|
||||
function IsValidHttpUrl(string) {
|
||||
let url;
|
||||
try {
|
||||
url = new URL(string);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
return url.protocol === "http:" || url.protocol === "https:";
|
||||
}
|
||||
|
||||
function GetVideoId(url) {
|
||||
// Share/Short url
|
||||
const YoutubeUrls = [
|
||||
"https://youtu.be/",
|
||||
"http://youtu.be/",
|
||||
"https://www.youtu.be/",
|
||||
"http://www.youtu.be/",
|
||||
"https://youtube.com/shorts/",
|
||||
"http://youtube.com/shorts/",
|
||||
"https://www.youtube.com/shorts/",
|
||||
"http://www.youtube.com/shorts/",
|
||||
];
|
||||
for (var i in YoutubeUrls) {
|
||||
let youtubeUrl = YoutubeUrls[i];
|
||||
if (url.startsWith(youtubeUrl)) {
|
||||
url = url.replace(youtubeUrl, "");
|
||||
if (url.includes("?")) {
|
||||
url = url.substring(0, url.indexOf("?"));
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
// regular url
|
||||
url = new URL(url);
|
||||
const urlSearchParams = new URLSearchParams(url.search);
|
||||
return urlSearchParams.get("v");
|
||||
}
|
||||
|
||||
const playVideo = async () => {
|
||||
let v = videoId;
|
||||
if (IsValidHttpUrl(v)) {
|
||||
v = GetVideoId(v);
|
||||
}
|
||||
if (!v || v.length < 8) {
|
||||
alert("Please set video id");
|
||||
return;
|
||||
}
|
||||
|
||||
await PlayletApi.playVideo(v);
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="form-control">
|
||||
<div class="input-group">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Video ID"
|
||||
class="input input-bordered"
|
||||
bind:value={videoId}
|
||||
/>
|
||||
<button class="btn" on:click={playVideo}> Play </button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -8,20 +8,77 @@ export class PlayletApi {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getPreferencesFile() {
|
||||
const response = await fetch(`${PlayletApi.host()}/config/preferences.json`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getHomeLayoutFile() {
|
||||
const response = await fetch(`${PlayletApi.host()}/config/default_home_layout.json`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getInvidiousVideoApiFile() {
|
||||
const response = await fetch(`${PlayletApi.host()}/config/invidious_video_api.json`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async invidiousAuthenticatedRequest(requestData) {
|
||||
const url = PlayletApi.host() + "/invidious/authenticated-request?request-data=" + encodeURIComponent(JSON.stringify(requestData));
|
||||
const response = await fetch(url);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getUserPreferences() {
|
||||
const response = await fetch(`${PlayletApi.host()}/api/preferences`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async saveUserPreference(key, value) {
|
||||
const response = await this.putJson(`${PlayletApi.host()}/api/preferences`, { [key]: value });
|
||||
return await response;
|
||||
}
|
||||
|
||||
static async logout() {
|
||||
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "logout" });
|
||||
}
|
||||
|
||||
static async playVideo(videoId) {
|
||||
if (!videoId) {
|
||||
return;
|
||||
}
|
||||
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "play", videoId: videoId });
|
||||
}
|
||||
|
||||
static async clearSearchHistory() {
|
||||
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "clear-search-history" });
|
||||
static async getSearchHistory() {
|
||||
const response = await fetch(`${PlayletApi.host()}/api/search-history`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async updateInstances(instances) {
|
||||
return await PlayletApi.postJson(`${PlayletApi.host()}/invidious/instances`, instances);
|
||||
static async putSearchHistory(query: string) {
|
||||
const response = await PlayletApi.putJson(`${PlayletApi.host()}/api/search-history`, { query });
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async clearSearchHistory() {
|
||||
return await fetch(`${PlayletApi.host()}/api/search-history`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
static async updateInstance(instance) {
|
||||
return await PlayletApi.putJson(`${PlayletApi.host()}/api/preferences`, { "invidious.instance": instance });
|
||||
}
|
||||
|
||||
static async setPlayletLibVersion(tag) {
|
||||
let content = null
|
||||
|
||||
if (tag !== "") {
|
||||
content = JSON.stringify([{
|
||||
link: `https://github.com/iBicha/playlet/releases/download/${tag}/playlet-lib.zip`,
|
||||
type: 'custom'
|
||||
}]);
|
||||
}
|
||||
|
||||
await this.postJson(`${PlayletApi.host()}/api/command`, { command: "set-playlet-lib-urls", content: content });
|
||||
}
|
||||
|
||||
private static postJson(url, payload) {
|
||||
@@ -33,4 +90,14 @@ export class PlayletApi {
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
|
||||
private static putJson(url, payload) {
|
||||
return fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
method: "PUT",
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<script lang="ts">
|
||||
import ScreenHomeRow from "./ScreenHomeRow.svelte";
|
||||
import { homeLayoutFileStore } from "./Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
</script>
|
||||
|
||||
<div class={visibility ? "" : "hidden"}>
|
||||
{#each $homeLayoutFileStore as homeLayoutItem}
|
||||
<ScreenHomeRow requestData={homeLayoutItem} />
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script lang="ts">
|
||||
import { InvidiousApi } from "./InvidiousApi";
|
||||
import {
|
||||
invidiousVideoApiStore,
|
||||
playletStateStore,
|
||||
} from "./Stores";
|
||||
import VideoCell from "./VideoCell.svelte";
|
||||
|
||||
export let requestData: any = undefined;
|
||||
export let videoRowData = undefined;
|
||||
|
||||
let invidiousApi = new InvidiousApi();
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
invidiousApi.instance = value?.invidious?.current_instance;
|
||||
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
||||
invidiousApi.isLoggedIn = value.invidious?.logged_in ?? false;
|
||||
updateRow();
|
||||
});
|
||||
|
||||
invidiousVideoApiStore.subscribe((value) => {
|
||||
invidiousApi.endpoints = value;
|
||||
updateRow();
|
||||
});
|
||||
|
||||
async function updateRow() {
|
||||
const result = await invidiousApi.makeRequest(requestData);
|
||||
if (result) {
|
||||
videoRowData = result;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if videoRowData}
|
||||
{#if Array.isArray(videoRowData)}
|
||||
{#each videoRowData as child}
|
||||
<svelte:self videoRowData={child} />
|
||||
{/each}
|
||||
{:else if videoRowData.title && videoRowData.videos}
|
||||
<div class="text-lg font-semibold m-4">{videoRowData.title}</div>
|
||||
<div
|
||||
class="carousel carousel-center rounded-box w-full space-x-4"
|
||||
>
|
||||
{#each videoRowData.videos as video}
|
||||
<div class="carousel-item">
|
||||
<VideoCell {...video} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -0,0 +1,81 @@
|
||||
<script lang="ts">
|
||||
import { playletStateStore } from "./Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
const displayNames = {
|
||||
version: "Playlet Version",
|
||||
lib_version: "Playlet Library Version",
|
||||
lib_version_latest: "Playlet Library Latest Version",
|
||||
lib_url: "Playlet Library URL",
|
||||
lib_url_type: "Playlet Library URL Type",
|
||||
git_commit_hash: "Playlet Git Commit Hash",
|
||||
lib_git_commit_hash: "Playlet Library Git Commit Hash",
|
||||
id: "App ID",
|
||||
};
|
||||
|
||||
let appInfo = {};
|
||||
let deviceInfo = {};
|
||||
let invidiousInfo = {};
|
||||
let preferencesInfo = {};
|
||||
let githubUrlIssue = "https://github.com/iBicha/playlet/issues/new";
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
appInfo = value.app || {};
|
||||
deviceInfo = value.device || {};
|
||||
invidiousInfo = value.invidious || {};
|
||||
preferencesInfo = value.preferences || {};
|
||||
githubUrlIssue = CreateGithubIssueUrl();
|
||||
});
|
||||
|
||||
function CreateGithubIssueUrl() {
|
||||
let title = "[Feedback] Playlet";
|
||||
let body = `### Feedback
|
||||
_insert feedback here_
|
||||
|
||||
#### App Info
|
||||
\`\`\`
|
||||
${JSON.stringify(appInfo, null, 2)}
|
||||
\`\`\`
|
||||
|
||||
#### Device Info
|
||||
\`\`\`
|
||||
${JSON.stringify(deviceInfo, null, 2)}
|
||||
\`\`\`
|
||||
|
||||
#### Invidious settings
|
||||
\`\`\`
|
||||
${JSON.stringify(invidiousInfo, null, 2)}
|
||||
\`\`\`
|
||||
|
||||
#### User preferences
|
||||
\`\`\`
|
||||
${JSON.stringify(preferencesInfo, null, 2)}
|
||||
\`\`\``;
|
||||
return `https://github.com/iBicha/playlet/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class={visibility ? "" : "hidden"}>
|
||||
<div class="text-base text-center m-8">
|
||||
Thank you for using Playlet.<br/> You have feedback? Let us know by <a class="link" href={githubUrlIssue} target="_blank" rel="noopener noreferrer">creating an issue on Github</a>.
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Object.entries(displayNames) as [key, value]}
|
||||
<tr>
|
||||
<td>{value}</td>
|
||||
<td>{appInfo[key]}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,140 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { InvidiousApi } from "./InvidiousApi";
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
import { playletStateStore, searchHistoryStore } from "./Stores";
|
||||
import VideoCell from "./VideoCell.svelte";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
let invidiousApi = new InvidiousApi();
|
||||
|
||||
let searchBox;
|
||||
let searchBoxText = "";
|
||||
let suggestions: { suggestions: any[] } = { suggestions: [] };
|
||||
let videos = [];
|
||||
let searchHistory = [];
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
invidiousApi.instance = value?.invidious?.current_instance;
|
||||
invidiousApi.userCountryCode = value?.device?.user_country_code ?? "US";
|
||||
});
|
||||
|
||||
searchHistoryStore.subscribe((value) => {
|
||||
searchHistory = value;
|
||||
});
|
||||
|
||||
async function searchSuggestions(event) {
|
||||
const query = event.currentTarget.value;
|
||||
let newSuggestions;
|
||||
if (query.length === 0) {
|
||||
newSuggestions = { suggestions: [], query: "" };
|
||||
} else {
|
||||
newSuggestions = await invidiousApi.searchSuggestions(query);
|
||||
}
|
||||
|
||||
// If we're late and the user walked away, no need for suggestions
|
||||
if (document.activeElement === searchBox) {
|
||||
// Check if this query is old or new
|
||||
if (searchBoxText === newSuggestions.query) {
|
||||
suggestions = makeSuggestionList(newSuggestions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function makeSuggestionList(newSuggestions, maxItems = 10) {
|
||||
const matchingHistory = getSavedHistoryMatchingQuery(searchBoxText);
|
||||
const matchingHistoryAndSuggestions = [
|
||||
...matchingHistory,
|
||||
...newSuggestions.suggestions,
|
||||
];
|
||||
const uniqueMatchingHistoryAndSuggestions = [
|
||||
...new Set(matchingHistoryAndSuggestions),
|
||||
];
|
||||
return {
|
||||
suggestions: uniqueMatchingHistoryAndSuggestions.slice(0, maxItems),
|
||||
query: newSuggestions.query,
|
||||
};
|
||||
}
|
||||
|
||||
function getSavedHistoryMatchingQuery(query) {
|
||||
if (query.length === 0) {
|
||||
return searchHistory;
|
||||
}
|
||||
return searchHistory.filter((item) => item.startsWith(query));
|
||||
}
|
||||
|
||||
async function suggestionClicked(query) {
|
||||
searchBoxText = query;
|
||||
await searchVideos();
|
||||
}
|
||||
|
||||
async function searchVideos() {
|
||||
suggestions = { suggestions: [] };
|
||||
videos = [];
|
||||
if (searchBoxText.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
videos = await invidiousApi.search(searchBoxText);
|
||||
const newSearchHistory = await PlayletApi.putSearchHistory(searchBoxText);
|
||||
searchHistoryStore.set(newSearchHistory);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class={visibility ? "" : "hidden"}>
|
||||
<div class="m-4">
|
||||
<form
|
||||
on:submit={async (e) => {
|
||||
e.preventDefault();
|
||||
await searchVideos();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="search"
|
||||
dir="auto"
|
||||
placeholder="Search..."
|
||||
class="input w-full border border-neutral rounded-full"
|
||||
bind:this={searchBox}
|
||||
bind:value={searchBoxText}
|
||||
on:input={searchSuggestions}
|
||||
on:focus={searchSuggestions}
|
||||
on:blur={() => {
|
||||
// A delay before clearing the suggestions allows the user to click on a suggestion
|
||||
// Clicking the suggestion will trigger the blur event immediately, and the search won't happen
|
||||
setTimeout(() => {
|
||||
suggestions = { suggestions: [] };
|
||||
}, 200);
|
||||
}}
|
||||
/>
|
||||
{#if suggestions.suggestions.length > 0}
|
||||
<ul
|
||||
class="dropdown-content menu z-10 p-2 shadow-xl bg-base-200 rounded-box"
|
||||
>
|
||||
{#each suggestions.suggestions as suggestion}
|
||||
<li class="p-1">
|
||||
<button
|
||||
type="button"
|
||||
on:click={async (e) => {
|
||||
await suggestionClicked(e.currentTarget.innerText);
|
||||
}}>{@html suggestion}</button
|
||||
>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div
|
||||
class="grid grid-flow-row-dense gap-4 items-center justify-center sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 m-4"
|
||||
>
|
||||
{#each videos as video}
|
||||
{#if video.type === "video"}
|
||||
<VideoCell {...video} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
import DevSettings from "./DevSettings.svelte";
|
||||
import SettingsNode from "./SettingsNode.svelte";
|
||||
import { preferencesModelStore } from "./Stores";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
let developerOptionsEnabled = false;
|
||||
|
||||
onMount(async () => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
developerOptionsEnabled = !!urlParams.get("dev");
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class={visibility ? "" : "hidden"}>
|
||||
{#each $preferencesModelStore as pref, i}
|
||||
{#if pref.visibility !== "tv"}
|
||||
<SettingsNode {...pref} />
|
||||
{#if i !== $preferencesModelStore.length - 1}
|
||||
<div class="divider" />
|
||||
{/if}
|
||||
{/if}
|
||||
{/each}
|
||||
{#if developerOptionsEnabled}
|
||||
<div class="divider" />
|
||||
<DevSettings />
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "../PlayletApi";
|
||||
import { userPreferencesStore } from "../Stores";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
|
||||
let value;
|
||||
userPreferencesStore.subscribe((userPreferences) => {
|
||||
value = userPreferences[key];
|
||||
});
|
||||
|
||||
async function handleChange() {
|
||||
if (key !== "") {
|
||||
await PlayletApi.saveUserPreference(key, value);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="form-control m-5">
|
||||
<label class="label p-0 cursor-pointer">
|
||||
<div class="label-text {textSizes[level]}">{displayText}</div>
|
||||
<input
|
||||
type="checkbox"
|
||||
name={key}
|
||||
bind:checked={value}
|
||||
on:change={handleChange}
|
||||
class="checkbox"
|
||||
/>
|
||||
</label>
|
||||
<div class="text-xs text-gray-500">{description}</div>
|
||||
</div>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "../PlayletApi";
|
||||
import { searchHistoryStore } from "../Stores";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
// svelte-ignore unused-export-let
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
|
||||
async function clearSeachHistory() {
|
||||
await PlayletApi.clearSearchHistory();
|
||||
searchHistoryStore.set([]);
|
||||
alert("Search history cleared.");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="m-5">
|
||||
<div class={textSizes[level]}>{displayText}</div>
|
||||
<div class="text-xs text-gray-500">{description}</div>
|
||||
<button class="btn m-1" on:click={clearSeachHistory}
|
||||
>Clear search history</button
|
||||
>
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "../PlayletApi";
|
||||
import { userPreferencesStore } from "../Stores";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
export let options: any[] = [];
|
||||
|
||||
let value;
|
||||
userPreferencesStore.subscribe((userPreferences) => {
|
||||
value = userPreferences[key];
|
||||
});
|
||||
|
||||
async function handleChange(event) {
|
||||
if (key !== "") {
|
||||
value = event.currentTarget.value;
|
||||
await PlayletApi.saveUserPreference(key, value);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="m-5">
|
||||
<div class={textSizes[level]}>{displayText}</div>
|
||||
<div class="text-xs text-gray-500">{description}</div>
|
||||
|
||||
{#each options as option}
|
||||
<div class="form-control">
|
||||
<label class="label cursor-pointer">
|
||||
<span class="label-text">{option.displayText}</span>
|
||||
<input
|
||||
type="radio"
|
||||
name={key}
|
||||
value={option.value}
|
||||
class="radio"
|
||||
checked={value === option.value}
|
||||
on:change={handleChange}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,44 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "../PlayletApi";
|
||||
import { userPreferencesStore } from "../Stores";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
|
||||
let inputValue;
|
||||
let currentValue;
|
||||
userPreferencesStore.subscribe((userPreferences) => {
|
||||
currentValue = userPreferences[key];
|
||||
inputValue = currentValue;
|
||||
});
|
||||
|
||||
async function save() {
|
||||
if (key !== "") {
|
||||
const value = inputValue;
|
||||
await PlayletApi.saveUserPreference(key, value);
|
||||
currentValue = inputValue = value;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="m-5">
|
||||
<div class={textSizes[level]}>{displayText}</div>
|
||||
<div class="text-xs text-gray-500">{description}</div>
|
||||
|
||||
<div class="join w-full m-1">
|
||||
<input
|
||||
type="text"
|
||||
name={key}
|
||||
bind:value={inputValue}
|
||||
placeholder={displayText}
|
||||
class="join-item input w-full mr-1"
|
||||
/>
|
||||
{#if inputValue !== currentValue}
|
||||
<button class="join-item btn" on:click={save}>Save</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script lang="ts">
|
||||
import BooleanControl from "./SettingControls/BooleanControl.svelte";
|
||||
import ClearSearchHistoryControl from "./SettingControls/ClearSearchHistoryControl.svelte";
|
||||
import RadioControl from "./SettingControls/RadioControl.svelte";
|
||||
import StringControl from "./SettingControls/StringControl.svelte";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let type: "boolean" | "radio" | "string" | undefined = undefined;
|
||||
export let svelteComponent: string | undefined = undefined;
|
||||
export let options: any[] | undefined = undefined;
|
||||
export let visibility: string | undefined = undefined;
|
||||
export let children: any[] | undefined = [];
|
||||
export let level: number = 0;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let defaultValue: any = undefined;
|
||||
|
||||
const customComponents = {
|
||||
ClearSearchHistoryControl
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if visibility !== "tv"}
|
||||
{#if type === "boolean"}
|
||||
<BooleanControl {displayText} {key} {description} {level} />
|
||||
{:else if type === "radio"}
|
||||
<RadioControl {displayText} {key} {description} {level} {options} />
|
||||
{:else if type === "string"}
|
||||
<StringControl {displayText} {key} {description} {level} />
|
||||
{:else if svelteComponent}
|
||||
<svelte:component this={customComponents[svelteComponent]} {displayText} {key} {description} {level} />
|
||||
{:else}
|
||||
<div class="m-5">
|
||||
<div class={textSizes[level]}>{displayText}</div>
|
||||
<div class="text-xs text-gray-500">{description}</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if children}
|
||||
{#each children as child}
|
||||
<svelte:self {...child} level={level + 1} />
|
||||
{/each}
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -1,3 +1,20 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import type { AppState, PlayletState } from './Types';
|
||||
|
||||
export const playletStateStore = writable({} as any);
|
||||
export const playletStateStore = writable({} as PlayletState);
|
||||
|
||||
export const appStateStore = writable({
|
||||
screen: 'home',
|
||||
} as AppState);
|
||||
|
||||
export const appThemeStore = writable("dark" as "dark" | "light");
|
||||
|
||||
export const preferencesModelStore = writable([] as any);
|
||||
|
||||
export const userPreferencesStore = writable({} as any);
|
||||
|
||||
export const invidiousVideoApiStore = writable({} as any);
|
||||
|
||||
export const homeLayoutFileStore = writable([] as any);
|
||||
|
||||
export const searchHistoryStore = writable([] as any);
|
||||
@@ -0,0 +1,31 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { appThemeStore } from "./Stores";
|
||||
|
||||
let checked;
|
||||
appThemeStore.subscribe((value) => {
|
||||
checked = value === "dark";
|
||||
document.documentElement.setAttribute("data-theme", value);
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
const savedTheme = localStorage.getItem('theme') as 'dark' | 'light' | undefined;
|
||||
if(savedTheme) {
|
||||
appThemeStore.set(savedTheme);
|
||||
}
|
||||
});
|
||||
|
||||
function handleChange() {
|
||||
const theme = checked ? "dark" : "light";
|
||||
localStorage.setItem("theme", theme);
|
||||
appThemeStore.set(theme);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row m-3">
|
||||
<div class="p-2">☀️</div>
|
||||
<label class="flex items-center">
|
||||
<input type="checkbox" class="toggle toggle-sm p2" bind:checked={checked} on:change={handleChange} />
|
||||
</label>
|
||||
<div class="p-2">🌙</div>
|
||||
</div>
|
||||
@@ -0,0 +1,10 @@
|
||||
export type AppState = {
|
||||
screen: "search" | "home" | "settings" | "info"
|
||||
}
|
||||
|
||||
export type PlayletState = {
|
||||
app?: any,
|
||||
device?: any,
|
||||
invidious?: any,
|
||||
preferences?: any,
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "./PlayletApi";
|
||||
import { playletStateStore } from "./Stores";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let videoId: string | undefined = undefined;
|
||||
export let author: string | undefined = undefined;
|
||||
export let videoThumbnails: any[] | undefined = undefined;
|
||||
export let viewCount: number | undefined = undefined;
|
||||
export let publishedText: string | undefined = undefined;
|
||||
export let isUpcoming: boolean = undefined;
|
||||
export let premiereTimestamp: number | undefined = undefined;
|
||||
export let lengthSeconds: number = undefined;
|
||||
export let liveNow: boolean = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorId: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorUrl: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorVerified: boolean = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let description: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let descriptionHtml: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let viewCountText: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let published: number = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let premium: boolean = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let index: number = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let indexId: string = undefined;
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
function getViewCountDateText() {
|
||||
if (isUpcoming) {
|
||||
return `Premeres in ${getFormattedTimeLeft(premiereTimestamp)}`;
|
||||
}
|
||||
const pubText = publishedText || '';
|
||||
const viewCountText = formatViewCount(viewCount);
|
||||
|
||||
if (pubText === '' && viewCountText === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `${pubText} • ${viewCountText}`;
|
||||
}
|
||||
|
||||
function getFormattedTimeLeft(unixTimestamp) {
|
||||
if (unixTimestamp === "invalid") {
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
let timeLeft = unixTimestamp - currentTime;
|
||||
if (timeLeft <= 0) {
|
||||
return "now";
|
||||
}
|
||||
|
||||
if (timeLeft < 60) {
|
||||
let result = `${timeLeft} second`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
timeLeft = timeLeft / 60.0;
|
||||
if (timeLeft < 60) {
|
||||
timeLeft = Math.floor(timeLeft);
|
||||
let result = `${timeLeft} minute`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
timeLeft = timeLeft / 60.0;
|
||||
if (timeLeft < 24) {
|
||||
timeLeft = Math.floor(timeLeft);
|
||||
let result = `${timeLeft} hour`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
timeLeft = timeLeft / 24.0;
|
||||
timeLeft = Math.floor(timeLeft);
|
||||
let result = `${timeLeft} day`;
|
||||
if (timeLeft > 1) {
|
||||
result += "s";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function getThumbnailUrl(quality: string = "medium") {
|
||||
if (!videoThumbnails || videoThumbnails.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const videoThumbnail =
|
||||
videoThumbnails.find((thumbnail) => thumbnail.quality === quality) ||
|
||||
videoThumbnails[0];
|
||||
return videoThumbnail.url;
|
||||
}
|
||||
|
||||
function formatViewCount(viewCount) {
|
||||
if (isNaN(viewCount)) {
|
||||
return "";
|
||||
}
|
||||
if (viewCount < 1000) {
|
||||
return `${formatFloat(viewCount)} views`;
|
||||
}
|
||||
|
||||
viewCount = viewCount / 1000;
|
||||
if (viewCount < 1000) {
|
||||
return `${formatFloat(viewCount)}K views`;
|
||||
}
|
||||
|
||||
viewCount = viewCount / 1000;
|
||||
if (viewCount < 1000) {
|
||||
return `${formatFloat(viewCount)}M views`;
|
||||
}
|
||||
|
||||
viewCount = viewCount / 1000;
|
||||
return `${formatFloat(viewCount)}B views`;
|
||||
}
|
||||
|
||||
function formatFloat(X) {
|
||||
X = X * 10;
|
||||
X = X + 0.5;
|
||||
X = Math.floor(X);
|
||||
X = X / 10;
|
||||
return X;
|
||||
}
|
||||
|
||||
function getFormattedTime(length) {
|
||||
const minutes = Math.floor(length / 60).toString();
|
||||
const seconds = (length % 60);
|
||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||
return minutes + ":" + secondsString;
|
||||
}
|
||||
|
||||
function isVideoLive() {
|
||||
if (liveNow) {
|
||||
return true;
|
||||
}
|
||||
return lengthSeconds === 0 && viewCount === 0;
|
||||
}
|
||||
|
||||
async function playVideoOnTv() {
|
||||
await PlayletApi.playVideo(videoId);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
window.open(`${invidiousInstance}/watch?v=${videoId}`)
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="w-80 p-2" on:click="{modal.showModal()}">
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<figure class="relative">
|
||||
<img class="w-full rounded-box" loading="lazy" width="320" height="180" src={getThumbnailUrl()} alt={title} />
|
||||
{#if isVideoLive()}
|
||||
<div class="absolute bottom-2 right-0 bg-red-500 text-white text-sm rounded-sm font-bold pt-1 pb-1 pr-2 pl-2">LIVE</div>
|
||||
{:else}
|
||||
{#if lengthSeconds}
|
||||
<div class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2">{getFormattedTime(lengthSeconds)}</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</figure>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
|
||||
<div class="font-semibold">{author}</div>
|
||||
<div>{getViewCountDateText()}</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO: a dialog for every video is very slow. Need to reuse the same one -->
|
||||
<dialog bind:this={modal} id="modal_{videoId}" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<h3 class="text-lg m-5">{title}</h3>
|
||||
<div class="flex flex-col">
|
||||
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button>
|
||||
<button class="btn m-2" on:click={openInvidiousInNewTab}>Open in Invidious</button>
|
||||
<button class="btn m-2">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
Reference in new issue
Block a user