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:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2023-06-24 15:33:09 -04:00
1 parent 9a631aab51
commit 8f8c7d38a8
91 files changed
+3979 -1787

No files matched your search

+53 -12
View File
@@ -1,25 +1,66 @@
<script lang="ts">
import { onMount } from "svelte";
import InstanceInfo from "./lib/InstanceInfo.svelte";
import NavBar from "./lib/NavBar.svelte";
import PlayVideo from "./lib/PlayVideo.svelte";
import ClearSearchHistory from "./lib/ClearSearchHistory.svelte";
import { PlayletApi } from "./lib/PlayletApi";
import { playletStateStore } from "./lib/Stores";
import LegacyUI from "./lib/LegacyUI.svelte";
import { appStateStore, homeLayoutFileStore, invidiousVideoApiStore, playletStateStore, preferencesModelStore, searchHistoryStore, userPreferencesStore } from "./lib/Stores";
import BottomNavigation from "./lib/BottomNavigation.svelte";
import ScreenHome from "./lib/ScreenHome.svelte";
import type { AppState } from "./lib/Types";
import ScreenSearch from "./lib/ScreenSearch.svelte";
import ScreenSettings from "./lib/ScreenSettings.svelte";
import ScreenInfo from "./lib/ScreenInfo.svelte";
import LinkDragDrop from "./lib/LinkDragDrop.svelte";
onMount(async () => {
const playletState = await PlayletApi.getState();
playletStateStore.set(playletState);
PlayletApi.getState().then((value) => {
playletStateStore.set(value);
});
PlayletApi.getHomeLayoutFile().then((value) => {
homeLayoutFileStore.set(value);
});
PlayletApi.getInvidiousVideoApiFile().then((invidiousVideoApiFile) => {
const invidiousVideoApiDefinitions =
invidiousVideoApiFile.endpoints.reduce((acc, endpoint) => {
acc[endpoint.name] = endpoint;
return acc;
}, {});
invidiousVideoApiStore.set(invidiousVideoApiDefinitions);
});
PlayletApi.getPreferencesFile().then((value) => {
preferencesModelStore.set(value);
});
PlayletApi.getUserPreferences().then((value) => {
userPreferencesStore.set(value);
});
PlayletApi.getSearchHistory().then((value) => {
searchHistoryStore.set(value);
});
});
let currentScreen: AppState["screen"];
appStateStore.subscribe((value) => {
currentScreen = value.screen;
});
</script>
<main>
<LinkDragDrop />
<NavBar />
<div class="p-6 space-y-2 form-control">
<InstanceInfo />
<PlayVideo />
<ClearSearchHistory />
<LegacyUI />
<!-- TODO: a better way to make the BottomNavigation not hide screens -->
<div style="margin-bottom: 4rem">
<ScreenSearch visibility={currentScreen == "search"} />
<ScreenHome visibility={currentScreen == "home"} />
<ScreenSettings visibility={currentScreen == "settings"} />
<ScreenInfo visibility={currentScreen == "info"} />
</div>
<BottomNavigation />
</main>
@@ -0,0 +1,6 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;">
<g class="fill-current">
<path d="M4,10V21h6V15h4v6h6V10L12,3Z"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 364 B

@@ -0,0 +1,6 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 122.88" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;">
<g class="fill-current">
<path d="M61.44,9.23c-1.85,0-3.64,0.08-5.35,0.25c-1.71,0.17-3.44,0.42-5.17,0.77c-1.72,0.34-3.39,0.77-5,1.26 c-1.59,0.49-3.16,1.07-4.7,1.72l-0.1,0.05l0,0c-1.63,0.7-3.18,1.45-4.67,2.25c-1.5,0.81-2.94,1.68-4.31,2.6 c-1.38,0.93-2.72,1.92-3.99,2.97c-1.27,1.05-2.5,2.16-3.68,3.35l-0.04,0.04c-1.18,1.18-2.29,2.4-3.33,3.66 c-1.05,1.28-2.04,2.61-2.97,3.99c-0.92,1.36-1.78,2.8-2.59,4.3c-0.8,1.49-1.56,3.05-2.26,4.67l-0.05,0.11l0,0l-0.07,0.14 c-0.63,1.5-1.19,3.04-1.67,4.61c-0.49,1.59-0.9,3.23-1.24,4.93c-0.35,1.73-0.6,3.45-0.77,5.17c-0.17,1.72-0.25,3.5-0.25,5.35 c0,1.85,0.08,3.64,0.25,5.35c0.17,1.71,0.42,3.44,0.77,5.17c0.35,1.72,0.77,3.39,1.27,5c0.49,1.57,1.05,3.13,1.7,4.66 c0.04,0.07,0.07,0.14,0.1,0.21c0.69,1.6,1.43,3.13,2.23,4.6c0.81,1.5,1.68,2.94,2.59,4.3c0.93,1.39,1.92,2.72,2.98,4 c1.02,1.24,2.11,2.44,3.26,3.59c0.07,0.06,0.13,0.12,0.19,0.19c1.16,1.16,2.36,2.24,3.59,3.26c1.28,1.05,2.61,2.04,3.99,2.97 c1.36,0.92,2.8,1.78,4.3,2.59c1.49,0.8,3.05,1.56,4.67,2.26l0.21,0.1c1.52,0.64,3.07,1.2,4.67,1.69c1.58,0.49,3.23,0.9,4.92,1.24 c1.73,0.35,3.45,0.6,5.17,0.77c1.72,0.17,3.5,0.25,5.35,0.25c1.85,0,3.64-0.08,5.35-0.25c1.71-0.17,3.44-0.42,5.17-0.77 c1.72-0.35,3.39-0.77,5-1.27c1.59-0.49,3.16-1.07,4.71-1.73l0.09-0.04l0-0.01c1.63-0.7,3.18-1.45,4.67-2.25 c1.5-0.81,2.94-1.68,4.31-2.6c1.38-0.93,2.72-1.92,3.99-2.97c1.25-1.03,2.45-2.12,3.62-3.29c0.06-0.06,0.11-0.12,0.18-0.18 c1.15-1.15,2.23-2.35,3.25-3.58c1.05-1.28,2.05-2.61,2.98-4c0.92-1.36,1.78-2.8,2.59-4.3c0.8-1.49,1.56-3.04,2.26-4.67l0.1-0.22 c0.64-1.51,1.2-3.06,1.69-4.65c0.49-1.59,0.9-3.23,1.24-4.93c0.35-1.73,0.6-3.45,0.77-5.17c0.17-1.72,0.25-3.5,0.25-5.35 c0-1.85-0.08-3.64-0.25-5.35c-0.17-1.71-0.42-3.44-0.77-5.17c-0.35-1.72-0.77-3.39-1.27-5c-0.49-1.59-1.07-3.16-1.73-4.71 l-0.04-0.09l0,0c-0.7-1.63-1.45-3.18-2.25-4.67c-0.81-1.5-1.68-2.94-2.59-4.3c-0.93-1.38-1.92-2.72-2.97-3.99 c-1.02-1.24-2.12-2.45-3.28-3.61c-0.07-0.06-0.13-0.12-0.18-0.18c-1.16-1.16-2.35-2.24-3.59-3.26c-1.28-1.05-2.61-2.04-3.99-2.97 c-1.37-0.92-2.8-1.78-4.3-2.59c-1.49-0.8-3.04-1.56-4.67-2.25l-0.19-0.09c-1.52-0.64-3.08-1.21-4.68-1.7 c-1.58-0.49-3.23-0.9-4.93-1.24c-1.73-0.35-3.45-0.6-5.17-0.77C65.08,9.31,63.29,9.23,61.44,9.23L61.44,9.23z M63.34,31.17 c2.19,0,3.91,0.63,5.16,1.88c1.24,1.25,1.87,2.96,1.87,5.17c0,2.24-1.07,4.22-3.21,5.97c-2.16,1.74-4.66,2.62-7.52,2.62 c-2.14,0-3.85-0.6-5.16-1.8c-1.31-1.22-1.96-2.79-1.96-4.75c0-2.47,1.07-4.59,3.19-6.4C57.82,32.06,60.37,31.17,63.34,31.17 L63.34,31.17L63.34,31.17z M75.55,91.71H47.33v-4.75h5.3V57.95h-5.3v-3.78h13.19c3.33,0,6.61-0.4,9.85-1.22v34.01h5.18L75.55,91.71 L75.55,91.71L75.55,91.71z M49.12,1.2c1.96-0.39,3.99-0.69,6.08-0.89C57.29,0.1,59.37,0,61.44,0c2.07,0,4.15,0.1,6.24,0.31 c2.09,0.2,4.12,0.5,6.08,0.89c1.94,0.39,3.88,0.88,5.82,1.48c1.88,0.58,3.74,1.26,5.58,2.04l0.19,0.07l0,0l0.06,0.02 c1.85,0.8,3.65,1.67,5.38,2.61c1.71,0.93,3.4,1.95,5.07,3.07c1.63,1.1,3.21,2.27,4.73,3.52c1.52,1.25,2.97,2.56,4.34,3.95 c1.38,1.38,2.7,2.83,3.95,4.34c1.25,1.52,2.42,3.09,3.52,4.73c1.09,1.63,2.11,3.32,3.06,5.06l0,0l0.01,0 c0.94,1.74,1.82,3.54,2.61,5.39c0.02,0.05,0.04,0.1,0.06,0.15c0.78,1.83,1.46,3.7,2.05,5.6c0.61,1.96,1.11,3.92,1.5,5.89 c0.39,1.96,0.69,3.99,0.89,6.08c0.2,2.09,0.3,4.17,0.3,6.24c0,2.07-0.1,4.15-0.31,6.24c-0.2,2.09-0.5,4.12-0.89,6.08 c-0.39,1.94-0.88,3.88-1.48,5.82c-0.58,1.89-1.27,3.76-2.05,5.62l-0.04,0.09l0,0l-0.05,0.11c-0.8,1.85-1.67,3.65-2.61,5.38 c-0.93,1.71-1.95,3.4-3.07,5.07c-1.1,1.63-2.27,3.21-3.52,4.73c-1.25,1.52-2.56,2.96-3.95,4.34c-1.38,1.38-2.83,2.7-4.35,3.95 c-1.52,1.25-3.09,2.42-4.72,3.51c-1.63,1.09-3.32,2.11-5.06,3.06c-1.78,0.96-3.57,1.84-5.39,2.62c-0.05,0.02-0.1,0.04-0.16,0.06 c-1.83,0.78-3.7,1.46-5.6,2.05c-1.96,0.61-3.92,1.11-5.88,1.5c-1.96,0.39-3.99,0.69-6.08,0.89c-2.09,0.2-4.17,0.3-6.24,0.3 s-4.15-0.1-6.24-0.3c-2.09-0.2-4.12-0.5-6.08-0.89c-1.94-0.39-3.88-0.88-5.82-1.48c-1.89-0.58-3.76-1.27-5.61-2.05l-0.2-0.08l0,0 c-1.85-0.8-3.65-1.67-5.38-2.61c-1.71-0.93-3.4-1.95-5.07-3.07c-1.63-1.09-3.21-2.27-4.72-3.51c-1.52-1.25-2.97-2.57-4.35-3.95 c-1.38-1.38-2.7-2.83-3.95-4.34c-1.25-1.52-2.42-3.1-3.52-4.73c-1.09-1.63-2.11-3.32-3.06-5.06c-0.97-1.78-1.84-3.58-2.62-5.4 c-0.02-0.05-0.04-0.1-0.06-0.15c-0.78-1.83-1.46-3.7-2.05-5.6c-0.61-1.96-1.11-3.93-1.5-5.89c-0.39-1.96-0.69-3.99-0.89-6.08 C0.1,65.59,0,63.51,0,61.44c0-2.07,0.1-4.15,0.31-6.24c0.2-2.09,0.5-4.12,0.89-6.08c0.39-1.94,0.88-3.88,1.48-5.82 c0.58-1.88,1.26-3.74,2.04-5.59l0.09-0.23l0,0c0.8-1.85,1.67-3.65,2.61-5.38c0.93-1.71,1.95-3.4,3.07-5.07 c1.1-1.63,2.27-3.21,3.52-4.73c1.25-1.52,2.56-2.96,3.95-4.34c1.38-1.38,2.83-2.7,4.34-3.95c1.52-1.25,3.09-2.42,4.73-3.52 c1.67-1.12,3.36-2.14,5.07-3.07l0.13-0.06c1.73-0.94,3.48-1.78,5.26-2.55c0.05-0.02,0.1-0.04,0.15-0.06 c1.83-0.78,3.7-1.46,5.6-2.05C45.19,2.09,47.15,1.59,49.12,1.2L49.12,1.2z"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="371"
height="142"
viewBox="0 0 98.160945 37.570857"
version="1.1"
id="svg9602"
sodipodi:docname="logo-light.svg"
inkscape:version="1.2.1 (9c6d41e4, 2022-07-14)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview20"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="2.6316652"
inkscape:cx="125.96587"
inkscape:cy="61.177994"
inkscape:window-width="1440"
inkscape:window-height="744"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1"
inkscape:current-layer="svg9602" />
<defs
id="defs9599" />
<g
id="layer1"
transform="translate(-22.260864,-34.716253)">
<rect
style="fill:#242424;fill-opacity:0.99;stroke:none;stroke-width:1.24539;stroke-linejoin:round;stroke-dasharray:none"
id="rect8445"
width="65.39537"
height="36.795055"
x="22.703459"
y="35.180595"
rx="6.8266635"
ry="6.5550508" />
<g
aria-label="P"
transform="matrix(0.44612332,0,0,0.44612332,-53.310985,-114.20369)"
id="text416-2"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 182.08151,397.45387 v -50.02669 h 15.38134 q 4.032,0 7.54134,1.49333 3.50933,1.49334 6.12267,4.18134 2.61333,2.61333 4.10667,6.12267 1.49333,3.50933 1.49333,7.54133 0,3.95734 -1.49333,7.46667 -1.49334,3.50934 -4.10667,6.12267 -2.61334,2.53867 -6.12267,4.03201 -3.50934,1.49333 -7.54134,1.49333 h -8.81067 v 11.57334 z m 6.57067,-18.14401 h 8.81067 q 2.61334,0 4.928,-0.97067 2.31467,-1.04533 4.03201,-2.688 1.71733,-1.71733 2.688,-3.95733 1.04533,-2.31467 1.04533,-4.92801 0,-2.688 -1.04533,-5.00267 -0.97067,-2.31466 -2.688,-4.032 -1.71734,-1.71733 -4.03201,-2.688 -2.31466,-0.97067 -4.928,-0.97067 h -8.81067 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9573" />
</g>
<g
aria-label="l"
transform="matrix(0.44612332,0,0,0.44612332,-36.59502,-114.22526)"
id="text416-2-1"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-8);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 189.92152,349.36851 v 48.08536 h -6.27201 v -48.08536 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9570" />
</g>
<g
aria-label="e"
transform="matrix(0.44612332,0,0,0.44612332,15.071073,-114.17511)"
id="text416-2-5"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-53);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 216.35353,388.8672 q -3.06134,4.55467 -7.24267,6.64533 -4.10667,2.09067 -8.96001,2.09067 -3.808,0 -7.168,-1.41867 -3.36,-1.49333 -5.824,-3.95733 -2.464,-2.464 -3.95734,-5.824 -1.41867,-3.36001 -1.41867,-7.16801 0,-3.88267 1.41867,-7.24267 1.49334,-3.36 3.95734,-5.824 2.464,-2.53867 5.824,-3.95734 3.36,-1.49333 7.168,-1.49333 4.85334,0 9.10934,2.24 4.33067,2.24 7.46667,6.944 l -21.65334,20.16001 q 1.19466,0.82134 2.98667,1.19467 1.792,0.29867 3.584,0.0747 3.136,-0.37334 5.824,-2.09067 2.76267,-1.792 4.62934,-4.48 z m -28.59735,-10.60267 q -0.224,2.83733 0.74667,5.22666 0.97066,2.38934 2.76267,3.73334 l 17.09867,-16.65067 q -1.41867,-1.71734 -3.808,-2.76267 -2.38934,-1.12 -5.22667,-0.97067 -2.31467,0.14933 -4.33067,1.04533 -2.016,0.896 -3.584,2.46401 -1.49333,1.49333 -2.464,3.50933 -0.97067,2.016 -1.19467,4.40534 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9558" />
</g>
<g
aria-label="t"
transform="matrix(0.44612332,0,0,0.44612332,32.445174,-114.17841)"
id="text416-2-59"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-6);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 180.21484,360.71785 h 3.43467 v -11.34934 h 6.34667 v 11.34934 h 6.64534 v 5.22667 h -6.64534 v 20.23468 q 0,2.61333 1.64267,4.256 1.64267,1.568 4.256,1.568 v 5.6 q -6.048,0 -9.184,-2.912 -3.06134,-2.912 -3.06134,-8.512 v -20.23468 h -3.43467 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9555" />
</g>
<g
aria-label="l"
transform="matrix(0.44612332,0,0,0.44612332,9.157916,-114.17642)"
id="text416-2-8"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-5);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 189.92152,349.36851 v 48.08536 h -6.27201 v -48.08536 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9561" />
</g>
<g
aria-label="a"
transform="matrix(0.44612332,0,0,0.44612332,-30.719029,-114.24707)"
id="text416-2-4"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-1);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 181.85751,379.23519 q 0,-3.88267 1.344,-7.24267 1.344,-3.36 3.584,-5.824 2.31467,-2.53867 5.37601,-3.95734 3.136,-1.49333 6.72,-1.49333 4.256,0 7.76534,2.09067 3.50933,2.016 5.74933,5.45067 v -7.39201 h 6.34667 v 36.58669 h -6.34667 v -7.31734 q -2.24,3.43467 -5.74933,5.45067 -3.50934,2.016 -7.76534,2.016 -3.584,0 -6.72,-1.41867 -3.06134,-1.49333 -5.37601,-3.95733 -2.24,-2.464 -3.584,-5.824 -1.344,-3.36001 -1.344,-7.16801 z m 6.34667,0 q 0,2.464 0.896,4.704 0.97067,2.16534 2.53867,3.80801 1.64267,1.64266 3.808,2.61333 2.24,0.896 4.77867,0.896 2.464,0 4.62934,-0.896 2.24,-0.97067 3.88266,-2.61333 1.64267,-1.64267 2.61334,-3.80801 0.97067,-2.24 0.97067,-4.704 0,-2.464 -0.97067,-4.704 -0.97067,-2.24 -2.61334,-3.88267 -1.64266,-1.64267 -3.88266,-2.61333 -2.16534,-0.97067 -4.62934,-0.97067 -2.53867,0 -4.77867,0.97067 -2.16533,0.97066 -3.808,2.61333 -1.568,1.64267 -2.53867,3.88267 -0.896,2.24 -0.896,4.704 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9567" />
</g>
<g
aria-label="y"
transform="matrix(0.44612332,0,0,0.44612332,-11.285794,-114.11033)"
id="text416-2-84"
style="font-size:74.6667px;font-family:'The Amaranth';-inkscape-font-specification:'The Amaranth, Normal';white-space:pre;shape-inside:url(#rect418-2-3);display:inline;fill:#ff1c30;stroke-width:1.06591;stroke-linejoin:round">
<path
d="m 186.56151,360.86718 10.97601,28.07468 10.752,-28.07468 h 6.72001 l -18.74135,47.56269 h -6.272 l 4.256,-10.82667 -14.48534,-36.73602 z"
style="font-family:'Bunya PERSONAL';-inkscape-font-specification:'Bunya PERSONAL, Normal'"
id="path9564" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.8 KiB

@@ -0,0 +1,6 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;">
<g class="fill-current">
<path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352c79.5 0 144-64.5 144-144s-64.5-144-144-144S64 128.5 64 208s64.5 144 144 144z"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 605 B

@@ -0,0 +1,6 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;">
<g class="fill-current">
<path d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,8c-2.21,0-4,1.79-4,4s1.79,4,4,4s4-1.79,4-4 S14.21,8,12,8L12,8z M13.22,3l0.55,2.2l0.13,0.51l0.5,0.18c0.61,0.23,1.19,0.56,1.72,0.98l0.4,0.32l0.5-0.14l2.17-0.62l1.22,2.11 l-1.63,1.59l-0.37,0.36l0.08,0.51c0.05,0.32,0.08,0.64,0.08,0.98s-0.03,0.66-0.08,0.98l-0.08,0.51l0.37,0.36l1.63,1.59l-1.22,2.11 l-2.17-0.62l-0.5-0.14l-0.4,0.32c-0.53,0.43-1.11,0.76-1.72,0.98l-0.5,0.18l-0.13,0.51L13.22,21h-2.44l-0.55-2.2l-0.13-0.51 l-0.5-0.18C9,17.88,8.42,17.55,7.88,17.12l-0.4-0.32l-0.5,0.14l-2.17,0.62L3.6,15.44l1.63-1.59l0.37-0.36l-0.08-0.51 C5.47,12.66,5.44,12.33,5.44,12s0.03-0.66,0.08-0.98l0.08-0.51l-0.37-0.36L3.6,8.56l1.22-2.11l2.17,0.62l0.5,0.14l0.4-0.32 C8.42,6.45,9,6.12,9.61,5.9l0.5-0.18l0.13-0.51L10.78,3H13.22 M14,2h-4L9.26,4.96c-0.73,0.27-1.4,0.66-2,1.14L4.34,5.27l-2,3.46 l2.19,2.13C4.47,11.23,4.44,11.61,4.44,12s0.03,0.77,0.09,1.14l-2.19,2.13l2,3.46l2.92-0.83c0.6,0.48,1.27,0.87,2,1.14L10,22h4 l0.74-2.96c0.73-0.27,1.4-0.66,2-1.14l2.92,0.83l2-3.46l-2.19-2.13c0.06-0.37,0.09-0.75,0.09-1.14s-0.03-0.77-0.09-1.14l2.19-2.13 l-2-3.46L16.74,6.1c-0.6-0.48-1.27-0.87-2-1.14L14,2L14,2z"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@@ -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>
+58
View File
@@ -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>
-33
View File
@@ -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>
+128
View File
@@ -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)}&region=${this.userCountryCode}`);
return await response.json();
}
public async search(query: string) {
const response = await fetch(`${this.instance}/api/v1/search?q=${encodeURIComponent(query)}&region=${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();
}
}
-11
View File
@@ -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>
+152
View File
@@ -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>
+71 -38
View File
@@ -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>
-69
View File
@@ -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>
+71 -4
View File
@@ -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)
})
}
}
+12
View File
@@ -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>
+51
View File
@@ -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}
+81
View File
@@ -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>
+140
View File
@@ -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>
+30
View File
@@ -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>
+48
View File
@@ -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}
+18 -1
View File
@@ -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);
+31
View File
@@ -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>
+10
View File
@@ -0,0 +1,10 @@
export type AppState = {
screen: "search" | "home" | "settings" | "info"
}
export type PlayletState = {
app?: any,
device?: any,
invidious?: any,
preferences?: any,
}
+205
View File
@@ -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>