Add --current-song to tauon-controls.
This commit is contained in:
parent
be914f08a0
commit
3f69307b8b
|
@ -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" \
|
||||
"$@"
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue