1
Fork 0

Add a write image option.

This commit is contained in:
Bauke 2023-04-26 11:52:55 +02:00
parent 2f4172122c
commit 3a6ae88440
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 23 additions and 1 deletions

View File

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

View File

@ -1,4 +1,4 @@
import { Command } from "./dependencies.ts"; import { Command, nodeFs } from "./dependencies.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";
@ -16,6 +16,7 @@ async function main(): Promise<void> {
"--volume <volume:number>", "--volume <volume:number>",
"Change the volume by a relative amount.", "Change the volume by a relative amount.",
) )
.option("--write-image", "Write the album cover image to a temporary file.")
.parse(Deno.args); .parse(Deno.args);
if (options.currentSong) { if (options.currentSong) {
@ -57,11 +58,30 @@ async function main(): Promise<void> {
console.log(formattedString); 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 = { type Status = {
album: string; album: string;
artist: string; artist: string;
id: number;
progress: number; progress: number;
title: string; title: string;
track: { track: {