This commit is contained in:
2025-11-19 22:01:25 +02:00
parent afef35b6f6
commit 3a7686713f
16 changed files with 276 additions and 212 deletions

View File

@@ -50,60 +50,61 @@ export type CiderNowPlaying = {
[key: string]: any;
};
// cachedAlbumArt = /tmp/.ocbwoy3-ciderv2lib-md5(isrc+albumName).jpg
export type albumStuffF = {
artist: string,
album: string,
song: string,
artUrl?: string
}
artist: string;
album: string;
song: string;
artUrl?: string;
};
export const albumRewriteRegexes: { a: RegExp, b: string | false }[] = [
export const albumRewriteRegexes: { a: RegExp; b: string | false }[] = [
{
a: / \(Original( (Video )?Game)? Soundtrack.*\)$/i,
b: ""
b: "",
},
{
a: / - Single$/i,
b: false
b: false,
},
{
a: / Soundtrack$/i,
b: ""
b: "",
},
{
a: /^(DELTARUNE|Deltarune) (chapter|chapters) /i,
b: "Deltarune $2 "
b: "Deltarune $2 ",
},
{
a: / - EP$/i,
b: ""
b: "",
},
{
a: /^regretevator$/i,
b: false
b: false,
},
]
];
export function doRewritesRn(t: string) {
let m = t;
for (const x of albumRewriteRegexes) {
if (x.a.test(m)) {
if (x.b === false) return "";
m = m.replace(x.a,x.b);
m = m.replace(x.a, x.b);
}
}
return m;
}
export async function fetchAlbumStuff(): Promise<albumStuffF> {
const d = await fetch("http://localhost:10767/api/v1/playback/now-playing?token=z");
const d = await fetch(
"http://localhost:10767/api/v1/playback/now-playing?token=z",
);
// console.log(d.status, d.statusText, await d.text())
const { info }: CiderNowPlaying = await d.json();
const special = MD5.hash(info.isrc + info.albumName, "hex");
const path = `/tmp/.ocbwoy3-ciderv2lib-md5-${special}.jpg`
const path = `/tmp/.ocbwoy3-ciderv2lib-md5-${special}.jpg`;
// console.log(existsSync(path), `hyprctl dispatch exec ${`wget -q --unlink -O ${path} ${info.artwork.url}`}`);
@@ -116,15 +117,15 @@ export async function fetchAlbumStuff(): Promise<albumStuffF> {
writeFileSync(path, data);
// writeFileSync(path,await ct.body?.pipeTo)
} catch {
rmSync(path)
rmSync(path);
}
}
return {
artist: info.artistName,
album: doRewritesRn(info.albumName),
song: info.name,
artUrl: existsSync(path) ? path : undefined
}
artUrl: existsSync(path) ? path : undefined,
};
}
// await fetchAlbumStuff();