lavalink-client 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/structures/Player.js +3 -3
- package/dist/cjs/structures/Track.d.ts +20 -2
- package/dist/cjs/structures/Utils.d.ts +12 -15
- package/dist/cjs/structures/Utils.js +46 -46
- package/dist/esm/structures/Player.js +3 -3
- package/dist/esm/structures/Track.d.ts +20 -2
- package/dist/esm/structures/Utils.d.ts +12 -15
- package/dist/esm/structures/Utils.js +46 -46
- package/dist/types/structures/Track.d.ts +20 -2
- package/dist/types/structures/Utils.d.ts +12 -15
- package/package.json +1 -1
|
@@ -216,7 +216,7 @@ class Player {
|
|
|
216
216
|
source: LavalinkManagerStatics_1.DefaultSources[(typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform.toLowerCase()] ?? (typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform
|
|
217
217
|
};
|
|
218
218
|
// if user does player.search("ytsearch:Hello")
|
|
219
|
-
const foundSource =
|
|
219
|
+
const foundSource = Object.keys(LavalinkManagerStatics_1.DefaultSources).find(source => Query.query.toLowerCase().startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
|
|
220
220
|
if (foundSource && LavalinkManagerStatics_1.DefaultSources[foundSource]) {
|
|
221
221
|
Query.source = LavalinkManagerStatics_1.DefaultSources[foundSource]; // set the source to ytsearch:
|
|
222
222
|
Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
|
|
@@ -251,13 +251,13 @@ class Player {
|
|
|
251
251
|
source: LavalinkManagerStatics_1.DefaultSources[(typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform.toLowerCase()] ?? (typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform
|
|
252
252
|
};
|
|
253
253
|
// if user does player.search("ytsearch:Hello")
|
|
254
|
-
const foundSource =
|
|
254
|
+
const foundSource = Object.keys(LavalinkManagerStatics_1.DefaultSources).find(source => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
|
|
255
255
|
if (foundSource && LavalinkManagerStatics_1.DefaultSources[foundSource]) {
|
|
256
256
|
Query.source = LavalinkManagerStatics_1.DefaultSources[foundSource]; // set the source to ytsearch:
|
|
257
257
|
Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
|
|
258
258
|
}
|
|
259
259
|
if (/^https?:\/\//.test(Query.query))
|
|
260
|
-
this.LavalinkManager.utils.
|
|
260
|
+
this.LavalinkManager.utils.validateQueryString(this.node, Query.source);
|
|
261
261
|
else if (Query.source)
|
|
262
262
|
this.LavalinkManager.utils.validateSourceString(this.node, Query.source);
|
|
263
263
|
// ftts query parameters: ?voice=Olivia&audio_format=ogg_opus&translate=False&silence=1000&speed=1.0 | example raw get query: https://api.flowery.pw/v1/tts?voice=Olivia&audio_format=ogg_opus&translate=False&silence=0&speed=1.0&text=Hello%20World
|
|
@@ -3,6 +3,18 @@ import { Base64 } from "./Utils";
|
|
|
3
3
|
type LavalinkSourceNames = "youtube" | "youtubemusic" | "soundcloud" | "bandcamp" | "twitch";
|
|
4
4
|
type LavalinkPlugin_LavaSrc_SourceNames = "deezer" | "spotify" | "applemusic" | "yandexmusic" | "flowery-tts";
|
|
5
5
|
type SourceNames = LavalinkSourceNames | LavalinkPlugin_LavaSrc_SourceNames;
|
|
6
|
+
export interface LavalinkTrackInfo {
|
|
7
|
+
identifier: string;
|
|
8
|
+
title: string;
|
|
9
|
+
author: string;
|
|
10
|
+
length: number;
|
|
11
|
+
artworkUrl: string | null;
|
|
12
|
+
uri: string;
|
|
13
|
+
sourceName: SourceNames;
|
|
14
|
+
isSeekable: boolean;
|
|
15
|
+
isStream: boolean;
|
|
16
|
+
isrc: string | null;
|
|
17
|
+
}
|
|
6
18
|
export interface TrackInfo {
|
|
7
19
|
identifier: string;
|
|
8
20
|
title: string;
|
|
@@ -51,11 +63,17 @@ export interface LavalinkTrack {
|
|
|
51
63
|
/** The Base 64 encoded String */
|
|
52
64
|
encoded?: Base64;
|
|
53
65
|
/** Track Information */
|
|
54
|
-
info:
|
|
66
|
+
info: LavalinkTrackInfo;
|
|
55
67
|
/** Plugin Information from Lavalink */
|
|
56
68
|
pluginInfo: Partial<PluginInfo>;
|
|
57
69
|
}
|
|
58
|
-
export interface Track
|
|
70
|
+
export interface Track {
|
|
71
|
+
/** The Base 64 encoded String */
|
|
72
|
+
encoded?: Base64;
|
|
73
|
+
/** Track Information */
|
|
74
|
+
info: TrackInfo;
|
|
75
|
+
/** Plugin Information from Lavalink */
|
|
76
|
+
pluginInfo: Partial<PluginInfo>;
|
|
59
77
|
/** The Track's Requester */
|
|
60
78
|
requester?: unknown;
|
|
61
79
|
}
|
|
@@ -2,7 +2,7 @@ import { LavalinkFilterData } from "./Filters";
|
|
|
2
2
|
import { LavalinkManager } from "./LavalinkManager";
|
|
3
3
|
import { LavalinkNode, LavalinkNodeOptions, NodeStats } from "./Node";
|
|
4
4
|
import { PlayOptions, Player } from "./Player";
|
|
5
|
-
import { PluginInfo, Track, UnresolvedTrack, UnresolvedQuery } from "./Track";
|
|
5
|
+
import { PluginInfo, Track, UnresolvedTrack, UnresolvedQuery, LavalinkTrack } from "./Track";
|
|
6
6
|
export declare const TrackSymbol: unique symbol;
|
|
7
7
|
export declare const UnresolvedTrackSymbol: unique symbol;
|
|
8
8
|
export declare const QueueSymbol: unique symbol;
|
|
@@ -37,13 +37,16 @@ export interface SearchResult {
|
|
|
37
37
|
playlist: PlaylistInfo | null;
|
|
38
38
|
tracks: Track[];
|
|
39
39
|
}
|
|
40
|
-
export interface ManagerUitls {
|
|
41
|
-
/** @private */
|
|
42
|
-
manager: LavalinkManager;
|
|
43
|
-
}
|
|
44
40
|
export declare class ManagerUitls {
|
|
41
|
+
LavalinkManager: LavalinkManager | null;
|
|
45
42
|
constructor(LavalinkManager?: LavalinkManager);
|
|
46
|
-
buildTrack(data:
|
|
43
|
+
buildTrack(data: LavalinkTrack | Track, requester: unknown): Track;
|
|
44
|
+
/**
|
|
45
|
+
* Builds a UnresolvedTrack to be resolved before being played .
|
|
46
|
+
* @param query
|
|
47
|
+
* @param requester
|
|
48
|
+
*/
|
|
49
|
+
buildUnresolvedTrack(query: UnresolvedQuery | UnresolvedTrack, requester: unknown): UnresolvedTrack;
|
|
47
50
|
/**
|
|
48
51
|
* Validate if a data is equal to a node
|
|
49
52
|
* @param data
|
|
@@ -69,15 +72,9 @@ export declare class ManagerUitls {
|
|
|
69
72
|
* Checks if the provided argument is a valid UnresolvedTrack.
|
|
70
73
|
* @param track
|
|
71
74
|
*/
|
|
72
|
-
isUnresolvedTrackQuery(data:
|
|
73
|
-
getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track>;
|
|
74
|
-
|
|
75
|
-
* Builds a UnresolvedTrack to be resolved before being played .
|
|
76
|
-
* @param query
|
|
77
|
-
* @param requester
|
|
78
|
-
*/
|
|
79
|
-
buildUnresolvedTrack(query: UnresolvedQuery | UnresolvedTrack, requester: unknown): UnresolvedTrack;
|
|
80
|
-
validatedQueryString(node: LavalinkNode, queryString: string): void;
|
|
75
|
+
isUnresolvedTrackQuery(data: UnresolvedQuery | any): boolean;
|
|
76
|
+
getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
|
|
77
|
+
validateQueryString(node: LavalinkNode, queryString: string): void;
|
|
81
78
|
validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
|
|
82
79
|
}
|
|
83
80
|
/**
|
|
@@ -9,32 +9,32 @@ exports.NodeSymbol = Symbol("LC-Node");
|
|
|
9
9
|
/** @hidden */
|
|
10
10
|
const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11
11
|
class ManagerUitls {
|
|
12
|
+
LavalinkManager = null;
|
|
12
13
|
constructor(LavalinkManager) {
|
|
13
|
-
this.
|
|
14
|
+
this.LavalinkManager = LavalinkManager;
|
|
14
15
|
}
|
|
15
16
|
buildTrack(data, requester) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new RangeError("Argument 'data.encoded' / 'data.encoded' / 'data.track' must be present.");
|
|
17
|
+
if (!data?.encoded || typeof data.encoded !== "string")
|
|
18
|
+
throw new RangeError("Argument 'data.encoded' must be present.");
|
|
19
19
|
if (!data.info)
|
|
20
|
-
data.info
|
|
20
|
+
throw new RangeError("Argument 'data.info' must be present.");
|
|
21
21
|
try {
|
|
22
22
|
const r = {
|
|
23
|
-
encoded,
|
|
23
|
+
encoded: data.encoded,
|
|
24
24
|
info: {
|
|
25
|
-
identifier: data.info
|
|
26
|
-
title: data.info
|
|
27
|
-
author: data.info
|
|
28
|
-
duration: data.info
|
|
29
|
-
artworkUrl: data.info
|
|
30
|
-
uri: data.info
|
|
31
|
-
sourceName: data.info
|
|
32
|
-
isSeekable: data.info
|
|
33
|
-
isStream: data.info
|
|
34
|
-
isrc: data.info
|
|
25
|
+
identifier: data.info.identifier,
|
|
26
|
+
title: data.info.title,
|
|
27
|
+
author: data.info.author,
|
|
28
|
+
duration: data.info.length || data.info.duration,
|
|
29
|
+
artworkUrl: data.info.artworkUrl || data.pluginInfo?.artworkUrl || data.plugin?.artworkUrl,
|
|
30
|
+
uri: data.info.uri,
|
|
31
|
+
sourceName: data.info.sourceName,
|
|
32
|
+
isSeekable: data.info.isSeekable,
|
|
33
|
+
isStream: data.info.isStream,
|
|
34
|
+
isrc: data.info.isrc,
|
|
35
35
|
},
|
|
36
36
|
pluginInfo: data.pluginInfo || data.plugin || {},
|
|
37
|
-
requester: typeof this.
|
|
37
|
+
requester: typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function" ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer(data?.requester || requester) : requester,
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(r, exports.TrackSymbol, { configurable: true, value: true });
|
|
40
40
|
return r;
|
|
@@ -43,6 +43,32 @@ class ManagerUitls {
|
|
|
43
43
|
throw new RangeError(`Argument "data" is not a valid track: ${error.message}`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Builds a UnresolvedTrack to be resolved before being played .
|
|
48
|
+
* @param query
|
|
49
|
+
* @param requester
|
|
50
|
+
*/
|
|
51
|
+
buildUnresolvedTrack(query, requester) {
|
|
52
|
+
if (typeof query === "undefined")
|
|
53
|
+
throw new RangeError('Argument "query" must be present.');
|
|
54
|
+
const unresolvedTrack = {
|
|
55
|
+
encoded: query.encoded || undefined,
|
|
56
|
+
info: query.info ? query.info : query.title ? query : undefined,
|
|
57
|
+
requester: typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function" ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer((query?.requester || requester)) : requester,
|
|
58
|
+
async resolve(player) {
|
|
59
|
+
const closest = await getClosestTrack(this, player, player.LavalinkManager.utils);
|
|
60
|
+
if (!closest)
|
|
61
|
+
throw new SyntaxError("No closest Track found");
|
|
62
|
+
Object.getOwnPropertyNames(this).forEach(prop => delete this[prop]);
|
|
63
|
+
Object.assign(this, closest);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
if (!this.isUnresolvedTrack(unresolvedTrack))
|
|
68
|
+
throw SyntaxError("Could not build Unresolved Track");
|
|
69
|
+
Object.defineProperty(unresolvedTrack, exports.UnresolvedTrackSymbol, { configurable: true, value: true });
|
|
70
|
+
return unresolvedTrack;
|
|
71
|
+
}
|
|
46
72
|
/**
|
|
47
73
|
* Validate if a data is equal to a node
|
|
48
74
|
* @param data
|
|
@@ -124,33 +150,7 @@ class ManagerUitls {
|
|
|
124
150
|
async getClosestTrack(data, player) {
|
|
125
151
|
return getClosestTrack(data, player, this);
|
|
126
152
|
}
|
|
127
|
-
|
|
128
|
-
* Builds a UnresolvedTrack to be resolved before being played .
|
|
129
|
-
* @param query
|
|
130
|
-
* @param requester
|
|
131
|
-
*/
|
|
132
|
-
buildUnresolvedTrack(query, requester) {
|
|
133
|
-
if (typeof query === "undefined")
|
|
134
|
-
throw new RangeError('Argument "query" must be present.');
|
|
135
|
-
const unresolvedTrack = {
|
|
136
|
-
encoded: query.encoded || undefined,
|
|
137
|
-
info: query.info ? query.info : query.title ? query : undefined,
|
|
138
|
-
requester: typeof this.manager.options?.playerOptions?.requesterTransformer === "function" ? this.manager.options?.playerOptions?.requesterTransformer((query?.requester || requester)) : requester,
|
|
139
|
-
async resolve(player) {
|
|
140
|
-
const closest = await getClosestTrack(this, player, player.LavalinkManager.utils);
|
|
141
|
-
if (!closest)
|
|
142
|
-
throw new SyntaxError("No closest Track found");
|
|
143
|
-
Object.getOwnPropertyNames(this).forEach(prop => delete this[prop]);
|
|
144
|
-
Object.assign(this, closest);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
if (!this.isUnresolvedTrack(unresolvedTrack))
|
|
149
|
-
throw SyntaxError("Could not build Unresolved Track");
|
|
150
|
-
Object.defineProperty(unresolvedTrack, exports.UnresolvedTrackSymbol, { configurable: true, value: true });
|
|
151
|
-
return unresolvedTrack;
|
|
152
|
-
}
|
|
153
|
-
validatedQueryString(node, queryString) {
|
|
153
|
+
validateQueryString(node, queryString) {
|
|
154
154
|
if (!node.info)
|
|
155
155
|
throw new Error("No Lavalink Node was provided");
|
|
156
156
|
if (!node.info.sourceManagers?.length)
|
|
@@ -197,7 +197,7 @@ class ManagerUitls {
|
|
|
197
197
|
validateSourceString(node, sourceString) {
|
|
198
198
|
if (!sourceString)
|
|
199
199
|
throw new Error(`No SourceString was provided`);
|
|
200
|
-
const source = LavalinkManagerStatics_1.DefaultSources[sourceString.toLowerCase()] || Object.
|
|
200
|
+
const source = LavalinkManagerStatics_1.DefaultSources[sourceString.toLowerCase()] || Object.keys(LavalinkManagerStatics_1.DefaultSources).find(v => v.toLowerCase() === sourceString?.toLowerCase());
|
|
201
201
|
if (!source)
|
|
202
202
|
throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
|
|
203
203
|
if (source === "amsearch" && !node.info.sourceManagers.includes("applemusic")) {
|
|
@@ -294,7 +294,7 @@ exports.queueTrackEnd = queueTrackEnd;
|
|
|
294
294
|
async function applyUnresolvedData(resTrack, data, utils) {
|
|
295
295
|
if (!resTrack?.info || !data?.info)
|
|
296
296
|
return;
|
|
297
|
-
if (utils
|
|
297
|
+
if (utils?.LavalinkManager?.options?.playerOptions?.useUnresolvedData === true) { // overwrite values
|
|
298
298
|
if (data.info.uri)
|
|
299
299
|
resTrack.info.uri = data.info.uri;
|
|
300
300
|
if (data.info.artworkUrl?.length)
|
|
@@ -213,7 +213,7 @@ export class Player {
|
|
|
213
213
|
source: DefaultSources[(typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform.toLowerCase()] ?? (typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform
|
|
214
214
|
};
|
|
215
215
|
// if user does player.search("ytsearch:Hello")
|
|
216
|
-
const foundSource =
|
|
216
|
+
const foundSource = Object.keys(DefaultSources).find(source => Query.query.toLowerCase().startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
|
|
217
217
|
if (foundSource && DefaultSources[foundSource]) {
|
|
218
218
|
Query.source = DefaultSources[foundSource]; // set the source to ytsearch:
|
|
219
219
|
Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
|
|
@@ -248,13 +248,13 @@ export class Player {
|
|
|
248
248
|
source: DefaultSources[(typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform.toLowerCase()] ?? (typeof query === "string" ? undefined : query.source?.trim?.()?.toLowerCase?.()) ?? this.LavalinkManager.options.playerOptions.defaultSearchPlatform
|
|
249
249
|
};
|
|
250
250
|
// if user does player.search("ytsearch:Hello")
|
|
251
|
-
const foundSource =
|
|
251
|
+
const foundSource = Object.keys(DefaultSources).find(source => Query.query?.toLowerCase?.()?.startsWith(`${source}:`.toLowerCase()))?.trim?.()?.toLowerCase?.();
|
|
252
252
|
if (foundSource && DefaultSources[foundSource]) {
|
|
253
253
|
Query.source = DefaultSources[foundSource]; // set the source to ytsearch:
|
|
254
254
|
Query.query = Query.query.slice(`${foundSource}:`.length, Query.query.length); // remove ytsearch: from the query
|
|
255
255
|
}
|
|
256
256
|
if (/^https?:\/\//.test(Query.query))
|
|
257
|
-
this.LavalinkManager.utils.
|
|
257
|
+
this.LavalinkManager.utils.validateQueryString(this.node, Query.source);
|
|
258
258
|
else if (Query.source)
|
|
259
259
|
this.LavalinkManager.utils.validateSourceString(this.node, Query.source);
|
|
260
260
|
// ftts query parameters: ?voice=Olivia&audio_format=ogg_opus&translate=False&silence=1000&speed=1.0 | example raw get query: https://api.flowery.pw/v1/tts?voice=Olivia&audio_format=ogg_opus&translate=False&silence=0&speed=1.0&text=Hello%20World
|
|
@@ -3,6 +3,18 @@ import { Base64 } from "./Utils";
|
|
|
3
3
|
type LavalinkSourceNames = "youtube" | "youtubemusic" | "soundcloud" | "bandcamp" | "twitch";
|
|
4
4
|
type LavalinkPlugin_LavaSrc_SourceNames = "deezer" | "spotify" | "applemusic" | "yandexmusic" | "flowery-tts";
|
|
5
5
|
type SourceNames = LavalinkSourceNames | LavalinkPlugin_LavaSrc_SourceNames;
|
|
6
|
+
export interface LavalinkTrackInfo {
|
|
7
|
+
identifier: string;
|
|
8
|
+
title: string;
|
|
9
|
+
author: string;
|
|
10
|
+
length: number;
|
|
11
|
+
artworkUrl: string | null;
|
|
12
|
+
uri: string;
|
|
13
|
+
sourceName: SourceNames;
|
|
14
|
+
isSeekable: boolean;
|
|
15
|
+
isStream: boolean;
|
|
16
|
+
isrc: string | null;
|
|
17
|
+
}
|
|
6
18
|
export interface TrackInfo {
|
|
7
19
|
identifier: string;
|
|
8
20
|
title: string;
|
|
@@ -51,11 +63,17 @@ export interface LavalinkTrack {
|
|
|
51
63
|
/** The Base 64 encoded String */
|
|
52
64
|
encoded?: Base64;
|
|
53
65
|
/** Track Information */
|
|
54
|
-
info:
|
|
66
|
+
info: LavalinkTrackInfo;
|
|
55
67
|
/** Plugin Information from Lavalink */
|
|
56
68
|
pluginInfo: Partial<PluginInfo>;
|
|
57
69
|
}
|
|
58
|
-
export interface Track
|
|
70
|
+
export interface Track {
|
|
71
|
+
/** The Base 64 encoded String */
|
|
72
|
+
encoded?: Base64;
|
|
73
|
+
/** Track Information */
|
|
74
|
+
info: TrackInfo;
|
|
75
|
+
/** Plugin Information from Lavalink */
|
|
76
|
+
pluginInfo: Partial<PluginInfo>;
|
|
59
77
|
/** The Track's Requester */
|
|
60
78
|
requester?: unknown;
|
|
61
79
|
}
|
|
@@ -2,7 +2,7 @@ import { LavalinkFilterData } from "./Filters";
|
|
|
2
2
|
import { LavalinkManager } from "./LavalinkManager";
|
|
3
3
|
import { LavalinkNode, LavalinkNodeOptions, NodeStats } from "./Node";
|
|
4
4
|
import { PlayOptions, Player } from "./Player";
|
|
5
|
-
import { PluginInfo, Track, UnresolvedTrack, UnresolvedQuery } from "./Track";
|
|
5
|
+
import { PluginInfo, Track, UnresolvedTrack, UnresolvedQuery, LavalinkTrack } from "./Track";
|
|
6
6
|
export declare const TrackSymbol: unique symbol;
|
|
7
7
|
export declare const UnresolvedTrackSymbol: unique symbol;
|
|
8
8
|
export declare const QueueSymbol: unique symbol;
|
|
@@ -37,13 +37,16 @@ export interface SearchResult {
|
|
|
37
37
|
playlist: PlaylistInfo | null;
|
|
38
38
|
tracks: Track[];
|
|
39
39
|
}
|
|
40
|
-
export interface ManagerUitls {
|
|
41
|
-
/** @private */
|
|
42
|
-
manager: LavalinkManager;
|
|
43
|
-
}
|
|
44
40
|
export declare class ManagerUitls {
|
|
41
|
+
LavalinkManager: LavalinkManager | null;
|
|
45
42
|
constructor(LavalinkManager?: LavalinkManager);
|
|
46
|
-
buildTrack(data:
|
|
43
|
+
buildTrack(data: LavalinkTrack | Track, requester: unknown): Track;
|
|
44
|
+
/**
|
|
45
|
+
* Builds a UnresolvedTrack to be resolved before being played .
|
|
46
|
+
* @param query
|
|
47
|
+
* @param requester
|
|
48
|
+
*/
|
|
49
|
+
buildUnresolvedTrack(query: UnresolvedQuery | UnresolvedTrack, requester: unknown): UnresolvedTrack;
|
|
47
50
|
/**
|
|
48
51
|
* Validate if a data is equal to a node
|
|
49
52
|
* @param data
|
|
@@ -69,15 +72,9 @@ export declare class ManagerUitls {
|
|
|
69
72
|
* Checks if the provided argument is a valid UnresolvedTrack.
|
|
70
73
|
* @param track
|
|
71
74
|
*/
|
|
72
|
-
isUnresolvedTrackQuery(data:
|
|
73
|
-
getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track>;
|
|
74
|
-
|
|
75
|
-
* Builds a UnresolvedTrack to be resolved before being played .
|
|
76
|
-
* @param query
|
|
77
|
-
* @param requester
|
|
78
|
-
*/
|
|
79
|
-
buildUnresolvedTrack(query: UnresolvedQuery | UnresolvedTrack, requester: unknown): UnresolvedTrack;
|
|
80
|
-
validatedQueryString(node: LavalinkNode, queryString: string): void;
|
|
75
|
+
isUnresolvedTrackQuery(data: UnresolvedQuery | any): boolean;
|
|
76
|
+
getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
|
|
77
|
+
validateQueryString(node: LavalinkNode, queryString: string): void;
|
|
81
78
|
validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
|
|
82
79
|
}
|
|
83
80
|
/**
|
|
@@ -6,32 +6,32 @@ export const NodeSymbol = Symbol("LC-Node");
|
|
|
6
6
|
/** @hidden */
|
|
7
7
|
const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8
8
|
export class ManagerUitls {
|
|
9
|
+
LavalinkManager = null;
|
|
9
10
|
constructor(LavalinkManager) {
|
|
10
|
-
this.
|
|
11
|
+
this.LavalinkManager = LavalinkManager;
|
|
11
12
|
}
|
|
12
13
|
buildTrack(data, requester) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new RangeError("Argument 'data.encoded' / 'data.encoded' / 'data.track' must be present.");
|
|
14
|
+
if (!data?.encoded || typeof data.encoded !== "string")
|
|
15
|
+
throw new RangeError("Argument 'data.encoded' must be present.");
|
|
16
16
|
if (!data.info)
|
|
17
|
-
data.info
|
|
17
|
+
throw new RangeError("Argument 'data.info' must be present.");
|
|
18
18
|
try {
|
|
19
19
|
const r = {
|
|
20
|
-
encoded,
|
|
20
|
+
encoded: data.encoded,
|
|
21
21
|
info: {
|
|
22
|
-
identifier: data.info
|
|
23
|
-
title: data.info
|
|
24
|
-
author: data.info
|
|
25
|
-
duration: data.info
|
|
26
|
-
artworkUrl: data.info
|
|
27
|
-
uri: data.info
|
|
28
|
-
sourceName: data.info
|
|
29
|
-
isSeekable: data.info
|
|
30
|
-
isStream: data.info
|
|
31
|
-
isrc: data.info
|
|
22
|
+
identifier: data.info.identifier,
|
|
23
|
+
title: data.info.title,
|
|
24
|
+
author: data.info.author,
|
|
25
|
+
duration: data.info.length || data.info.duration,
|
|
26
|
+
artworkUrl: data.info.artworkUrl || data.pluginInfo?.artworkUrl || data.plugin?.artworkUrl,
|
|
27
|
+
uri: data.info.uri,
|
|
28
|
+
sourceName: data.info.sourceName,
|
|
29
|
+
isSeekable: data.info.isSeekable,
|
|
30
|
+
isStream: data.info.isStream,
|
|
31
|
+
isrc: data.info.isrc,
|
|
32
32
|
},
|
|
33
33
|
pluginInfo: data.pluginInfo || data.plugin || {},
|
|
34
|
-
requester: typeof this.
|
|
34
|
+
requester: typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function" ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer(data?.requester || requester) : requester,
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(r, TrackSymbol, { configurable: true, value: true });
|
|
37
37
|
return r;
|
|
@@ -40,6 +40,32 @@ export class ManagerUitls {
|
|
|
40
40
|
throw new RangeError(`Argument "data" is not a valid track: ${error.message}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds a UnresolvedTrack to be resolved before being played .
|
|
45
|
+
* @param query
|
|
46
|
+
* @param requester
|
|
47
|
+
*/
|
|
48
|
+
buildUnresolvedTrack(query, requester) {
|
|
49
|
+
if (typeof query === "undefined")
|
|
50
|
+
throw new RangeError('Argument "query" must be present.');
|
|
51
|
+
const unresolvedTrack = {
|
|
52
|
+
encoded: query.encoded || undefined,
|
|
53
|
+
info: query.info ? query.info : query.title ? query : undefined,
|
|
54
|
+
requester: typeof this.LavalinkManager?.options?.playerOptions?.requesterTransformer === "function" ? this.LavalinkManager?.options?.playerOptions?.requesterTransformer((query?.requester || requester)) : requester,
|
|
55
|
+
async resolve(player) {
|
|
56
|
+
const closest = await getClosestTrack(this, player, player.LavalinkManager.utils);
|
|
57
|
+
if (!closest)
|
|
58
|
+
throw new SyntaxError("No closest Track found");
|
|
59
|
+
Object.getOwnPropertyNames(this).forEach(prop => delete this[prop]);
|
|
60
|
+
Object.assign(this, closest);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (!this.isUnresolvedTrack(unresolvedTrack))
|
|
65
|
+
throw SyntaxError("Could not build Unresolved Track");
|
|
66
|
+
Object.defineProperty(unresolvedTrack, UnresolvedTrackSymbol, { configurable: true, value: true });
|
|
67
|
+
return unresolvedTrack;
|
|
68
|
+
}
|
|
43
69
|
/**
|
|
44
70
|
* Validate if a data is equal to a node
|
|
45
71
|
* @param data
|
|
@@ -121,33 +147,7 @@ export class ManagerUitls {
|
|
|
121
147
|
async getClosestTrack(data, player) {
|
|
122
148
|
return getClosestTrack(data, player, this);
|
|
123
149
|
}
|
|
124
|
-
|
|
125
|
-
* Builds a UnresolvedTrack to be resolved before being played .
|
|
126
|
-
* @param query
|
|
127
|
-
* @param requester
|
|
128
|
-
*/
|
|
129
|
-
buildUnresolvedTrack(query, requester) {
|
|
130
|
-
if (typeof query === "undefined")
|
|
131
|
-
throw new RangeError('Argument "query" must be present.');
|
|
132
|
-
const unresolvedTrack = {
|
|
133
|
-
encoded: query.encoded || undefined,
|
|
134
|
-
info: query.info ? query.info : query.title ? query : undefined,
|
|
135
|
-
requester: typeof this.manager.options?.playerOptions?.requesterTransformer === "function" ? this.manager.options?.playerOptions?.requesterTransformer((query?.requester || requester)) : requester,
|
|
136
|
-
async resolve(player) {
|
|
137
|
-
const closest = await getClosestTrack(this, player, player.LavalinkManager.utils);
|
|
138
|
-
if (!closest)
|
|
139
|
-
throw new SyntaxError("No closest Track found");
|
|
140
|
-
Object.getOwnPropertyNames(this).forEach(prop => delete this[prop]);
|
|
141
|
-
Object.assign(this, closest);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
if (!this.isUnresolvedTrack(unresolvedTrack))
|
|
146
|
-
throw SyntaxError("Could not build Unresolved Track");
|
|
147
|
-
Object.defineProperty(unresolvedTrack, UnresolvedTrackSymbol, { configurable: true, value: true });
|
|
148
|
-
return unresolvedTrack;
|
|
149
|
-
}
|
|
150
|
-
validatedQueryString(node, queryString) {
|
|
150
|
+
validateQueryString(node, queryString) {
|
|
151
151
|
if (!node.info)
|
|
152
152
|
throw new Error("No Lavalink Node was provided");
|
|
153
153
|
if (!node.info.sourceManagers?.length)
|
|
@@ -194,7 +194,7 @@ export class ManagerUitls {
|
|
|
194
194
|
validateSourceString(node, sourceString) {
|
|
195
195
|
if (!sourceString)
|
|
196
196
|
throw new Error(`No SourceString was provided`);
|
|
197
|
-
const source = DefaultSources[sourceString.toLowerCase()] || Object.
|
|
197
|
+
const source = DefaultSources[sourceString.toLowerCase()] || Object.keys(DefaultSources).find(v => v.toLowerCase() === sourceString?.toLowerCase());
|
|
198
198
|
if (!source)
|
|
199
199
|
throw new Error(`Lavalink Node SearchQuerySource: '${sourceString}' is not available`);
|
|
200
200
|
if (source === "amsearch" && !node.info.sourceManagers.includes("applemusic")) {
|
|
@@ -288,7 +288,7 @@ export async function queueTrackEnd(player) {
|
|
|
288
288
|
async function applyUnresolvedData(resTrack, data, utils) {
|
|
289
289
|
if (!resTrack?.info || !data?.info)
|
|
290
290
|
return;
|
|
291
|
-
if (utils
|
|
291
|
+
if (utils?.LavalinkManager?.options?.playerOptions?.useUnresolvedData === true) { // overwrite values
|
|
292
292
|
if (data.info.uri)
|
|
293
293
|
resTrack.info.uri = data.info.uri;
|
|
294
294
|
if (data.info.artworkUrl?.length)
|
|
@@ -3,6 +3,18 @@ import { Base64 } from "./Utils";
|
|
|
3
3
|
type LavalinkSourceNames = "youtube" | "youtubemusic" | "soundcloud" | "bandcamp" | "twitch";
|
|
4
4
|
type LavalinkPlugin_LavaSrc_SourceNames = "deezer" | "spotify" | "applemusic" | "yandexmusic" | "flowery-tts";
|
|
5
5
|
type SourceNames = LavalinkSourceNames | LavalinkPlugin_LavaSrc_SourceNames;
|
|
6
|
+
export interface LavalinkTrackInfo {
|
|
7
|
+
identifier: string;
|
|
8
|
+
title: string;
|
|
9
|
+
author: string;
|
|
10
|
+
length: number;
|
|
11
|
+
artworkUrl: string | null;
|
|
12
|
+
uri: string;
|
|
13
|
+
sourceName: SourceNames;
|
|
14
|
+
isSeekable: boolean;
|
|
15
|
+
isStream: boolean;
|
|
16
|
+
isrc: string | null;
|
|
17
|
+
}
|
|
6
18
|
export interface TrackInfo {
|
|
7
19
|
identifier: string;
|
|
8
20
|
title: string;
|
|
@@ -51,11 +63,17 @@ export interface LavalinkTrack {
|
|
|
51
63
|
/** The Base 64 encoded String */
|
|
52
64
|
encoded?: Base64;
|
|
53
65
|
/** Track Information */
|
|
54
|
-
info:
|
|
66
|
+
info: LavalinkTrackInfo;
|
|
55
67
|
/** Plugin Information from Lavalink */
|
|
56
68
|
pluginInfo: Partial<PluginInfo>;
|
|
57
69
|
}
|
|
58
|
-
export interface Track
|
|
70
|
+
export interface Track {
|
|
71
|
+
/** The Base 64 encoded String */
|
|
72
|
+
encoded?: Base64;
|
|
73
|
+
/** Track Information */
|
|
74
|
+
info: TrackInfo;
|
|
75
|
+
/** Plugin Information from Lavalink */
|
|
76
|
+
pluginInfo: Partial<PluginInfo>;
|
|
59
77
|
/** The Track's Requester */
|
|
60
78
|
requester?: unknown;
|
|
61
79
|
}
|
|
@@ -2,7 +2,7 @@ import { LavalinkFilterData } from "./Filters";
|
|
|
2
2
|
import { LavalinkManager } from "./LavalinkManager";
|
|
3
3
|
import { LavalinkNode, LavalinkNodeOptions, NodeStats } from "./Node";
|
|
4
4
|
import { PlayOptions, Player } from "./Player";
|
|
5
|
-
import { PluginInfo, Track, UnresolvedTrack, UnresolvedQuery } from "./Track";
|
|
5
|
+
import { PluginInfo, Track, UnresolvedTrack, UnresolvedQuery, LavalinkTrack } from "./Track";
|
|
6
6
|
export declare const TrackSymbol: unique symbol;
|
|
7
7
|
export declare const UnresolvedTrackSymbol: unique symbol;
|
|
8
8
|
export declare const QueueSymbol: unique symbol;
|
|
@@ -37,13 +37,16 @@ export interface SearchResult {
|
|
|
37
37
|
playlist: PlaylistInfo | null;
|
|
38
38
|
tracks: Track[];
|
|
39
39
|
}
|
|
40
|
-
export interface ManagerUitls {
|
|
41
|
-
/** @private */
|
|
42
|
-
manager: LavalinkManager;
|
|
43
|
-
}
|
|
44
40
|
export declare class ManagerUitls {
|
|
41
|
+
LavalinkManager: LavalinkManager | null;
|
|
45
42
|
constructor(LavalinkManager?: LavalinkManager);
|
|
46
|
-
buildTrack(data:
|
|
43
|
+
buildTrack(data: LavalinkTrack | Track, requester: unknown): Track;
|
|
44
|
+
/**
|
|
45
|
+
* Builds a UnresolvedTrack to be resolved before being played .
|
|
46
|
+
* @param query
|
|
47
|
+
* @param requester
|
|
48
|
+
*/
|
|
49
|
+
buildUnresolvedTrack(query: UnresolvedQuery | UnresolvedTrack, requester: unknown): UnresolvedTrack;
|
|
47
50
|
/**
|
|
48
51
|
* Validate if a data is equal to a node
|
|
49
52
|
* @param data
|
|
@@ -69,15 +72,9 @@ export declare class ManagerUitls {
|
|
|
69
72
|
* Checks if the provided argument is a valid UnresolvedTrack.
|
|
70
73
|
* @param track
|
|
71
74
|
*/
|
|
72
|
-
isUnresolvedTrackQuery(data:
|
|
73
|
-
getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track>;
|
|
74
|
-
|
|
75
|
-
* Builds a UnresolvedTrack to be resolved before being played .
|
|
76
|
-
* @param query
|
|
77
|
-
* @param requester
|
|
78
|
-
*/
|
|
79
|
-
buildUnresolvedTrack(query: UnresolvedQuery | UnresolvedTrack, requester: unknown): UnresolvedTrack;
|
|
80
|
-
validatedQueryString(node: LavalinkNode, queryString: string): void;
|
|
75
|
+
isUnresolvedTrackQuery(data: UnresolvedQuery | any): boolean;
|
|
76
|
+
getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track | undefined>;
|
|
77
|
+
validateQueryString(node: LavalinkNode, queryString: string): void;
|
|
81
78
|
validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;
|
|
82
79
|
}
|
|
83
80
|
/**
|
package/package.json
CHANGED