rework to work with non forked version
This commit is contained in:
793
package-lock.json
generated
793
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -13,9 +13,9 @@ export class TidalClient extends BaseClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async post<T>(endpoint: string, data: unknown): Promise<T> {
|
async put<T>(endpoint: string, data: unknown): Promise<T> {
|
||||||
try {
|
try {
|
||||||
const response = await this.getAxios().post<T>(`/${endpoint}`, data);
|
const response = await this.getAxios().put<T>(`/${endpoint}`, data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
printNetworkError(error);
|
printNetworkError(error);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
BaseService,
|
BaseService,
|
||||||
type ServiceResult,
|
type ServiceResult,
|
||||||
type TidalSong,
|
type TidalGetCurrent,
|
||||||
type TidalVolume,
|
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";
|
||||||
@@ -11,7 +11,7 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
async getSongFormatted(): Promise<ServiceResult<string>> {
|
async getSongFormatted(): Promise<ServiceResult<string>> {
|
||||||
const req = await this.getSong();
|
const req = await this.getSong();
|
||||||
if (req.successful) {
|
if (req.successful) {
|
||||||
const song = req.result as TidalSong;
|
const song = req.result as TidalGetCurrent;
|
||||||
const status = song.status === "playing" ? "▶️" : "⏸️";
|
const status = song.status === "playing" ? "▶️" : "⏸️";
|
||||||
return this.getSuccessfulResult(
|
return this.getSuccessfulResult(
|
||||||
`listening to ${song.title} by ${song.artists}. ${status} ${song.current}/${song.duration}. link: ${song.url}`,
|
`listening to ${song.title} by ${song.artists}. ${status} ${song.current}/${song.duration}. link: ${song.url}`,
|
||||||
@@ -21,9 +21,9 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSong(): Promise<ServiceResult<TidalSong | string>> {
|
async getSong(): Promise<ServiceResult<TidalGetCurrent | string>> {
|
||||||
try {
|
try {
|
||||||
const response = await this.getClient().get<TidalSong>("current");
|
const response = await this.getClient().get<TidalGetCurrent>("current");
|
||||||
|
|
||||||
return this.getSuccessfulResult(response);
|
return this.getSuccessfulResult(response);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -33,11 +33,13 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVolume(): Promise<ServiceResult<TidalVolume | string>> {
|
async getVolume(): Promise<ServiceResult<TidalPutVolume | string>> {
|
||||||
try {
|
try {
|
||||||
const response = await this.getClient().get<TidalVolume>("volume");
|
const response = await this.getClient().get<TidalGetCurrent>("current");
|
||||||
|
|
||||||
return this.getSuccessfulResult(response);
|
return this.getSuccessfulResult({
|
||||||
|
volume: 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);
|
||||||
@@ -51,14 +53,14 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
|
|
||||||
async setVolume(
|
async setVolume(
|
||||||
argument: string,
|
argument: string,
|
||||||
): Promise<ServiceResult<TidalVolume | string>> {
|
): Promise<ServiceResult<TidalPutVolume | string>> {
|
||||||
const value = parseInt(argument, 10);
|
const value = this.percentageToDecimal(argument);
|
||||||
// relative
|
// relative
|
||||||
const adjustMatch = argument.match(/^([+-])(\d+)$/);
|
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 TidalVolume;
|
const volume = req.result as TidalPutVolume;
|
||||||
const wantedVolume = volume.volume + value;
|
const wantedVolume = volume.volume + value;
|
||||||
const clampWantedVolume = this.clamp(wantedVolume);
|
const clampWantedVolume = this.clamp(wantedVolume);
|
||||||
return await this.setVolumeToTidal(clampWantedVolume);
|
return await this.setVolumeToTidal(clampWantedVolume);
|
||||||
@@ -66,7 +68,7 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// absolute
|
// absolute
|
||||||
const setMatch = argument.match(/^(\d+)$/);
|
const setMatch = argument.match(/^(\d+)/);
|
||||||
if (setMatch) {
|
if (setMatch) {
|
||||||
const clampValue = this.clamp(value);
|
const clampValue = this.clamp(value);
|
||||||
return await this.setVolumeToTidal(clampValue);
|
return await this.setVolumeToTidal(clampValue);
|
||||||
@@ -79,11 +81,12 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
|
|
||||||
async setVolumeToTidal(
|
async setVolumeToTidal(
|
||||||
volume: number,
|
volume: number,
|
||||||
): Promise<ServiceResult<TidalVolume | string>> {
|
): Promise<ServiceResult<TidalPutVolume | string>> {
|
||||||
try {
|
try {
|
||||||
const response = await this.getClient().post<TidalVolume>("volume", {
|
const response = await this.getClient().put<TidalPutVolume>(
|
||||||
volume,
|
`player/volume?volume=${volume}`,
|
||||||
});
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
return this.getSuccessfulResult(response);
|
return this.getSuccessfulResult(response);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -92,4 +95,13 @@ export class TidalService extends BaseService<TidalClient> {
|
|||||||
return this.getErrorResult(error_message);
|
return this.getErrorResult(error_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decimalToPercentage(decimal: number): number {
|
||||||
|
return decimal * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
percentageToDecimal(percentage: string): number {
|
||||||
|
const num = parseFloat(percentage);
|
||||||
|
return num / 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user