mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 15:02:42 +01:00
music source and client for subsonic
test fixture setup for navidrome
This commit is contained in:
44
docker/library-manager/scripts/music-download.ts
Executable file
44
docker/library-manager/scripts/music-download.ts
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env -S deno --allow-all
|
||||
import * as path from "jsr:@std/path@1.1.2";
|
||||
import { MUSIC_DIR } from "./util/env.ts";
|
||||
import { SubsonicClient } from "./util/subsonic.ts";
|
||||
|
||||
await new Deno.Command("rm", { args: ["-rf", path.join(MUSIC_DIR, "*")] })
|
||||
.output();
|
||||
|
||||
const client = new SubsonicClient(
|
||||
"http://demo.subsonic.org",
|
||||
"guest1",
|
||||
"guest",
|
||||
);
|
||||
|
||||
for (const id of ["197", "199", "321"]) {
|
||||
const res = await client.get("download", { id });
|
||||
|
||||
let filename = res.headers.get("Content-Disposition")
|
||||
?.split(";")[1];
|
||||
filename = (filename?.includes("*=")
|
||||
? decodeURIComponent(filename.split("''")[1])
|
||||
: filename?.split("=")[1]) ?? `${id}.zip`;
|
||||
|
||||
console.log("downloading album:", filename);
|
||||
const downloadPath = path.join(MUSIC_DIR, filename);
|
||||
|
||||
const file = await Deno.open(downloadPath, {
|
||||
write: true,
|
||||
create: true,
|
||||
});
|
||||
await res.body?.pipeTo(file.writable);
|
||||
|
||||
await new Deno.Command("unzip", {
|
||||
args: [
|
||||
downloadPath,
|
||||
"-d",
|
||||
path.join(MUSIC_DIR, filename.split(".")[0]),
|
||||
],
|
||||
}).output();
|
||||
|
||||
await Deno.remove(downloadPath);
|
||||
}
|
||||
|
||||
console.log("music-download complete");
|
||||
18
docker/library-manager/scripts/setup-servers.ts
Executable file
18
docker/library-manager/scripts/setup-servers.ts
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env -S deno --allow-all
|
||||
|
||||
async function setupNavidrome() {
|
||||
console.log("setting up navidrome...");
|
||||
|
||||
await fetch("http://navidrome:4533/auth/createAdmin", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
username: "admin",
|
||||
password: "password",
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
await setupNavidrome();
|
||||
|
||||
console.log("setup-servers complete");
|
||||
1
docker/library-manager/scripts/util/env.ts
Normal file
1
docker/library-manager/scripts/util/env.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const MUSIC_DIR = Deno.env.get("MUSIC_DIR") ?? "/music";
|
||||
24
docker/library-manager/scripts/util/subsonic.ts
Normal file
24
docker/library-manager/scripts/util/subsonic.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export class SubsonicClient {
|
||||
constructor(
|
||||
readonly baseUrl: string,
|
||||
readonly username: string,
|
||||
readonly password: string,
|
||||
) {}
|
||||
|
||||
get(method: string, params?: Record<string, string>) {
|
||||
const url = new URL(`rest/${method}.view`, this.baseUrl);
|
||||
|
||||
url.searchParams.set("u", this.username);
|
||||
url.searchParams.set("p", this.password);
|
||||
url.searchParams.set("v", "1.13.0");
|
||||
url.searchParams.set("c", "subtracks-test-fixture");
|
||||
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) =>
|
||||
url.searchParams.append(key, value)
|
||||
);
|
||||
}
|
||||
|
||||
return fetch(url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user