diff --git a/.bauke/bin/tauon-controls b/.bauke/bin/tauon-controls index 3382e50..bec8088 100755 --- a/.bauke/bin/tauon-controls +++ b/.bauke/bin/tauon-controls @@ -2,6 +2,8 @@ deno run \ --allow-net="127.0.0.1:7813,127.0.0.1:7814" \ + --allow-read \ --allow-run="notify-send" \ + --allow-write \ "$BAUKE_DIR/scripts/tauon-controls.ts" \ "$@" diff --git a/.bauke/scripts/tauon-controls.ts b/.bauke/scripts/tauon-controls.ts index a8a0ce1..71bf54b 100644 --- a/.bauke/scripts/tauon-controls.ts +++ b/.bauke/scripts/tauon-controls.ts @@ -1,4 +1,4 @@ -import { Command } from "./dependencies.ts"; +import { Command, nodeFs } from "./dependencies.ts"; const hiddenApi = "http://127.0.0.1:7813"; const remoteApi = "http://127.0.0.1:7814/api1"; @@ -16,6 +16,7 @@ async function main(): Promise { "--volume ", "Change the volume by a relative amount.", ) + .option("--write-image", "Write the album cover image to a temporary file.") .parse(Deno.args); if (options.currentSong) { @@ -57,11 +58,30 @@ async function main(): Promise { console.log(formattedString); } + + if (options.writeImage) { + const status = await getStatus(); + const path = `/tmp/tauon-cover-${status.id}.jpg`; + if (nodeFs.existsSync(path)) { + console.log(path); + return; + } + + const image = await fetch(`${remoteApi}/pic/medium/${status.id}`); + if (image.body === null) { + return; + } + + const imageBuffer = new Uint8Array(await image.arrayBuffer()); + await Deno.writeFile(path, imageBuffer); + console.log(path); + } } type Status = { album: string; artist: string; + id: number; progress: number; title: string; track: {