rework tidal api to be nicer now
This commit is contained in:
44
package-lock.json
generated
44
package-lock.json
generated
@@ -25,8 +25,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dpu/shared": {
|
"node_modules/@dpu/shared": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.1",
|
||||||
"resolved": "git+https://git.dariusbag.dev/DarDarBinks/dpu-shared.git#862401fa9b2a358b2338490f4c7c6f125d11675e",
|
"resolved": "git+https://git.dariusbag.dev/DarDarBinks/dpu-shared.git#b55e1dd0a651c4cc3a7aabd8a44d49eb654f0189",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
@@ -709,9 +709,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@isaacs/brace-expansion": {
|
"node_modules/@isaacs/brace-expansion": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz",
|
||||||
"integrity": "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==",
|
"integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@isaacs/balanced-match": "^4.0.1"
|
"@isaacs/balanced-match": "^4.0.1"
|
||||||
@@ -736,9 +736,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "24.10.9",
|
"version": "24.10.10",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.9.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.10.tgz",
|
||||||
"integrity": "sha512-ne4A0IpG3+2ETuREInjPNhUGis1SFjv1d5asp8MzEAGtOZeTeHVDOYqOgqfhvseqg/iXty2hjBf1zAOb7RNiNw==",
|
"integrity": "sha512-+0/4J266CBGPUq/ELg7QUHhN25WYjE0wYTPSQJn1xeu8DOlIOPxXxrNGiLmfAWl7HMMgWFWXpt9IDjMWrF5Iow==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1108,9 +1108,9 @@
|
|||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/fastify": {
|
"node_modules/fastify": {
|
||||||
"version": "5.7.2",
|
"version": "5.7.4",
|
||||||
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.7.4.tgz",
|
||||||
"integrity": "sha512-dBJolW+hm6N/yJVf6J5E1BxOBNkuXNl405nrfeR8SpvGWG3aCC2XDHyiFBdow8Win1kj7sjawQc257JlYY6M/A==",
|
"integrity": "sha512-e6l5NsRdaEP8rdD8VR0ErJASeyaRbzXYpmkrpr2SuvuMq6Si3lvsaVy5C+7gLanEkvjpMDzBXWE5HPeb/hgTxA==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "github",
|
"type": "github",
|
||||||
@@ -1309,9 +1309,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/get-tsconfig": {
|
"node_modules/get-tsconfig": {
|
||||||
"version": "4.13.0",
|
"version": "4.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.1.tgz",
|
||||||
"integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==",
|
"integrity": "sha512-EoY1N2xCn44xU6750Sx7OjOIT59FkmstNc3X6y5xpz7D5cBtZRe/3pSlTkDJgqsOk3WwZPkWfonhhUJfttQo3w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1322,12 +1322,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/glob": {
|
"node_modules/glob": {
|
||||||
"version": "13.0.0",
|
"version": "13.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/glob/-/glob-13.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/glob/-/glob-13.0.1.tgz",
|
||||||
"integrity": "sha512-tvZgpqk6fz4BaNZ66ZsRaZnbHvP/jG3uKJvAZOwEVUL4RTA5nJeeLYfyN9/VA8NX/V3IBG+hkeuGpKjvELkVhA==",
|
"integrity": "sha512-B7U/vJpE3DkJ5WXTgTpTRN63uV42DseiXXKMwG14LQBXmsdeIoHAPbU/MEo6II0k5ED74uc2ZGTC6MwHFQhF6w==",
|
||||||
"license": "BlueOak-1.0.0",
|
"license": "BlueOak-1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimatch": "^10.1.1",
|
"minimatch": "^10.1.2",
|
||||||
"minipass": "^7.1.2",
|
"minipass": "^7.1.2",
|
||||||
"path-scurry": "^2.0.0"
|
"path-scurry": "^2.0.0"
|
||||||
},
|
},
|
||||||
@@ -1555,12 +1555,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/minimatch": {
|
"node_modules/minimatch": {
|
||||||
"version": "10.1.1",
|
"version": "10.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.2.tgz",
|
||||||
"integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==",
|
"integrity": "sha512-fu656aJ0n2kcXwsnwnv9g24tkU5uSmOlTjd6WyyaKm2Z+h1qmY6bAjrcaIxF/BslFqbZ8UBtbJi7KgQOZD2PTw==",
|
||||||
"license": "BlueOak-1.0.0",
|
"license": "BlueOak-1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@isaacs/brace-expansion": "^5.0.0"
|
"@isaacs/brace-expansion": "^5.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "20 || >=22"
|
"node": "20 || >=22"
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ export async function tidalRoutes(
|
|||||||
description: "Get current volume level",
|
description: "Get current volume level",
|
||||||
tags: ["tidal"],
|
tags: ["tidal"],
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.number(),
|
||||||
volume: z.number(),
|
|
||||||
}),
|
|
||||||
418: z.object({
|
418: z.object({
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
}),
|
}),
|
||||||
@@ -110,13 +108,9 @@ export async function tidalRoutes(
|
|||||||
description:
|
description:
|
||||||
"Set volume level (accepts absolute number or relative +/- value)",
|
"Set volume level (accepts absolute number or relative +/- value)",
|
||||||
tags: ["tidal"],
|
tags: ["tidal"],
|
||||||
body: z.object({
|
body: z.string(),
|
||||||
volume: z.string(),
|
|
||||||
}),
|
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.number(),
|
||||||
volume: z.number(),
|
|
||||||
}),
|
|
||||||
401: z.object({
|
401: z.object({
|
||||||
error: z.literal("Invalid API key"),
|
error: z.literal("Invalid API key"),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import {
|
|||||||
BaseService,
|
BaseService,
|
||||||
type ServiceResult,
|
type ServiceResult,
|
||||||
type TidalGetCurrent,
|
type TidalGetCurrent,
|
||||||
type TidalPutVolume,
|
|
||||||
} from "@dpu/shared";
|
} from "@dpu/shared";
|
||||||
import { logWarning } from "@dpu/shared/dist/logger.js";
|
import { logWarning } from "@dpu/shared/dist/logger.js";
|
||||||
import type { TidalClient } from "./client.js";
|
import type { TidalClient } from "./client.js";
|
||||||
@@ -33,13 +32,13 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVolume(): Promise<ServiceResult<TidalPutVolume | string>> {
|
async getVolume(): Promise<ServiceResult<number | string>> {
|
||||||
try {
|
try {
|
||||||
const response = await this.getClient().get<TidalGetCurrent>("current");
|
const response = await this.getClient().get<TidalGetCurrent>("current");
|
||||||
|
|
||||||
return this.getSuccessfulResult({
|
return this.getSuccessfulResult(
|
||||||
volume: response.volume,
|
this.decimalToPercentage(response.volume),
|
||||||
});
|
);
|
||||||
} catch {
|
} catch {
|
||||||
const error_message = "error getting volume from tidal";
|
const error_message = "error getting volume from tidal";
|
||||||
logWarning(error_message);
|
logWarning(error_message);
|
||||||
@@ -48,20 +47,18 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clamp(value: number): number {
|
clamp(value: number): number {
|
||||||
return Math.min(Math.max(value, 0), 100);
|
return Math.min(Math.max(value, 0.0), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setVolume(
|
async setVolume(argument: string): Promise<ServiceResult<number | string>> {
|
||||||
argument: string,
|
const value = this.percentageToDecimal(parseFloat(argument));
|
||||||
): Promise<ServiceResult<TidalPutVolume | string>> {
|
|
||||||
const value = this.percentageToDecimal(argument);
|
|
||||||
// relative
|
// relative
|
||||||
const adjustMatch = argument.match(/^([+-])/);
|
const adjustMatch = argument.match(/^([+-])/);
|
||||||
if (adjustMatch) {
|
if (adjustMatch) {
|
||||||
const req = await this.getVolume();
|
const req = await this.getVolume();
|
||||||
if (req.successful) {
|
if (req.successful) {
|
||||||
const volume = req.result as TidalPutVolume;
|
const volume = req.result as number;
|
||||||
const wantedVolume = volume.volume + value;
|
const wantedVolume = volume + value;
|
||||||
const clampWantedVolume = this.clamp(wantedVolume);
|
const clampWantedVolume = this.clamp(wantedVolume);
|
||||||
return await this.setVolumeToTidal(clampWantedVolume);
|
return await this.setVolumeToTidal(clampWantedVolume);
|
||||||
}
|
}
|
||||||
@@ -81,16 +78,11 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
|
|
||||||
async setVolumeToTidal(
|
async setVolumeToTidal(
|
||||||
volume: number,
|
volume: number,
|
||||||
): Promise<ServiceResult<TidalPutVolume | string>> {
|
): Promise<ServiceResult<number | string>> {
|
||||||
try {
|
try {
|
||||||
const response = await this.getClient().put<TidalPutVolume>(
|
await this.getClient().put<number>(`player/volume?volume=${volume}`, {});
|
||||||
`player/volume?volume=${volume}`,
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
return this.getSuccessfulResult(
|
return this.getSuccessfulResult(this.decimalToPercentage(volume));
|
||||||
this.decimalToPercentage(response.volume).toString(),
|
|
||||||
);
|
|
||||||
} catch {
|
} catch {
|
||||||
const error_message = "error setting volume from tidal";
|
const error_message = "error setting volume from tidal";
|
||||||
logWarning(error_message);
|
logWarning(error_message);
|
||||||
@@ -102,8 +94,7 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
return decimal * 100;
|
return decimal * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
percentageToDecimal(percentage: string): number {
|
percentageToDecimal(percentage: number): number {
|
||||||
const num = parseFloat(percentage);
|
return percentage / 100;
|
||||||
return num / 100;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user