Support playing a video from a specific time (cast from phone, drag a… (#88)
* Support playing a video from a specific time (cast from phone, drag and drop, open in Invidious) * Remove a console log
This commit is contained in:
1 parent
6c84630cec
commit
3acf733eec
14 files changed
+216
-41
No files matched your search
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Support playing a video from a specific time (cast from phone, drag and drop, open in Invidious)
|
||||||
|
|
||||||
## [0.10.0] - 2023-06-25
|
## [0.10.0] - 2023-06-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
<!-- markdownlint-disable MD036 -->
|
||||||
|
|
||||||
# Releasing
|
# Releasing
|
||||||
|
|
||||||
These are mostly the steps when releasing a new version:
|
These are mostly the steps when releasing a new version:
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
<!-- markdownlint-disable MD041 -->
|
||||||
|
|
||||||
This is an automated release. It is generated when new code is pushed to the main branch.
|
This is an automated release. It is generated when new code is pushed to the main branch.
|
||||||
|
|
||||||
To test this release:
|
To test this release:
|
||||||
|
|||||||
@@ -113,8 +113,11 @@ function OnWebServerLogin()
|
|||||||
m.homeGridScreen.refresh = true
|
m.homeGridScreen.refresh = true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function OnWebServerCommand()
|
function OnWebServerCommand() as void
|
||||||
if m.serverTask.command.StartsWith("play:")
|
if m.serverTask.command = invalid or m.serverTask.command.command = invalid
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
if m.serverTask.command.command = "play"
|
||||||
sender = m.videoContainer.sender ?? m.currentFocued
|
sender = m.videoContainer.sender ?? m.currentFocued
|
||||||
if m.videoContainer.fullscreen
|
if m.videoContainer.fullscreen
|
||||||
dialog = m.top.getScene().dialog
|
dialog = m.top.getScene().dialog
|
||||||
@@ -122,7 +125,7 @@ function OnWebServerCommand()
|
|||||||
dialog.close = true
|
dialog.close = true
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
PlayVideo(m.serverTask.command.Mid(5), { sender: sender })
|
PlayVideo(m.serverTask.command.videoId, { sender: sender, timestamp: m.serverTask.command.timestamp })
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -146,5 +149,5 @@ function PlayVideoFromArgs(args as object) as void
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
sender = m.videoContainer.sender ?? m.currentFocued
|
sender = m.videoContainer.sender ?? m.currentFocued
|
||||||
PlayVideo(args.contentId, { sender: sender })
|
PlayVideo(args.contentId, { sender: sender, timestamp: args.timestamp })
|
||||||
end function
|
end function
|
||||||
@@ -7,11 +7,16 @@ import "pkg:/components/VideoPlayer/MarkVideoWatchedTask.bs"
|
|||||||
function PlayVideo(videoId as string, args = invalid as object)
|
function PlayVideo(videoId as string, args = invalid as object)
|
||||||
sender = args?.sender
|
sender = args?.sender
|
||||||
metadata = args?.metadata
|
metadata = args?.metadata
|
||||||
|
timestamp = args?.timestamp
|
||||||
|
|
||||||
if metadata <> invalid and GetInterface(metadata, "ifSGNodeField") <> invalid
|
if metadata <> invalid and GetInterface(metadata, "ifSGNodeField") <> invalid
|
||||||
metadata = args.metadata.getFields()
|
metadata = args.metadata.getFields()
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
if timestamp = invalid
|
||||||
|
timestamp = 0
|
||||||
|
end if
|
||||||
|
|
||||||
width = 1280
|
width = 1280
|
||||||
height = 720
|
height = 720
|
||||||
translation = [0.0, 0.0]
|
translation = [0.0, 0.0]
|
||||||
@@ -29,6 +34,7 @@ function PlayVideo(videoId as string, args = invalid as object)
|
|||||||
videoContainer.insertChild(videoContainer.videoPlayer, 0)
|
videoContainer.insertChild(videoContainer.videoPlayer, 0)
|
||||||
videoContainer.videoPlayer.id = "VideoPlayer"
|
videoContainer.videoPlayer.id = "VideoPlayer"
|
||||||
videoContainer.videoPlayer.metadata = metadata
|
videoContainer.videoPlayer.metadata = metadata
|
||||||
|
videoContainer.videoPlayer.timestamp = timestamp
|
||||||
videoContainer.videoPlayer.videoId = videoId
|
videoContainer.videoPlayer.videoId = videoId
|
||||||
videoContainer.videoPlayer.width = width
|
videoContainer.videoPlayer.width = width
|
||||||
videoContainer.videoPlayer.height = height
|
videoContainer.videoPlayer.height = height
|
||||||
|
|||||||
@@ -286,8 +286,11 @@ function OnVideoPlayerStateChange() as void
|
|||||||
|
|
||||||
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
|
' If we successfully played the video, then any error that comes later is not due to a 403 (FORBIDDEN).
|
||||||
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
|
' This is to reduce false positives, as we do not want retry another link if the first link is working fine.
|
||||||
if state = "playing"
|
if state = "playing" and not m.videoPlayingSuccess
|
||||||
m.videoPlayingSuccess = true
|
m.videoPlayingSuccess = true
|
||||||
|
if m.top.timestamp <> 0
|
||||||
|
m.top.seek = m.top.timestamp
|
||||||
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if state = "error"
|
if state = "error"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<field id="chapter" type="string" alias="chapterLabel.text" />
|
<field id="chapter" type="string" alias="chapterLabel.text" />
|
||||||
<field id="videoId" type="string" />
|
<field id="videoId" type="string" />
|
||||||
<field id="metadata" type="assocarray" />
|
<field id="metadata" type="assocarray" />
|
||||||
|
<field id="timestamp" type="integer" />
|
||||||
</interface>
|
</interface>
|
||||||
<children>
|
<children>
|
||||||
<Label
|
<Label
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ namespace Http
|
|||||||
response.Default(204, "OK")
|
response.Default(204, "OK")
|
||||||
return true
|
return true
|
||||||
else if payload.command = "play"
|
else if payload.command = "play"
|
||||||
videoId = payload.videoId
|
server.task.top.command = payload
|
||||||
server.task.top.command = `play:${videoId}`
|
|
||||||
response.Default(204, "OK")
|
response.Default(204, "OK")
|
||||||
return true
|
return true
|
||||||
else if payload.command = "set-playlet-lib-urls"
|
else if payload.command = "set-playlet-lib-urls"
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
<component name="WebServerTask" extends="Task">
|
<component name="WebServerTask" extends="Task">
|
||||||
<interface>
|
<interface>
|
||||||
<field id="login" type="boolean" alwaysNotify="true" />
|
<field id="login" type="boolean" alwaysNotify="true" />
|
||||||
<field id="command" type="string" alwaysNotify="true" />
|
<field id="command" type="assocarray" alwaysNotify="true" />
|
||||||
</interface>
|
</interface>
|
||||||
</component>
|
</component>
|
||||||
@@ -3,12 +3,16 @@
|
|||||||
import { PlayletApi } from "./PlayletApi";
|
import { PlayletApi } from "./PlayletApi";
|
||||||
import { playletStateStore } from "./Stores";
|
import { playletStateStore } from "./Stores";
|
||||||
import { InvidiousApi } from "./InvidiousApi";
|
import { InvidiousApi } from "./InvidiousApi";
|
||||||
|
import VideoStartAt from "./VideoStartAt.svelte";
|
||||||
|
|
||||||
let modal;
|
let modal;
|
||||||
let isDragging;
|
let isDragging;
|
||||||
let isLoading;
|
let isLoading;
|
||||||
let dragEndTimeout;
|
let dragEndTimeout;
|
||||||
|
|
||||||
|
let videoStartAtChecked;
|
||||||
|
let videoStartAtTimestamp;
|
||||||
|
|
||||||
let videoMetadata;
|
let videoMetadata;
|
||||||
|
|
||||||
let tvName = "Roku TV";
|
let tvName = "Roku TV";
|
||||||
@@ -43,10 +47,10 @@
|
|||||||
let dataString = await new Promise((resolve) =>
|
let dataString = await new Promise((resolve) =>
|
||||||
item.getAsString(resolve)
|
item.getAsString(resolve)
|
||||||
);
|
);
|
||||||
if (IsValidHttpUrl(dataString)) {
|
if (isValidHttpUrl(dataString)) {
|
||||||
const videoId = GetVideoId(dataString);
|
const videoInfo = parseYouTubeUrl(dataString);
|
||||||
if (videoId) {
|
if (videoInfo.videoId) {
|
||||||
searchForVideoById(videoId);
|
searchForVideoById(videoInfo.videoId, videoInfo.timestamp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,10 +58,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchForVideoById(videoId) {
|
async function searchForVideoById(videoId, timestamp) {
|
||||||
try {
|
try {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
videoMetadata = await invidiousApi.getVideoMetadata(videoId);
|
videoMetadata = await invidiousApi.getVideoMetadata(videoId);
|
||||||
|
videoStartAtTimestamp = timestamp;
|
||||||
|
videoStartAtChecked = videoStartAtTimestamp !== undefined;
|
||||||
modal.showModal();
|
modal.showModal();
|
||||||
} finally {
|
} finally {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
@@ -74,7 +80,7 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
function IsValidHttpUrl(string) {
|
function isValidHttpUrl(string) {
|
||||||
let url;
|
let url;
|
||||||
try {
|
try {
|
||||||
url = new URL(string);
|
url = new URL(string);
|
||||||
@@ -84,7 +90,18 @@
|
|||||||
return url.protocol === "http:" || url.protocol === "https:";
|
return url.protocol === "http:" || url.protocol === "https:";
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetVideoId(url) {
|
function parseYouTubeUrl(url) {
|
||||||
|
const urlSearchParams = new URLSearchParams(new URL(url).search);
|
||||||
|
|
||||||
|
function getTimestamp(){
|
||||||
|
const timestamp = urlSearchParams.get("t");
|
||||||
|
if (timestamp) {
|
||||||
|
return timestamp.endsWith("s")
|
||||||
|
? timestamp.slice(0, -1)
|
||||||
|
: timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Share/Short url
|
// Share/Short url
|
||||||
// TODO: use regex, and support timestamped videos
|
// TODO: use regex, and support timestamped videos
|
||||||
const YoutubeUrls = [
|
const YoutubeUrls = [
|
||||||
@@ -100,33 +117,52 @@
|
|||||||
for (var i in YoutubeUrls) {
|
for (var i in YoutubeUrls) {
|
||||||
let youtubeUrl = YoutubeUrls[i];
|
let youtubeUrl = YoutubeUrls[i];
|
||||||
if (url.startsWith(youtubeUrl)) {
|
if (url.startsWith(youtubeUrl)) {
|
||||||
url = url.replace(youtubeUrl, "");
|
let videoId = url.replace(youtubeUrl, "");
|
||||||
if (url.includes("?")) {
|
if (videoId.includes("?")) {
|
||||||
url = url.substring(0, url.indexOf("?"));
|
videoId = videoId.substring(0, videoId.indexOf("?"));
|
||||||
}
|
}
|
||||||
return url;
|
const result: any = {
|
||||||
|
videoId,
|
||||||
|
};
|
||||||
|
|
||||||
|
const timestamp = getTimestamp();
|
||||||
|
if (timestamp) {
|
||||||
|
result.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// regular url
|
// regular url
|
||||||
url = new URL(url);
|
const result: any = {
|
||||||
const urlSearchParams = new URLSearchParams(url.search);
|
videoId: urlSearchParams.get("v"),
|
||||||
return urlSearchParams.get("v");
|
};
|
||||||
|
|
||||||
|
const timestamp = getTimestamp();
|
||||||
|
if (timestamp) {
|
||||||
|
result.timestamp = timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function playVideoOnTv() {
|
async function playVideoOnTv() {
|
||||||
await PlayletApi.playVideo(videoMetadata?.videoId);
|
await PlayletApi.playVideo(videoMetadata?.videoId, videoStartAtTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openInvidiousInNewTab() {
|
function openInvidiousInNewTab() {
|
||||||
window.open(`${invidiousInstance}/watch?v=${videoMetadata?.videoId}`);
|
let url = `${invidiousInstance}/watch?v=${videoMetadata?.videoId}`;
|
||||||
|
if (videoStartAtChecked && videoStartAtTimestamp) {
|
||||||
|
url += `&t=${videoStartAtTimestamp}`;
|
||||||
|
}
|
||||||
|
window.open(url);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="{isDragging || isLoading
|
class="{isDragging || isLoading
|
||||||
? ''
|
? ''
|
||||||
: 'hidden'} absolute w-full h-full bg-base-100/80 z-50 flex justify-center items-center"
|
: 'hidden'} fixed w-full h-full bg-base-100/80 z-50 flex justify-center items-center"
|
||||||
>
|
>
|
||||||
{#if isDragging}
|
{#if isDragging}
|
||||||
<div class="text-2xl font-bold">Drop a Youtube link here</div>
|
<div class="text-2xl font-bold">Drop a Youtube link here</div>
|
||||||
@@ -139,6 +175,11 @@
|
|||||||
<form method="dialog" class="modal-box bg-base-100">
|
<form method="dialog" class="modal-box bg-base-100">
|
||||||
<h3 class="text-lg m-5">{videoMetadata?.title}</h3>
|
<h3 class="text-lg m-5">{videoMetadata?.title}</h3>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
|
<VideoStartAt
|
||||||
|
bind:checked={videoStartAtChecked}
|
||||||
|
bind:timestamp={videoStartAtTimestamp}
|
||||||
|
lengthSeconds={videoMetadata?.lengthSeconds}
|
||||||
|
/>
|
||||||
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button>
|
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button>
|
||||||
<button class="btn m-2" on:click={openInvidiousInNewTab}
|
<button class="btn m-2" on:click={openInvidiousInNewTab}
|
||||||
>Open in Invidious</button
|
>Open in Invidious</button
|
||||||
|
|||||||
@@ -43,11 +43,15 @@ export class PlayletApi {
|
|||||||
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "logout" });
|
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "logout" });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async playVideo(videoId) {
|
static async playVideo(videoId, timestamp) {
|
||||||
if (!videoId) {
|
if (!videoId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "play", videoId: videoId });
|
const payload = { command: "play", videoId: videoId };
|
||||||
|
if (timestamp !== undefined) {
|
||||||
|
payload["timestamp"] = timestamp;
|
||||||
|
}
|
||||||
|
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getSearchHistory() {
|
static async getSearchHistory() {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
// svelte-ignore unused-export-let
|
// svelte-ignore unused-export-let
|
||||||
export let defaultValue: any = undefined;
|
export let defaultValue: any = undefined;
|
||||||
|
// svelte-ignore unused-export-let
|
||||||
|
export let rokuComponent: any = undefined;
|
||||||
|
|
||||||
const customComponents = {
|
const customComponents = {
|
||||||
ClearSearchHistoryControl
|
ClearSearchHistoryControl
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { PlayletApi } from "./PlayletApi";
|
import { PlayletApi } from "./PlayletApi";
|
||||||
import { playletStateStore } from "./Stores";
|
import { playletStateStore } from "./Stores";
|
||||||
|
import VideoStartAt from "./VideoStartAt.svelte";
|
||||||
|
|
||||||
export let title: string | undefined = undefined;
|
export let title: string | undefined = undefined;
|
||||||
export let videoId: string | undefined = undefined;
|
export let videoId: string | undefined = undefined;
|
||||||
@@ -39,6 +40,8 @@
|
|||||||
let modal;
|
let modal;
|
||||||
let tvName = "Roku TV";
|
let tvName = "Roku TV";
|
||||||
let invidiousInstance;
|
let invidiousInstance;
|
||||||
|
let videoStartAtChecked;
|
||||||
|
let videoStartAtTimestamp;
|
||||||
|
|
||||||
playletStateStore.subscribe((value) => {
|
playletStateStore.subscribe((value) => {
|
||||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||||
@@ -49,11 +52,11 @@
|
|||||||
if (isUpcoming) {
|
if (isUpcoming) {
|
||||||
return `Premeres in ${getFormattedTimeLeft(premiereTimestamp)}`;
|
return `Premeres in ${getFormattedTimeLeft(premiereTimestamp)}`;
|
||||||
}
|
}
|
||||||
const pubText = publishedText || '';
|
const pubText = publishedText || "";
|
||||||
const viewCountText = formatViewCount(viewCount);
|
const viewCountText = formatViewCount(viewCount);
|
||||||
|
|
||||||
if (pubText === '' && viewCountText === '') {
|
if (pubText === "" && viewCountText === "") {
|
||||||
return '';
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${pubText} • ${viewCountText}`;
|
return `${pubText} • ${viewCountText}`;
|
||||||
@@ -149,7 +152,7 @@
|
|||||||
|
|
||||||
function getFormattedTime(length) {
|
function getFormattedTime(length) {
|
||||||
const minutes = Math.floor(length / 60).toString();
|
const minutes = Math.floor(length / 60).toString();
|
||||||
const seconds = (length % 60);
|
const seconds = length % 60;
|
||||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||||
return minutes + ":" + secondsString;
|
return minutes + ":" + secondsString;
|
||||||
}
|
}
|
||||||
@@ -162,24 +165,37 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function playVideoOnTv() {
|
async function playVideoOnTv() {
|
||||||
await PlayletApi.playVideo(videoId);
|
await PlayletApi.playVideo(videoId, videoStartAtTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openInvidiousInNewTab() {
|
function openInvidiousInNewTab() {
|
||||||
window.open(`${invidiousInstance}/watch?v=${videoId}`)
|
window.open(`${invidiousInstance}/watch?v=${videoId}`);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button class="w-80 p-2" on:click="{modal.showModal()}">
|
<button class="w-80 p-2" on:click={modal.showModal()}>
|
||||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||||
<figure class="relative">
|
<figure class="relative">
|
||||||
<img class="w-full rounded-box" loading="lazy" width="320" height="180" src={getThumbnailUrl()} alt={title} />
|
<img
|
||||||
|
class="w-full rounded-box"
|
||||||
|
loading="lazy"
|
||||||
|
width="320"
|
||||||
|
height="180"
|
||||||
|
src={getThumbnailUrl()}
|
||||||
|
alt={title}
|
||||||
|
/>
|
||||||
{#if isVideoLive()}
|
{#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>
|
<div
|
||||||
{:else}
|
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"
|
||||||
{#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>
|
LIVE
|
||||||
{/if}
|
</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>
|
</figure>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@@ -194,8 +210,15 @@
|
|||||||
<form method="dialog" class="modal-box bg-base-100">
|
<form method="dialog" class="modal-box bg-base-100">
|
||||||
<h3 class="text-lg m-5">{title}</h3>
|
<h3 class="text-lg m-5">{title}</h3>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
|
<VideoStartAt
|
||||||
|
bind:checked={videoStartAtChecked}
|
||||||
|
bind:timestamp={videoStartAtTimestamp}
|
||||||
|
{lengthSeconds}
|
||||||
|
/>
|
||||||
<button class="btn m-2" on:click={playVideoOnTv}>Play on {tvName}</button>
|
<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" on:click={openInvidiousInNewTab}
|
||||||
|
>Open in Invidious</button
|
||||||
|
>
|
||||||
<button class="btn m-2">Cancel</button>
|
<button class="btn m-2">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let checked = false;
|
||||||
|
export let lengthSeconds = undefined;
|
||||||
|
export let timestamp = 0;
|
||||||
|
|
||||||
|
let textInputElemet;
|
||||||
|
let timestampText = "";
|
||||||
|
let timestampRange = 0;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (document.activeElement !== textInputElemet) {
|
||||||
|
timestampText = getTimeStampText(timestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: timestampRange = timestamp !== undefined ? timestamp : 0;
|
||||||
|
|
||||||
|
function getTimeStamp(timestampText) {
|
||||||
|
if (timestampText === "") {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const match = /^(\d{1,3}):(\d{1,2})$/.exec(timestampText);
|
||||||
|
if (match) {
|
||||||
|
const minutes = parseInt(match[1]);
|
||||||
|
const seconds = parseInt(match[2]);
|
||||||
|
if (seconds < 60) {
|
||||||
|
return minutes * 60 + seconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTimeStampText(timestamp) {
|
||||||
|
if (timestamp === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const minutes = Math.floor(timestamp / 60);
|
||||||
|
const remainingSeconds = timestamp % 60;
|
||||||
|
|
||||||
|
const formattedMinutes = String(minutes);
|
||||||
|
const formattedSeconds = String(remainingSeconds).padStart(2, "0");
|
||||||
|
|
||||||
|
return `${formattedMinutes}:${formattedSeconds}`;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="form-control">
|
||||||
|
<div class="flex flex-row items-center">
|
||||||
|
<label class="label justify-start cursor-pointer">
|
||||||
|
<input type="checkbox" bind:checked class="checkbox" />
|
||||||
|
<span class="label-text m-2">Start at</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
bind:this={textInputElemet}
|
||||||
|
disabled={!checked}
|
||||||
|
class="input w-24"
|
||||||
|
placeholder="0:00"
|
||||||
|
bind:value={timestampText}
|
||||||
|
on:input={(e) => {
|
||||||
|
timestamp = getTimeStamp(e.currentTarget.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{#if checked}
|
||||||
|
{#if timestamp !== undefined}
|
||||||
|
<span class="label-text m-2">({timestamp}s)</span>
|
||||||
|
{:else}
|
||||||
|
<span class="label-text m-2 text-error">(Invalid time)</span>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if lengthSeconds && checked}
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max={lengthSeconds}
|
||||||
|
bind:value={timestampRange}
|
||||||
|
on:input={(e) => {
|
||||||
|
// @ts-ignore
|
||||||
|
timestamp = e.currentTarget.value;
|
||||||
|
}}
|
||||||
|
class="range range-xs range-primary"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
Reference in new issue
Block a user