Refactor casting dialog and add thumbnails (#184)
This commit is contained in:
1 parent
f58137b326
commit
af1fa0b401
17 files changed
+525
-393
No files matched your search
@@ -1,11 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import { InvidiousApi } from "lib/Api/InvidiousApi";
|
||||
import VideoStartAt from "lib/VideoStartAt.svelte";
|
||||
import VideoCastDialog from "./VideoFeed/VideoCastDialog.svelte";
|
||||
import ChannelCastDialog from "./VideoFeed/ChannelCastDialog.svelte";
|
||||
|
||||
let modal;
|
||||
let videoModal;
|
||||
let channelModal;
|
||||
let isDragging;
|
||||
let isLoading;
|
||||
let dragEndTimeout;
|
||||
@@ -88,7 +89,7 @@
|
||||
if (videoStartAtChecked) {
|
||||
videoStartAtTimestamp = timestamp;
|
||||
}
|
||||
modal.showModal();
|
||||
videoModal.show();
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
@@ -98,7 +99,7 @@
|
||||
try {
|
||||
isLoading = true;
|
||||
channelMetadata = await invidiousApi.getChannelMetadata(channelId);
|
||||
modal.showModal();
|
||||
channelModal.show();
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
@@ -181,46 +182,11 @@
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
modal.close();
|
||||
videoModal?.close();
|
||||
channelModal?.close();
|
||||
videoMetadata = undefined;
|
||||
channelMetadata = undefined;
|
||||
}
|
||||
|
||||
async function playVideoOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.playVideo(
|
||||
videoMetadata?.videoId,
|
||||
timestamp,
|
||||
videoMetadata?.title,
|
||||
videoMetadata?.author
|
||||
);
|
||||
}
|
||||
async function queueVideoOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.queueVideo(
|
||||
videoMetadata?.videoId,
|
||||
timestamp,
|
||||
videoMetadata?.title,
|
||||
videoMetadata?.author
|
||||
);
|
||||
}
|
||||
|
||||
async function openChannelOnTv() {
|
||||
await PlayletApi.openChannel(channelMetadata?.authorId);
|
||||
}
|
||||
|
||||
function openVideoInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/watch?v=${videoMetadata?.videoId}`;
|
||||
if (videoStartAtChecked && videoStartAtTimestamp) {
|
||||
url += `&t=${videoStartAtTimestamp}`;
|
||||
}
|
||||
window.open(url);
|
||||
}
|
||||
|
||||
function openChannelInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/channel/${channelMetadata?.authorId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -235,41 +201,22 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<dialog bind:this={modal} id="modal_video_drag_drop" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
{#if videoMetadata}
|
||||
<h3 class="text-lg m-5">{videoMetadata.title}</h3>
|
||||
<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={queueVideoOnTv}>
|
||||
Queue on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openVideoInvidiousInNewTab}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
</div>
|
||||
{:else if channelMetadata}
|
||||
<h3 class="text-lg m-5">{channelMetadata.author}</h3>
|
||||
<div class="text-sm m-5 line-clamp-3">{channelMetadata.description}</div>
|
||||
<button class="btn m-2" on:click={openChannelOnTv}>
|
||||
Open on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openChannelInvidiousInNewTab}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
{:else}
|
||||
<span class="loading loading-spinner loading-md" />
|
||||
{/if}
|
||||
<button class="btn m-2">Cancel</button>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
<VideoCastDialog
|
||||
bind:this={videoModal}
|
||||
videoId={videoMetadata?.videoId}
|
||||
title={videoMetadata?.title}
|
||||
videoThumbnails={videoMetadata?.videoThumbnails}
|
||||
author={videoMetadata?.author}
|
||||
lengthSeconds={videoMetadata?.lengthSeconds}
|
||||
liveNow={videoMetadata?.liveNow}
|
||||
viewCount={videoMetadata?.viewCount}
|
||||
bind:videoStartAtChecked
|
||||
bind:videoStartAtTimestamp
|
||||
/>
|
||||
|
||||
<ChannelCastDialog
|
||||
bind:this={channelModal}
|
||||
author={channelMetadata?.author}
|
||||
authorId={channelMetadata?.authorId}
|
||||
authorThumbnails={channelMetadata?.authorThumbnails}
|
||||
/>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import VideoListRow from "./Home/VideoListRow.svelte";
|
||||
import VideoListRow from "lib/VideoFeed/VideoListRow.svelte";
|
||||
import { bookmarksStore } from "lib/Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
|
||||
export let author: string | undefined = undefined;
|
||||
export let authorId: string | undefined = undefined;
|
||||
export let authorThumbnails: any[] | undefined = undefined;
|
||||
export let channelHandle: string | undefined = undefined;
|
||||
export let subCount: number | undefined = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: 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 getThumbnailUrl() {
|
||||
if (!authorThumbnails || authorThumbnails.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const authorThumbnail = authorThumbnails[authorThumbnails.length - 1];
|
||||
let url = authorThumbnail.url;
|
||||
if (url.startsWith("//")) {
|
||||
url = "https:" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
async function openChannelOnTv() {
|
||||
await PlayletApi.openChannel(authorId);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/channel/${authorId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="w-60 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-44 rounded-full aspect-square object-cover"
|
||||
loading="lazy"
|
||||
width="176"
|
||||
height="176"
|
||||
src={getThumbnailUrl()}
|
||||
alt={author}
|
||||
/>
|
||||
</figure>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-1 min-h-8">{author}</h3>
|
||||
<div>{subCount} subscribers</div>
|
||||
<div>{channelHandle || ""}</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO:P2 a dialog for every video is very slow. Need to reuse the same one -->
|
||||
<dialog bind:this={modal} id="modal_{authorId}" class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<h3 class="text-lg m-5">{author}</h3>
|
||||
<div class="flex flex-col">
|
||||
<button class="btn m-2" on:click={openChannelOnTv}>
|
||||
Open 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,114 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let author: string | undefined = undefined;
|
||||
export let playlistId: string | undefined = undefined;
|
||||
export let playlistThumbnail: string | undefined = undefined;
|
||||
export let videoCount: number | undefined = undefined;
|
||||
export let videos: any[] | undefined = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: 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 getThumbnailUrl(quality: string = "medium") {
|
||||
let url = "";
|
||||
if (playlistThumbnail) {
|
||||
url = playlistThumbnail;
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
} else if (videos && videos.length) {
|
||||
const video = videos[0];
|
||||
if (video.videoThumbnails) {
|
||||
const videoThumbnail =
|
||||
video.videoThumbnails.find(
|
||||
(thumbnail) => thumbnail.quality === quality
|
||||
) || video.videoThumbnails[0];
|
||||
url = videoThumbnail.url;
|
||||
}
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
}
|
||||
if (url === "") {
|
||||
url = `${invidiousInstance}/vi/-----------/mqdefault.jpg`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
async function playPlaylistOnTv() {
|
||||
await PlayletApi.playPlaylist(playlistId, title, videoCount);
|
||||
}
|
||||
|
||||
async function queuePlaylistOnTv() {
|
||||
await PlayletApi.queuePlaylist(playlistId, title, videoCount);
|
||||
}
|
||||
|
||||
async function openPlaylistOnTv() {
|
||||
await PlayletApi.openPlaylist(playlistId);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/playlist?list=${playlistId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</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 aspect-video object-cover"
|
||||
loading="lazy"
|
||||
width="320"
|
||||
height="180"
|
||||
src={getThumbnailUrl()}
|
||||
alt={title}
|
||||
/>
|
||||
<div
|
||||
class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2"
|
||||
>
|
||||
{videoCount} videos
|
||||
</div>
|
||||
</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>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO:P2 a dialog for every video is very slow. Need to reuse the same one -->
|
||||
<dialog bind:this={modal} id="modal_{playlistId}" 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={playPlaylistOnTv}>
|
||||
Play on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={queuePlaylistOnTv}>
|
||||
Queue on {tvName}
|
||||
</button>
|
||||
<button class="btn m-2" on:click={openPlaylistOnTv}>
|
||||
Open 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,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import VideoListRow from "lib/Screens/Home/VideoListRow.svelte";
|
||||
import VideoListRow from "lib/VideoFeed/VideoListRow.svelte";
|
||||
import { homeLayoutFileStore } from "lib/Stores";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import { InvidiousApi } from "lib/Api/InvidiousApi";
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore, searchHistoryStore } from "lib/Stores";
|
||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||
import VideoCell from "lib/VideoFeed/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/VideoFeed/PlaylistCell.svelte";
|
||||
import ChannelCell from "lib/VideoFeed/ChannelCell.svelte";
|
||||
import SearchThinIcon from "assets/search-thin-icon.svg.svelte";
|
||||
import FiltersIcon from "assets/filters.svg.svelte";
|
||||
import ChannelCell from "./Home/ChannelCell.svelte";
|
||||
import SearchFilters from "./Search/SearchFilters.svelte";
|
||||
|
||||
export let visibility: boolean;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import ChannelThumbnail from "./ChannelThumbnail.svelte";
|
||||
|
||||
export let author: string | undefined = undefined;
|
||||
export let authorId: string | undefined = undefined;
|
||||
export let authorThumbnails: any[] | undefined = undefined;
|
||||
|
||||
export function show() {
|
||||
modal.showModal();
|
||||
}
|
||||
|
||||
export function close() {
|
||||
modal.close();
|
||||
}
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
async function openOnTv() {
|
||||
await PlayletApi.openChannel(authorId);
|
||||
}
|
||||
|
||||
function openInvidious() {
|
||||
let url = `${invidiousInstance}/channel/${authorId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={modal} class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<div class="flex flex-col items-center">
|
||||
<div class="w-32">
|
||||
<ChannelThumbnail bind:author bind:authorThumbnails />
|
||||
</div>
|
||||
<div class="m-4">{author}</div>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<div class="join join-vertical m-2">
|
||||
<button class="btn join-item hover:btn-accent" on:click={openOnTv}>
|
||||
Open on {tvName}
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>Close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import ChannelCastDialog from "./ChannelCastDialog.svelte";
|
||||
import ChannelThumbnail from "./ChannelThumbnail.svelte";
|
||||
|
||||
export let author: string | undefined = undefined;
|
||||
export let authorId: string | undefined = undefined;
|
||||
export let authorThumbnails: any[] | undefined = undefined;
|
||||
export let channelHandle: string | undefined = undefined;
|
||||
export let subCount: number | undefined = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
|
||||
let modal;
|
||||
</script>
|
||||
|
||||
<button class="w-60 p-2" on:click={modal.show()}>
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<ChannelThumbnail bind:author bind:authorThumbnails />
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-1 min-h-8">{author}</h3>
|
||||
<div>{subCount} subscribers</div>
|
||||
<div>{channelHandle || ""}</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<ChannelCastDialog
|
||||
bind:this={modal}
|
||||
bind:author
|
||||
bind:authorId
|
||||
bind:authorThumbnails
|
||||
/>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script lang="ts">
|
||||
export let author: string | undefined = undefined;
|
||||
export let authorThumbnails: any[] | undefined = undefined;
|
||||
|
||||
let thumbnailUrl;
|
||||
|
||||
$: {
|
||||
if (authorThumbnails && authorThumbnails.length > 0) {
|
||||
const authorThumbnail = authorThumbnails[authorThumbnails.length - 1];
|
||||
let url = authorThumbnail.url;
|
||||
if (url.startsWith("//")) {
|
||||
url = "https:" + url;
|
||||
}
|
||||
thumbnailUrl = url;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-44 rounded-full aspect-square object-cover"
|
||||
loading="lazy"
|
||||
width="176"
|
||||
height="176"
|
||||
src={thumbnailUrl}
|
||||
alt={author}
|
||||
/>
|
||||
</figure>
|
||||
@@ -0,0 +1,83 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import PlaylistThumbnail from "./PlaylistThumbnail.svelte";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let playlistId: string | undefined = undefined;
|
||||
export let videoCount: number | undefined = undefined;
|
||||
export let playlistThumbnail: string | undefined = undefined;
|
||||
export let videos: any[] | undefined = undefined;
|
||||
|
||||
export function show() {
|
||||
modal.showModal();
|
||||
}
|
||||
|
||||
export function close() {
|
||||
modal.close();
|
||||
}
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
async function playOnTv() {
|
||||
await PlayletApi.playPlaylist(playlistId, title, videoCount);
|
||||
}
|
||||
|
||||
async function queueOnTv() {
|
||||
await PlayletApi.queuePlaylist(playlistId, title, videoCount);
|
||||
}
|
||||
|
||||
async function openOnTv() {
|
||||
await PlayletApi.openPlaylist(playlistId);
|
||||
}
|
||||
|
||||
function openInvidious() {
|
||||
let url = `${invidiousInstance}/playlist?list=${playlistId}`;
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={modal} class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<div class="flex flex-col items-center">
|
||||
<div class="w-64">
|
||||
<PlaylistThumbnail
|
||||
bind:title
|
||||
bind:playlistThumbnail
|
||||
bind:videoCount
|
||||
bind:videos
|
||||
bind:invidiousInstance
|
||||
/>
|
||||
</div>
|
||||
<div class="m-4">{title}</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<div class="join join-vertical m-2">
|
||||
<button class="btn join-item hover:btn-accent" on:click={playOnTv}>
|
||||
Play on {tvName}
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
|
||||
Queue on {tvName}
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent" on:click={openOnTv}>
|
||||
Open on {tvName}
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>Close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import PlaylistCastDialog from "./PlaylistCastDialog.svelte";
|
||||
import PlaylistThumbnail from "./PlaylistThumbnail.svelte";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let author: string | undefined = undefined;
|
||||
export let playlistId: string | undefined = undefined;
|
||||
export let playlistThumbnail: string | undefined = undefined;
|
||||
export let videoCount: number | undefined = undefined;
|
||||
export let videos: any[] | undefined = undefined;
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
|
||||
let modal;
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
</script>
|
||||
|
||||
<button class="w-80 p-2" on:click={modal.show()}>
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<PlaylistThumbnail
|
||||
bind:title
|
||||
bind:playlistThumbnail
|
||||
bind:videoCount
|
||||
bind:videos
|
||||
bind:invidiousInstance
|
||||
/>
|
||||
<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>
|
||||
</div>
|
||||
</button>
|
||||
<PlaylistCastDialog
|
||||
bind:this={modal}
|
||||
bind:title
|
||||
bind:playlistId
|
||||
bind:playlistThumbnail
|
||||
bind:videoCount
|
||||
bind:videos
|
||||
/>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
export let title: string | undefined = undefined;
|
||||
export let videoCount: number | undefined = undefined;
|
||||
export let playlistThumbnail: string | undefined = undefined;
|
||||
export let videos: any[] | undefined = undefined;
|
||||
|
||||
export let invidiousInstance;
|
||||
|
||||
let thumbnailUrl;
|
||||
|
||||
$: {
|
||||
let url = "";
|
||||
if (playlistThumbnail) {
|
||||
url = playlistThumbnail;
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
} else if (videos && videos.length) {
|
||||
const video = videos[0];
|
||||
if (video.videoThumbnails) {
|
||||
const videoThumbnail =
|
||||
video.videoThumbnails.find(
|
||||
(thumbnail) => thumbnail.quality === "medium"
|
||||
) || video.videoThumbnails[0];
|
||||
url = videoThumbnail.url;
|
||||
}
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
}
|
||||
if (url === "") {
|
||||
url = `${invidiousInstance}/vi/-----------/mqdefault.jpg`;
|
||||
}
|
||||
thumbnailUrl = url;
|
||||
}
|
||||
</script>
|
||||
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-full rounded-box aspect-video object-cover"
|
||||
loading="lazy"
|
||||
width="320"
|
||||
height="180"
|
||||
src={thumbnailUrl}
|
||||
alt={title}
|
||||
/>
|
||||
<div
|
||||
class="absolute bottom-2 right-0 bg-black/70 text-white text-sm rounded-sm pt-1 pb-1 pr-2 pl-2"
|
||||
>
|
||||
{videoCount} videos
|
||||
</div>
|
||||
</figure>
|
||||
@@ -0,0 +1,94 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import VideoStartAt from "./VideoStartAt.svelte";
|
||||
import VideoThumbnail from "./VideoThumbnail.svelte";
|
||||
|
||||
export let videoId: string | undefined = undefined;
|
||||
export let title: string | undefined = undefined;
|
||||
export let videoThumbnails: any[] | undefined = undefined;
|
||||
export let author: string | undefined = undefined;
|
||||
export let lengthSeconds: number = undefined;
|
||||
export let liveNow: boolean = undefined;
|
||||
export let viewCount: number | undefined = undefined;
|
||||
|
||||
export let videoStartAtChecked;
|
||||
export let videoStartAtTimestamp;
|
||||
|
||||
export function show() {
|
||||
modal.showModal();
|
||||
}
|
||||
|
||||
export function close() {
|
||||
modal.close();
|
||||
videoStartAtChecked = false;
|
||||
videoStartAtTimestamp = 0;
|
||||
}
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
async function playOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.playVideo(videoId, timestamp, title, author);
|
||||
}
|
||||
|
||||
async function queueOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.queueVideo(videoId, timestamp, title, author);
|
||||
}
|
||||
|
||||
function openInvidious() {
|
||||
let url = `${invidiousInstance}/watch?v=${videoId}`;
|
||||
if (videoStartAtChecked && videoStartAtTimestamp) {
|
||||
url += `&t=${videoStartAtTimestamp}`;
|
||||
}
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={modal} class="modal">
|
||||
<form method="dialog" class="modal-box bg-base-100">
|
||||
<div class="flex flex-col items-center">
|
||||
<div class="w-64">
|
||||
<VideoThumbnail
|
||||
bind:title
|
||||
bind:videoThumbnails
|
||||
bind:liveNow
|
||||
bind:lengthSeconds
|
||||
bind:viewCount
|
||||
bind:invidiousInstance
|
||||
/>
|
||||
</div>
|
||||
<div class="m-4">{title}</div>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<VideoStartAt
|
||||
bind:checked={videoStartAtChecked}
|
||||
bind:timestamp={videoStartAtTimestamp}
|
||||
{lengthSeconds}
|
||||
/>
|
||||
<div class="join join-vertical m-2">
|
||||
<button class="btn join-item hover:btn-accent" on:click={playOnTv}>
|
||||
Play on {tvName}
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
|
||||
Queue on {tvName}
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
|
||||
Open in Invidious
|
||||
</button>
|
||||
<button class="btn join-item hover:btn-accent">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>Close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
+23
-111
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
import { playletStateStore } from "lib/Stores";
|
||||
import VideoStartAt from "lib/VideoStartAt.svelte";
|
||||
import VideoCastDialog from "./VideoCastDialog.svelte";
|
||||
import VideoThumbnail from "./VideoThumbnail.svelte";
|
||||
|
||||
export let title: string | undefined = undefined;
|
||||
export let videoId: string | undefined = undefined;
|
||||
@@ -38,13 +38,9 @@
|
||||
export let indexId: string = undefined;
|
||||
|
||||
let modal;
|
||||
let tvName = "Roku TV";
|
||||
let invidiousInstance;
|
||||
let videoStartAtChecked;
|
||||
let videoStartAtTimestamp;
|
||||
|
||||
playletStateStore.subscribe((value) => {
|
||||
tvName = value?.device?.friendly_name ?? "Roku TV";
|
||||
invidiousInstance = value?.invidious?.current_instance;
|
||||
});
|
||||
|
||||
@@ -110,20 +106,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function getThumbnailUrl(quality: string = "medium") {
|
||||
if (!videoThumbnails || videoThumbnails.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const videoThumbnail =
|
||||
videoThumbnails.find((thumbnail) => thumbnail.quality === quality) ||
|
||||
videoThumbnails[0];
|
||||
let url = videoThumbnail.url;
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function formatViewCount(viewCount) {
|
||||
if (isNaN(viewCount)) {
|
||||
return "";
|
||||
@@ -153,76 +135,18 @@
|
||||
X = X / 10;
|
||||
return X;
|
||||
}
|
||||
|
||||
function getFormattedTime(length) {
|
||||
const hours = Math.floor(length / 3600);
|
||||
const minutes = Math.floor((length / 60) % 60);
|
||||
const seconds = length % 60;
|
||||
|
||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||
const minutesString =
|
||||
minutes < 10 && hours > 0 ? `0${minutes}` : minutes.toString();
|
||||
|
||||
let formattedTime = minutesString + ":" + secondsString;
|
||||
|
||||
if (hours > 0) {
|
||||
formattedTime = hours.toString() + ":" + formattedTime;
|
||||
}
|
||||
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
function isVideoLive() {
|
||||
if (liveNow) {
|
||||
return true;
|
||||
}
|
||||
return lengthSeconds === 0 && viewCount === 0;
|
||||
}
|
||||
|
||||
async function playVideoOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.playVideo(videoId, timestamp, title, author);
|
||||
}
|
||||
|
||||
async function queueVideoOnTv() {
|
||||
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
|
||||
await PlayletApi.queueVideo(videoId, timestamp, title, author);
|
||||
}
|
||||
|
||||
function openInvidiousInNewTab() {
|
||||
let url = `${invidiousInstance}/watch?v=${videoId}`;
|
||||
if (videoStartAtChecked && videoStartAtTimestamp) {
|
||||
url += `&t=${videoStartAtTimestamp}`;
|
||||
}
|
||||
window.open(url);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="w-80 p-2" on:click={modal.showModal()}>
|
||||
<button class="w-80 p-2" on:click={modal.show()}>
|
||||
<div class="card card-compact bg-base-100 shadow-xl border border-neutral">
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-full rounded-box aspect-video object-cover"
|
||||
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}
|
||||
</figure>
|
||||
<VideoThumbnail
|
||||
bind:title
|
||||
bind:videoThumbnails
|
||||
bind:liveNow
|
||||
bind:lengthSeconds
|
||||
bind:viewCount
|
||||
bind:invidiousInstance
|
||||
/>
|
||||
<div class="card-body">
|
||||
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
|
||||
<div class="font-semibold">{author}</div>
|
||||
@@ -230,27 +154,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<!-- TODO:P2 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">
|
||||
<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={queueVideoOnTv}
|
||||
>Queue 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>
|
||||
<VideoCastDialog
|
||||
bind:this={modal}
|
||||
bind:videoId
|
||||
bind:title
|
||||
bind:author
|
||||
bind:lengthSeconds
|
||||
bind:videoThumbnails
|
||||
bind:liveNow
|
||||
bind:viewCount
|
||||
videoStartAtChecked={false}
|
||||
videoStartAtTimestamp={0}
|
||||
/>
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { InvidiousApi } from "lib/Api/InvidiousApi";
|
||||
import { invidiousVideoApiStore, playletStateStore } from "lib/Stores";
|
||||
import VideoCell from "lib/Screens/Home/VideoCell.svelte";
|
||||
import PlaylistCell from "lib/Screens/Home/PlaylistCell.svelte";
|
||||
import VideoCell from "./VideoCell.svelte";
|
||||
import PlaylistCell from "./PlaylistCell.svelte";
|
||||
import ChannelCell from "./ChannelCell.svelte";
|
||||
|
||||
// TODO:P1 figure out why some uncached feeds (e.g. channels/ucid/videos) get hit twice
|
||||
File renamed without changes.
@@ -0,0 +1,73 @@
|
||||
<script lang="ts">
|
||||
export let title: string | undefined = undefined;
|
||||
export let videoThumbnails: any[] | undefined = undefined;
|
||||
export let liveNow: boolean = undefined;
|
||||
export let lengthSeconds: number = undefined;
|
||||
export let viewCount: number | undefined = undefined;
|
||||
|
||||
export let invidiousInstance;
|
||||
|
||||
let thumbnailUrl;
|
||||
|
||||
$: {
|
||||
if (videoThumbnails && videoThumbnails.length > 0) {
|
||||
const videoThumbnail =
|
||||
videoThumbnails.find((thumbnail) => thumbnail.quality === "medium") ||
|
||||
videoThumbnails[0];
|
||||
let url = videoThumbnail.url;
|
||||
if (url.startsWith("/") && invidiousInstance) {
|
||||
url = invidiousInstance + url;
|
||||
}
|
||||
thumbnailUrl = url;
|
||||
}
|
||||
}
|
||||
|
||||
function getFormattedTime(length) {
|
||||
const hours = Math.floor(length / 3600);
|
||||
const minutes = Math.floor((length / 60) % 60);
|
||||
const seconds = length % 60;
|
||||
|
||||
const secondsString = seconds < 10 ? `0${seconds}` : seconds.toString();
|
||||
const minutesString =
|
||||
minutes < 10 && hours > 0 ? `0${minutes}` : minutes.toString();
|
||||
|
||||
let formattedTime = minutesString + ":" + secondsString;
|
||||
|
||||
if (hours > 0) {
|
||||
formattedTime = hours.toString() + ":" + formattedTime;
|
||||
}
|
||||
|
||||
return formattedTime;
|
||||
}
|
||||
|
||||
function isVideoLive() {
|
||||
if (liveNow) {
|
||||
return true;
|
||||
}
|
||||
return lengthSeconds === 0 && viewCount === 0;
|
||||
}
|
||||
</script>
|
||||
|
||||
<figure class="relative">
|
||||
<img
|
||||
class="w-full rounded-box aspect-video object-cover"
|
||||
loading="lazy"
|
||||
width="320"
|
||||
height="180"
|
||||
src={thumbnailUrl}
|
||||
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}
|
||||
</figure>
|
||||
Reference in new issue
Block a user