Play queue notification (#186)

* Play queue notification

* Lint fix

* change binding

* Add notification preference

* Lint fix

* changelog

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2023-11-04 20:23:02 -04:00
1 parent 777db66bda
commit 4233f30dec
14 files changed
+283 -63

No files matched your search

+19 -47
View File
@@ -43,73 +43,45 @@ export class PlayletApi {
await fetch(`${PlayletApi.host()}/invidious/logout`);
}
static async playVideo(videoId, timestamp, title, author) {
if (!videoId) {
static async playVideo(args) {
if (!args.videoId) {
return;
}
const args = { videoId };
if (timestamp !== undefined) {
if (typeof timestamp === "string") {
timestamp = parseInt(timestamp);
if (args.timestamp !== undefined) {
if (typeof args.timestamp === "string") {
args.timestamp = parseInt(args.timestamp);
}
args["timestamp"] = timestamp;
}
if (title !== undefined) {
args["title"] = title;
}
if (author !== undefined) {
args["author"] = author;
await PlayletApi.postJson(`${PlayletApi.host()}/api/queue/play`, args);
}
static async playPlaylist(args) {
if (!args.playlistId) {
return;
}
await PlayletApi.postJson(`${PlayletApi.host()}/api/queue/play`, args);
}
static async playPlaylist(playlistId, title, videoCount) {
if (!playlistId) {
static async queueVideo(args) {
if (!args.videoId) {
return;
}
const args = { playlistId };
if (title !== undefined) {
args["title"] = title;
}
if (videoCount !== undefined) {
args["author"] = videoCount;
}
await PlayletApi.postJson(`${PlayletApi.host()}/api/queue/play`, args);
}
static async queueVideo(videoId, timestamp, title, author) {
if (!videoId) {
return;
}
const args = { videoId };
if (timestamp !== undefined) {
if (typeof timestamp === "string") {
timestamp = parseInt(timestamp);
if (args.timestamp !== undefined) {
if (typeof args.timestamp === "string") {
args.timestamp = parseInt(args.timestamp);
}
args["timestamp"] = timestamp;
}
if (title !== undefined) {
args["title"] = title;
}
if (author !== undefined) {
args["author"] = author;
}
const response = await PlayletApi.postJson(`${PlayletApi.host()}/api/queue`, args);
return await response.json();
}
static async queuePlaylist(playlistId, title, videoCount) {
if (!playlistId) {
static async queuePlaylist(args) {
if (!args.playlistId) {
return;
}
const args = { playlistId };
if (title !== undefined) {
args["title"] = title;
}
if (videoCount !== undefined) {
args["author"] = videoCount;
}
const response = await PlayletApi.postJson(`${PlayletApi.host()}/api/queue`, args);
return await response.json();
}
@@ -27,11 +27,11 @@
});
async function playOnTv() {
await PlayletApi.playPlaylist(playlistId, title, videoCount);
await PlayletApi.playPlaylist(getPlaylistInfo());
}
async function queueOnTv() {
await PlayletApi.queuePlaylist(playlistId, title, videoCount);
await PlayletApi.queuePlaylist(getPlaylistInfo());
}
async function openOnTv() {
@@ -42,6 +42,43 @@
let url = `${invidiousInstance}/playlist?list=${playlistId}`;
window.open(url);
}
function getPlaylistInfo() {
return {
type: "playlist",
playlistId,
title,
playlistThumbnail: getPlaylistThumbnail(),
videoCount,
videos,
};
}
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 = `${invidiousInstance}/vi/-----------/mqdefault.jpg`;
}
return url;
}
</script>
<dialog bind:this={modal} class="modal">
@@ -35,13 +35,11 @@
});
async function playOnTv() {
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
await PlayletApi.playVideo(videoId, timestamp, title, author);
await PlayletApi.playVideo(getVideoInfo());
}
async function queueOnTv() {
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
await PlayletApi.queueVideo(videoId, timestamp, title, author);
await PlayletApi.queueVideo(getVideoInfo());
}
function openInvidious() {
@@ -51,6 +49,36 @@
}
window.open(url);
}
function getVideoInfo() {
const timestamp = videoStartAtChecked ? videoStartAtTimestamp : undefined;
return {
type: "video",
videoId,
title,
videoThumbnails: getVideoThumbnails(),
author,
lengthSeconds,
liveNow,
viewCount,
timestamp,
};
}
function getVideoThumbnails() {
if (!invidiousInstance || !videoThumbnails || !videoThumbnails.length) {
return videoThumbnails;
}
return videoThumbnails.map((thumbnail) => {
let url = thumbnail.url;
if (url.startsWith("/")) {
url = invidiousInstance + url;
thumbnail.url = url;
}
return thumbnail;
});
}
</script>
<dialog bind:this={modal} class="modal">