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();

View File

@@ -10,7 +10,9 @@ const API_URL = "https://api.e-z.host/files";
*/
export async function UploadToEZ(content: Buffer): Promise<string> {
if (!process.env.EZ_API_KEY) {
throw new Error(`Missing EZ_API_KEY, make sure you're loading the env from ${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env!`)
throw new Error(
`Missing EZ_API_KEY, make sure you're loading the env from ${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env!`,
);
}
if (!(content[0] === 0x89 && content[1] === 0x50 && content[2] === 0x4e)) {
@@ -21,7 +23,7 @@ export async function UploadToEZ(content: Buffer): Promise<string> {
form.append(
"file",
new Blob([content as any], { type: "image/png" }),
"screenshot.png"
"screenshot.png",
);
const res = await fetch(API_URL, {
@@ -34,7 +36,7 @@ export async function UploadToEZ(content: Buffer): Promise<string> {
if (!res.ok) {
throw new Error(
`Upload failed with status ${res.status}: ${await res.text()}`
`Upload failed with status ${res.status}: ${await res.text()}`,
);
}

View File

@@ -24,26 +24,28 @@ export type RegretevatorState = DeadUnknownState | InElevatorState;
export function getRegretevatorState(): null | RegretevatorState {
if (!existsSync(STATE_FILE_PATH)) return null;
try {
const {text, tooltip}: { text: string, tooltip: string } = JSON.parse(readFileSync(STATE_FILE_PATH).toString('utf-8'))
const { text, tooltip }: { text: string; tooltip: string } = JSON.parse(
readFileSync(STATE_FILE_PATH).toString("utf-8"),
);
if (/^On Floor ([0-9]+)$/.test(tooltip)) {
const floorNum = tooltip.match(/^On Floor ([0-9]+)$/)![1]
const floorNum = tooltip.match(/^On Floor ([0-9]+)$/)![1];
return {
floor: Number(floorNum),
state: "INGAME",
isGoingUp: false
}
isGoingUp: false,
};
}
if (/^Floor ([0-9]+)/.test(tooltip)) {
const floorNum = tooltip.match(/^Floor ([0-9]+)/)![1]
const floorNum = tooltip.match(/^Floor ([0-9]+)/)![1];
return {
floor: Number(floorNum),
state: "INGAME",
isGoingUp: true
}
isGoingUp: true,
};
}
return {
state: "UNKNOWN"
}
state: "UNKNOWN",
};
} catch {}
return null;
}