1
Fork 0

Add a i3status-rust block for the currently playing song in Tauon.

This commit is contained in:
Bauke 2024-02-28 13:15:26 +01:00
parent 0a32e075d4
commit 1d291bd39f
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import { Command } from "./dependencies.ts"; import { Command } from "./dependencies.ts";
import { pathExists, runCommand } from "./utilities.ts"; import { pathExists } from "./utilities.ts";
const hiddenApi = "http://127.0.0.1:7813"; const hiddenApi = "http://127.0.0.1:7813";
const remoteApi = "http://127.0.0.1:7814/api1"; const remoteApi = "http://127.0.0.1:7814/api1";
@ -8,7 +8,7 @@ async function main(): Promise<void> {
const { options } = await new Command() const { options } = await new Command()
.name("tauon-controls") .name("tauon-controls")
.description("Small remote control CLI for Tauon Music Box!") .description("Small remote control CLI for Tauon Music Box!")
.option("--current-song", "Send a notification with the current song.") .option("--current-song", "Get the currently playing song.")
.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.")
@ -21,7 +21,7 @@ async function main(): Promise<void> {
.parse(Deno.args); .parse(Deno.args);
if (options.currentSong) { if (options.currentSong) {
await notifyCurrentSong(); await getCurrentSong();
} }
if (options.nextSong) { if (options.nextSong) {
@ -85,6 +85,7 @@ type Status = {
artist: string; artist: string;
id: number; id: number;
progress: number; progress: number;
status: "playing" | "paused";
title: string; title: string;
track: { track: {
duration: number; duration: number;
@ -96,12 +97,14 @@ async function getStatus(): Promise<Status> {
return await (await fetch(`${remoteApi}/status`)).json(); return await (await fetch(`${remoteApi}/status`)).json();
} }
/** Run a `notify-send` with the current song's artist and title. */ /** Print the current song's artist and title. */
async function notifyCurrentSong(): Promise<void> { async function getCurrentSong(): Promise<void> {
const status = await getStatus(); const status = await getStatus();
await runCommand("notify-send", { if (status.status === "paused") {
args: [status.title, status.artist], return;
}); }
console.log(`${status.artist} - ${status.title}`);
} }
if (import.meta.main) { if (import.meta.main) {

View File

@ -1,6 +1,13 @@
[icons] [icons]
icons = "emoji" icons = "emoji"
[[block]]
block = "custom"
command = "tauon-controls --current-song"
format = "^icon_music_play $text.pango-str()"
interval = 15
hide_when_empty = true
[[block]] [[block]]
block = "custom" block = "custom"
command = "miniflux-unread-entries" command = "miniflux-unread-entries"