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,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>
|
||||
Reference in new issue
Block a user