1
Fork 0

Add --current-song to tauon-controls.

This commit is contained in:
Bauke 2022-12-12 17:34:02 +01:00
parent be914f08a0
commit 3f69307b8b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 22 additions and 0 deletions

View File

@ -2,5 +2,6 @@
deno run \
--allow-net="127.0.0.1:7813,127.0.0.1:7814" \
--allow-run="notify-send" \
"$BAUKE_DIR/scripts/tauon-controls.ts" \
"$@"

View File

@ -7,6 +7,7 @@ async function main(): Promise<void> {
const { options } = await new Command()
.name("tauon-controls")
.description("Small remote control CLI for Tauon Music Box!")
.option("--current-song", "Send a notification with the current song.")
.option("--next-song", "Play the next song.")
.option("--play-pause", "Toggle play or pause.")
.option("--previous-song", "Play the previous song.")
@ -16,6 +17,10 @@ async function main(): Promise<void> {
)
.parse(Deno.args);
if (options.currentSong) {
await notifyCurrentSong();
}
if (options.nextSong) {
await fetch(`${remoteApi}/next`);
}
@ -33,6 +38,22 @@ async function main(): Promise<void> {
}
}
type Status = {
artist?: string;
title?: string;
};
async function notifyCurrentSong(): Promise<void> {
const status: Status = await (await fetch(`${remoteApi}/status`)).json();
if (status.artist === undefined || status.title === undefined) {
return;
}
await Deno.run({
cmd: ["notify-send", status.title, status.artist],
}).status();
}
if (import.meta.main) {
void main();
}