155 lines
4.5 KiB
Svelte
155 lines
4.5 KiB
Svelte
<script lang="ts">
|
|
import { PlayletApi } from "lib/Api/PlayletApi";
|
|
import { playletStateStore, translate } 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 videoCountText: string | undefined = undefined;
|
|
export let playlistThumbnail: string | undefined = undefined;
|
|
export let videos: any[] | undefined = undefined;
|
|
// videoId is Mix continuation (playlistId starts with "RD")
|
|
export let videoId: string | undefined = undefined;
|
|
|
|
export function show() {
|
|
modal.showModal();
|
|
}
|
|
|
|
export function close() {
|
|
modal.close();
|
|
}
|
|
|
|
let modal;
|
|
let tvName = "Roku TV";
|
|
let invidiousInstance;
|
|
let invidiousInstanceForRedirect;
|
|
|
|
playletStateStore.subscribe((value) => {
|
|
tvName = value?.device?.friendly_name ?? "Roku TV";
|
|
let instance = value?.invidious?.invidious_instance || "";
|
|
invidiousInstance = instance;
|
|
if (!instance) {
|
|
instance = "https://redirect.invidious.io";
|
|
}
|
|
invidiousInstanceForRedirect = instance;
|
|
});
|
|
|
|
async function playOnTv() {
|
|
await PlayletApi.playPlaylist(getPlaylistInfo());
|
|
}
|
|
|
|
async function queueOnTv() {
|
|
await PlayletApi.queuePlaylist(getPlaylistInfo());
|
|
}
|
|
|
|
async function openOnTv() {
|
|
const continuationVideoId =
|
|
playlistId.startsWith("RD") && videoId ? videoId : undefined;
|
|
await PlayletApi.openPlaylist(playlistId, continuationVideoId);
|
|
}
|
|
|
|
function openInvidious() {
|
|
const continuationVideoId =
|
|
playlistId.startsWith("RD") && videoId ? videoId : undefined;
|
|
let url = `${invidiousInstanceForRedirect}/mix?list=${playlistId}`;
|
|
if (continuationVideoId) {
|
|
url += `&continuation=${continuationVideoId}`;
|
|
}
|
|
window.open(url);
|
|
}
|
|
|
|
function openYouTube() {
|
|
let url = "https://www.youtube.com";
|
|
if (videoId && playlistId.startsWith("RD")) {
|
|
url += `/watch?v=${videoId}&list=${playlistId}`;
|
|
} else {
|
|
url += `/playlist?list=${playlistId}`;
|
|
}
|
|
window.open(url);
|
|
}
|
|
|
|
function getPlaylistInfo() {
|
|
return {
|
|
type: "playlist",
|
|
playlistId,
|
|
title,
|
|
playlistThumbnail: getPlaylistThumbnail(),
|
|
videoCount,
|
|
videoCountText,
|
|
videos,
|
|
videoId,
|
|
};
|
|
}
|
|
|
|
function getPlaylistThumbnail() {
|
|
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 = `https://i.ytimg.com/vi/-----------/mqdefault.jpg`;
|
|
}
|
|
return 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:videoCountText
|
|
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}>
|
|
{$translate("Play on %1").replace("%1", tvName)}
|
|
</button>
|
|
<button class="btn join-item hover:btn-accent" on:click={queueOnTv}>
|
|
{$translate("Queue on %1").replace("%1", tvName)}
|
|
</button>
|
|
<button class="btn join-item hover:btn-accent" on:click={openOnTv}>
|
|
{$translate("Open on %1").replace("%1", tvName)}
|
|
</button>
|
|
<button class="btn join-item hover:btn-accent" on:click={openInvidious}>
|
|
{$translate("Open in Invidious")}
|
|
</button>
|
|
<button class="btn join-item hover:btn-accent" on:click={openYouTube}>
|
|
{$translate("Open in YouTube")}
|
|
</button>
|
|
<button class="btn join-item hover:btn-accent"
|
|
>{$translate("Cancel")}</button
|
|
>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<form method="dialog" class="modal-backdrop">
|
|
<button>{$translate("Close")}</button>
|
|
</form>
|
|
</dialog>
|