Compare commits
No commits in common. "9c900c919e991b41d9000f5102c0094f64d417ef" and "e851405da4054661adcbc818088f2a48a1425210" have entirely different histories.
9c900c919e
...
e851405da4
|
@ -13,7 +13,6 @@
|
||||||
chromium
|
chromium
|
||||||
clang
|
clang
|
||||||
clonehero
|
clonehero
|
||||||
conky
|
|
||||||
delta
|
delta
|
||||||
deno
|
deno
|
||||||
direnv
|
direnv
|
||||||
|
|
|
@ -11,7 +11,6 @@ async function main(): Promise<void> {
|
||||||
.option("--next-song", "Play the next song.")
|
.option("--next-song", "Play the next song.")
|
||||||
.option("--play-pause", "Toggle play or pause.")
|
.option("--play-pause", "Toggle play or pause.")
|
||||||
.option("--previous-song", "Play the previous song.")
|
.option("--previous-song", "Play the previous song.")
|
||||||
.option("--print <print:string>", "Print data from the current song.")
|
|
||||||
.option(
|
.option(
|
||||||
"--volume <volume:number>",
|
"--volume <volume:number>",
|
||||||
"Change the volume by a relative amount",
|
"Change the volume by a relative amount",
|
||||||
|
@ -37,44 +36,19 @@ async function main(): Promise<void> {
|
||||||
if (options.volume !== undefined) {
|
if (options.volume !== undefined) {
|
||||||
await fetch(`${remoteApi}/setvolumerel/${options.volume}`);
|
await fetch(`${remoteApi}/setvolumerel/${options.volume}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.print !== undefined) {
|
|
||||||
const status = await getStatus();
|
|
||||||
const progressPercentage = ((status.progress / status.track.duration) * 100)
|
|
||||||
.toFixed(2);
|
|
||||||
const markersAndReplacements = [
|
|
||||||
["album", status.album],
|
|
||||||
["artist", status.artist],
|
|
||||||
["title", status.title],
|
|
||||||
["progress", progressPercentage],
|
|
||||||
];
|
|
||||||
|
|
||||||
let formattedString = options.print;
|
|
||||||
for (const [marker, replacement] of markersAndReplacements) {
|
|
||||||
const regex = new RegExp(`<${marker}>`, "g");
|
|
||||||
formattedString = formattedString.replace(regex, replacement);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(formattedString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Status = {
|
type Status = {
|
||||||
album: string;
|
artist?: string;
|
||||||
artist: string;
|
title?: string;
|
||||||
progress: number;
|
|
||||||
title: string;
|
|
||||||
track: {
|
|
||||||
duration: number;
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
async function getStatus(): Promise<Status> {
|
|
||||||
return await (await fetch(`${remoteApi}/status`)).json();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function notifyCurrentSong(): Promise<void> {
|
async function notifyCurrentSong(): Promise<void> {
|
||||||
const status = await getStatus();
|
const status: Status = await (await fetch(`${remoteApi}/status`)).json();
|
||||||
|
if (status.artist === undefined || status.title === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await Deno.run({
|
await Deno.run({
|
||||||
cmd: ["notify-send", status.title, status.artist],
|
cmd: ["notify-send", status.title, status.artist],
|
||||||
}).status();
|
}).status();
|
||||||
|
|
Loading…
Reference in New Issue