aqualink 1.8.0 → 1.8.1-beta2
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/build/index.d.ts +80 -0
- package/build/index.js +9 -9
- package/build/structures/Aqua.js +9 -6
- package/build/structures/Connection.js +74 -67
- package/build/structures/Filters.js +3 -1
- package/build/structures/Node.js +4 -2
- package/build/structures/Player.js +6 -4
- package/build/structures/Plugins.js +2 -1
- package/build/structures/Queue.js +2 -2
- package/build/structures/Rest.js +70 -61
- package/build/structures/Track.js +9 -23
- package/package.json +2 -1
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
declare module "AquaLink" {
|
|
2
|
+
export class Aqua {
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} client - The client instance.
|
|
5
|
+
* @param {Array<Object>} nodes - An array of node configurations.
|
|
6
|
+
* @param {Object} options - Configuration options for Aqua.
|
|
7
|
+
* @param {Function} options.send - Function to send data.
|
|
8
|
+
* @param {string} [options.defaultSearchPlatform="ytsearch"] - Default search platform.
|
|
9
|
+
* @param {string} [options.restVersion="v4"] - Version of the REST API.
|
|
10
|
+
* @param {Array<Object>} [options.plugins=[]] - Plugins to load.
|
|
11
|
+
* @param {boolean} [options.autoResume=false] - Automatically resume tracks on reconnect.
|
|
12
|
+
* @param {boolean} [options.infiniteReconnects=false] - Reconnect infinitely.
|
|
13
|
+
*/
|
|
14
|
+
constructor(client: any, nodes: Array<any>, options?: { [key: string]: any });
|
|
15
|
+
init(clientId: string): this;
|
|
16
|
+
createNode(options: { [key: string]: any }): Node;
|
|
17
|
+
createPlayer(node: Node, options: { [key: string]: any }): Player;
|
|
18
|
+
destroyPlayer(guildId: string): Promise<void>;
|
|
19
|
+
resolve(options: { query: string, source?: string, requester?: any, nodes?: any }): Promise<any>;
|
|
20
|
+
updateVoiceState(data: { d: any, t: string }): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Connection {
|
|
24
|
+
constructor(player: Player);
|
|
25
|
+
setServerUpdate(data: { endpoint: string, token: string }): void;
|
|
26
|
+
setStateUpdate(data: { channel_id: string, session_id: string, self_deaf: boolean, self_mute: boolean }): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class Filters {
|
|
30
|
+
constructor(player: Player, options?: { [key: string]: any });
|
|
31
|
+
setEqualizer(bands: Array<any>): Promise<void>;
|
|
32
|
+
setKaraoke(enabled: boolean, options?: { [key: string]: any }): Promise<void>;
|
|
33
|
+
clearFilters(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class Node {
|
|
37
|
+
constructor(aqua: Aqua, connOptions: { [key: string]: any }, options?: { [key: string]: any });
|
|
38
|
+
connect(): Promise<void>;
|
|
39
|
+
getStats(): Promise<any>;
|
|
40
|
+
destroy(clean?: boolean): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Player {
|
|
44
|
+
constructor(aqua: Aqua, nodes: any, options?: { [key: string]: any });
|
|
45
|
+
play(): Promise<void>;
|
|
46
|
+
pause(paused: boolean): this;
|
|
47
|
+
skip(): Promise<void>;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class Plugin {
|
|
52
|
+
constructor(name: string);
|
|
53
|
+
load(aqua: Aqua): void;
|
|
54
|
+
unload(aqua: Aqua): void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class Queue extends Array {
|
|
58
|
+
add(track: any): this;
|
|
59
|
+
remove(track: any): void;
|
|
60
|
+
clear(): void;
|
|
61
|
+
shuffle(): void;
|
|
62
|
+
peek(): any;
|
|
63
|
+
toArray(): Array<any>;
|
|
64
|
+
at(index: number): any;
|
|
65
|
+
dequeue(): any;
|
|
66
|
+
isEmpty(): boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class Rest {
|
|
70
|
+
constructor(aqua: Aqua, options: { [key: string]: any });
|
|
71
|
+
makeRequest(method: string, endpoint: string, body?: any): Promise<any>;
|
|
72
|
+
getPlayers(): Promise<any>;
|
|
73
|
+
destroyPlayer(guildId: string): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class Track {
|
|
77
|
+
constructor(data: { [key: string]: any }, requester: Player, nodes: Node);
|
|
78
|
+
resolve(aqua: Aqua): Promise<Track | null>;
|
|
79
|
+
}
|
|
80
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
1
|
+
const Connection = require("./structures/Connection");
|
|
2
|
+
const Filters = require("./structures/Filters");
|
|
3
|
+
const Node = require("./structures/Node");
|
|
4
|
+
const Aqua = require("./structures/Aqua");
|
|
5
|
+
const Player = require("./structures/Player");
|
|
6
|
+
const Plugin = require("./structures/Plugins");
|
|
7
|
+
const Queue = require("./structures/Queue");
|
|
8
|
+
const Rest = require("./structures/Rest");
|
|
9
|
+
const Track = require("./structures/Track");
|
|
10
10
|
|
|
11
11
|
module.exports = { Connection, Filters, Node, Aqua, Player, Plugin, Queue, Rest, Track };
|
package/build/structures/Aqua.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { EventEmitter } = require("node:events");
|
|
4
|
+
const Node = require("./Node");
|
|
5
|
+
const Player = require("./Player");
|
|
6
|
+
const Track = require("./Track");
|
|
5
7
|
const { version: pkgVersion } = require("../../package.json");
|
|
6
8
|
const URL_REGEX = /^https?:\/\//;
|
|
7
9
|
|
|
@@ -111,12 +113,13 @@ class Aqua extends EventEmitter {
|
|
|
111
113
|
updateVoiceState({ d, t }) {
|
|
112
114
|
const player = this.players.get(d.guild_id);
|
|
113
115
|
if (!player) return;
|
|
116
|
+
|
|
114
117
|
if (t === "VOICE_SERVER_UPDATE" || (t === "VOICE_STATE_UPDATE" && d.user_id === this.clientId)) {
|
|
115
118
|
const updateMethod = t === "VOICE_SERVER_UPDATE" ? "setServerUpdate" : "setStateUpdate";
|
|
116
119
|
if (player.connection && typeof player.connection[updateMethod] === "function") {
|
|
117
120
|
player.connection[updateMethod](d);
|
|
118
121
|
}
|
|
119
|
-
if (d.
|
|
122
|
+
if (d.channel_id === null) {
|
|
120
123
|
this.cleanupPlayer(player);
|
|
121
124
|
}
|
|
122
125
|
}
|
|
@@ -273,4 +276,4 @@ class Aqua extends EventEmitter {
|
|
|
273
276
|
}
|
|
274
277
|
}
|
|
275
278
|
|
|
276
|
-
module.exports =
|
|
279
|
+
module.exports = Aqua
|
|
@@ -1,75 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
class Connection {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
constructor(player) {
|
|
5
|
+
this.playerRef = new WeakRef(player);
|
|
6
|
+
const { voiceChannel, guildId, aqua, nodes } = player;
|
|
7
|
+
this.voice = {
|
|
8
|
+
sessionId: null,
|
|
9
|
+
endpoint: null,
|
|
10
|
+
token: null
|
|
11
|
+
};
|
|
12
|
+
this.region = null;
|
|
13
|
+
this.selfDeaf = false;
|
|
14
|
+
this.selfMute = false;
|
|
15
|
+
this.voiceChannel = voiceChannel;
|
|
16
|
+
this.guildId = guildId;
|
|
17
|
+
this.aqua = aqua;
|
|
18
|
+
this.nodes = nodes;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setServerUpdate(data = {}) {
|
|
22
|
+
const { endpoint, token } = data;
|
|
23
|
+
|
|
24
|
+
if (!endpoint) {
|
|
25
|
+
throw new Error("Missing 'endpoint' property");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const newRegion = endpoint.split('.')[0];
|
|
29
|
+
if (this.region !== newRegion) {
|
|
30
|
+
this.voice.endpoint = endpoint;
|
|
31
|
+
this.voice.token = token;
|
|
32
|
+
const prevRegion = this.region;
|
|
33
|
+
this.region = newRegion;
|
|
34
|
+
|
|
35
|
+
const message = prevRegion
|
|
36
|
+
? `Changed Voice Region from ${prevRegion} to ${newRegion}`
|
|
37
|
+
: `Voice Server: ${newRegion}`;
|
|
38
|
+
|
|
39
|
+
this.aqua.emit("debug", `[Player ${this.guildId} - CONNECTION] ${message}`);
|
|
40
|
+
this._updatePlayerVoiceData();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
18
43
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const regionMatch = endpoint.match(/^([a-zA-Z]+)/);
|
|
25
|
-
if (!regionMatch) return;
|
|
26
|
-
const newRegion = regionMatch[1];
|
|
44
|
+
setStateUpdate({ channel_id: channelId, session_id: sessionId, self_deaf: selfDeaf, self_mute: selfMute } = {}) {
|
|
45
|
+
if (!channelId || !sessionId) {
|
|
46
|
+
this.playerRef.deref()?.destroy();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
27
49
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.region = newRegion;
|
|
33
|
-
this.aqua.emit(
|
|
34
|
-
"debug",
|
|
35
|
-
`[Player ${this.guildId} - CONNECTION] ${
|
|
36
|
-
prevRegion
|
|
37
|
-
? `Changed Voice Region from ${prevRegion} to ${newRegion}`
|
|
38
|
-
: `Voice Server: ${newRegion}`
|
|
39
|
-
}`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
this._updatePlayerVoiceData();
|
|
43
|
-
}
|
|
50
|
+
if (this.voiceChannel !== channelId) {
|
|
51
|
+
this.aqua.emit("playerMove", this.voiceChannel, channelId);
|
|
52
|
+
this.voiceChannel = channelId;
|
|
53
|
+
}
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
this.selfDeaf = selfDeaf;
|
|
56
|
+
this.selfMute = selfMute;
|
|
57
|
+
this.voice.sessionId = sessionId;
|
|
58
|
+
}
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
this.selfDeaf = selfDeaf;
|
|
54
|
-
this.selfMute = selfMute;
|
|
55
|
-
this.voice.sessionId = sessionId;
|
|
56
|
-
}
|
|
60
|
+
async _updatePlayerVoiceData() {
|
|
61
|
+
const player = this.playerRef.deref();
|
|
62
|
+
if (!player) return;
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
try {
|
|
65
|
+
await this.nodes.rest.updatePlayer({
|
|
66
|
+
guildId: this.guildId,
|
|
67
|
+
data: {
|
|
68
|
+
voice: this.voice,
|
|
69
|
+
volume: player.volume
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
} catch (err) {
|
|
73
|
+
this.aqua.emit("apiError", "updatePlayer", {
|
|
74
|
+
error: err,
|
|
75
|
+
guildId: this.guildId,
|
|
76
|
+
voiceData: this.voice
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
module.exports =
|
|
82
|
+
module.exports = Connection;
|
package/build/structures/Node.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
const WebSocket = require("ws");
|
|
2
|
-
const
|
|
4
|
+
const Rest = require("./Rest");
|
|
3
5
|
|
|
4
6
|
class Node {
|
|
5
7
|
#ws = null;
|
|
@@ -272,4 +274,4 @@ class Node {
|
|
|
272
274
|
}
|
|
273
275
|
}
|
|
274
276
|
|
|
275
|
-
module.exports =
|
|
277
|
+
module.exports = Node
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
const { EventEmitter } = require("events");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
4
|
+
const Connection = require("./Connection");
|
|
5
|
+
const Queue = require("./Queue");
|
|
6
|
+
const Filters = require("./Filters");
|
|
5
7
|
|
|
6
8
|
class Player extends EventEmitter {
|
|
7
9
|
static LOOP_MODES = Object.freeze({
|
|
@@ -347,4 +349,4 @@ class Player extends EventEmitter {
|
|
|
347
349
|
}
|
|
348
350
|
}
|
|
349
351
|
|
|
350
|
-
module.exports =
|
|
352
|
+
module.exports = Player
|
package/build/structures/Rest.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const { request } = require("undici");
|
|
2
3
|
|
|
3
4
|
class Rest {
|
|
4
|
-
constructor(aqua,
|
|
5
|
+
constructor(aqua, { secure, host, port, sessionId, password }) {
|
|
5
6
|
this.aqua = aqua;
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.version = options.restVersion || "v4";
|
|
10
|
-
this.calls = 0;
|
|
7
|
+
this.sessionId = sessionId;
|
|
8
|
+
this.version = "v4";
|
|
9
|
+
this.baseUrl = `http${secure ? "s" : ""}://${host}:${port}`;
|
|
11
10
|
this.headers = {
|
|
12
11
|
"Content-Type": "application/json",
|
|
13
|
-
Authorization:
|
|
12
|
+
Authorization: password,
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -22,90 +21,100 @@ class Rest {
|
|
|
22
21
|
const options = {
|
|
23
22
|
method,
|
|
24
23
|
headers: this.headers,
|
|
24
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const response = await request(`${this.url}${endpoint}`, options);
|
|
32
|
-
if (response.statusCode === 204) return null;
|
|
33
|
-
this.calls++;
|
|
34
|
-
const data = await response.body.json();
|
|
35
|
-
this.aqua.emit("apiResponse", endpoint, {
|
|
36
|
-
status: response.statusCode,
|
|
37
|
-
headers: response.headers,
|
|
38
|
-
});
|
|
39
|
-
response.body.destroy();
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
27
|
+
try {
|
|
28
|
+
const { statusCode, headers, body: responseBody } = await request(`${this.baseUrl}${endpoint}`, options);
|
|
29
|
+
this.aqua.emit("apiResponse", endpoint, { status: statusCode, headers: headers });
|
|
42
30
|
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
if (statusCode === 204) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
45
34
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
const data = await responseBody.text();
|
|
36
|
+
return data ? JSON.parse(data) : null;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`Request to ${endpoint} failed: ${error.message}`);
|
|
49
39
|
}
|
|
40
|
+
}
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
buildEndpoint(...segments) {
|
|
43
|
+
const validSegments = segments.filter(segment => segment && segment.trim());
|
|
44
|
+
return '/' + validSegments.join('/');
|
|
45
|
+
}
|
|
46
|
+
validateSessionId() {
|
|
47
|
+
if (!this.sessionId) {
|
|
48
|
+
throw new Error("Session ID is not set.");
|
|
55
49
|
}
|
|
50
|
+
}
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
52
|
+
updatePlayer({ guildId, data }) {
|
|
53
|
+
if ((data.track?.encoded && data.track?.identifier) || (data.encodedTrack && data.identifier)) {
|
|
54
|
+
throw new Error("Cannot provide both 'encoded' and 'identifier' for track");
|
|
55
|
+
}
|
|
56
|
+
this.validateSessionId();
|
|
57
|
+
const endpoint = this.buildEndpoint(this.version, "sessions", this.sessionId, "players", guildId) + "?noReplace=false";
|
|
58
|
+
return this.makeRequest("PATCH", endpoint, data);
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
getPlayers() {
|
|
65
|
-
|
|
61
|
+
async getPlayers() {
|
|
62
|
+
this.validateSessionId();
|
|
63
|
+
const endpoint = this.buildEndpoint(this.version, "sessions", this.sessionId, "players");
|
|
64
|
+
return this.makeRequest("GET", endpoint);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
destroyPlayer(guildId) {
|
|
69
|
-
|
|
67
|
+
async destroyPlayer(guildId) {
|
|
68
|
+
this.validateSessionId();
|
|
69
|
+
const endpoint = this.buildEndpoint(this.version, "sessions", this.sessionId, "players", guildId);
|
|
70
|
+
return this.makeRequest("DELETE", endpoint);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
getTracks(identifier) {
|
|
73
|
-
|
|
73
|
+
async getTracks(identifier) {
|
|
74
|
+
const endpoint = `/${this.version}/loadtracks?identifier=${encodeURIComponent(identifier)}`;
|
|
75
|
+
return this.makeRequest("GET", endpoint);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
decodeTrack(track) {
|
|
77
|
-
|
|
78
|
+
async decodeTrack(track) {
|
|
79
|
+
const endpoint = `/${this.version}/decodetrack?encodedTrack=${encodeURIComponent(track)}`;
|
|
80
|
+
return this.makeRequest("GET", endpoint);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
decodeTracks(tracks) {
|
|
81
|
-
|
|
83
|
+
async decodeTracks(tracks) {
|
|
84
|
+
const endpoint = `/${this.version}/decodetracks`;
|
|
85
|
+
return this.makeRequest("POST", endpoint, tracks);
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
getStats() {
|
|
85
|
-
|
|
88
|
+
async getStats() {
|
|
89
|
+
const endpoint = `/${this.version}/stats/all`;
|
|
90
|
+
return this.makeRequest("GET", endpoint);
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
getInfo() {
|
|
89
|
-
|
|
93
|
+
async getInfo() {
|
|
94
|
+
const endpoint = `/${this.version}/info`;
|
|
95
|
+
return this.makeRequest("GET", endpoint);
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
getRoutePlannerStatus() {
|
|
93
|
-
|
|
98
|
+
async getRoutePlannerStatus() {
|
|
99
|
+
const endpoint = `/${this.version}/routeplanner/status`;
|
|
100
|
+
return this.makeRequest("GET", endpoint);
|
|
94
101
|
}
|
|
95
102
|
|
|
96
|
-
getRoutePlannerAddress(address) {
|
|
97
|
-
|
|
103
|
+
async getRoutePlannerAddress(address) {
|
|
104
|
+
const endpoint = `/${this.version}/routeplanner/free/address`;
|
|
105
|
+
return this.makeRequest("POST", endpoint, { address });
|
|
98
106
|
}
|
|
107
|
+
|
|
99
108
|
async getLyrics({ track }) {
|
|
100
109
|
if (track.search) {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
110
|
+
const endpoint = `/v4/lyrics/search?query=${encodeURIComponent(track.encoded.info.title)}&source=genius`;
|
|
111
|
+
const res = await this.makeRequest("GET", endpoint);
|
|
112
|
+
if (res) return res;
|
|
105
113
|
}
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
this.validateSessionId();
|
|
115
|
+
const endpoint = this.buildEndpoint(this.version, "sessions", this.sessionId, "players", track.guild_id, "track", "lyrics") + "?skipTrackSource=false";
|
|
116
|
+
return this.makeRequest("GET", endpoint);
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
|
|
111
|
-
module.exports =
|
|
120
|
+
module.exports = Rest;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
const { getImageUrl } = require("../handlers/fetchImage");
|
|
2
3
|
/**
|
|
3
4
|
* @typedef {import("../Aqua")} Aqua
|
|
@@ -10,9 +11,9 @@ class Track {
|
|
|
10
11
|
* @param {Player} requester
|
|
11
12
|
* @param {Node} nodes
|
|
12
13
|
*/
|
|
13
|
-
constructor(data, requester, nodes) {
|
|
14
|
-
const { info = {}, encoded = null, playlist = null } = data
|
|
15
|
-
this.info =
|
|
14
|
+
constructor(data = {}, requester, nodes) {
|
|
15
|
+
const { info = {}, encoded = null, playlist = null } = data;
|
|
16
|
+
this.info = {
|
|
16
17
|
identifier: info.identifier || '',
|
|
17
18
|
isSeekable: !!info.isSeekable,
|
|
18
19
|
author: info.author || '',
|
|
@@ -22,22 +23,20 @@ class Track {
|
|
|
22
23
|
uri: info.uri || '',
|
|
23
24
|
sourceName: info.sourceName || '',
|
|
24
25
|
artworkUrl: info.artworkUrl || ''
|
|
25
|
-
}
|
|
26
|
+
};
|
|
26
27
|
this.track = encoded;
|
|
27
28
|
this.playlist = playlist;
|
|
28
29
|
this.requester = requester;
|
|
29
30
|
this.nodes = nodes;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
32
|
/**
|
|
33
33
|
* @param {string} thumbnail
|
|
34
34
|
* @returns {string|null}
|
|
35
35
|
*/
|
|
36
36
|
resolveThumbnail(thumbnail) {
|
|
37
37
|
if (!thumbnail) return null;
|
|
38
|
-
return
|
|
38
|
+
return getImageUrl(thumbnail);
|
|
39
39
|
}
|
|
40
|
-
|
|
41
40
|
/**
|
|
42
41
|
* @param {Aqua} aqua
|
|
43
42
|
* @returns {Promise<Track|null>}
|
|
@@ -45,7 +44,6 @@ class Track {
|
|
|
45
44
|
async resolve(aqua) {
|
|
46
45
|
const searchPlatform = aqua?.options?.defaultSearchPlatform;
|
|
47
46
|
if (!searchPlatform) return null;
|
|
48
|
-
|
|
49
47
|
try {
|
|
50
48
|
const query = `${this.info.author} - ${this.info.title}`;
|
|
51
49
|
const result = await aqua.resolve({
|
|
@@ -54,41 +52,29 @@ class Track {
|
|
|
54
52
|
requester: this.requester,
|
|
55
53
|
node: this.nodes
|
|
56
54
|
});
|
|
57
|
-
|
|
58
55
|
if (!result?.tracks?.length) return null;
|
|
59
|
-
|
|
60
56
|
const track = this._findMatchingTrack(result.tracks);
|
|
61
57
|
if (!track) return null;
|
|
62
|
-
|
|
63
58
|
this.info.identifier = track.info.identifier;
|
|
64
59
|
this.track = track.track;
|
|
65
60
|
this.playlist = track.playlist || null;
|
|
66
|
-
|
|
67
61
|
return this;
|
|
68
62
|
} catch (error) {
|
|
69
63
|
console.error("Error resolving track:", error);
|
|
70
64
|
return null;
|
|
71
65
|
}
|
|
72
66
|
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @private
|
|
76
|
-
*/
|
|
77
67
|
_findMatchingTrack(tracks) {
|
|
78
68
|
const { author, title, length } = this.info;
|
|
79
|
-
|
|
80
69
|
for (const track of tracks) {
|
|
81
70
|
const tInfo = track.info;
|
|
82
|
-
|
|
83
|
-
if (author && title && author === tInfo.author && title === tInfo.title) {
|
|
71
|
+
if (author === tInfo.author && title === tInfo.title) {
|
|
84
72
|
if (!length || Math.abs(tInfo.length - length) <= 2000) {
|
|
85
73
|
return track;
|
|
86
74
|
}
|
|
87
75
|
}
|
|
88
76
|
}
|
|
89
|
-
|
|
90
|
-
return tracks[0];
|
|
77
|
+
return null;
|
|
91
78
|
}
|
|
92
79
|
}
|
|
93
|
-
|
|
94
|
-
module.exports = { Track };
|
|
80
|
+
module.exports = Track;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aqualink",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1-beta2",
|
|
4
4
|
"description": "An Lavalink wrapper, focused in speed, performance, and features, Based in Riffy!",
|
|
5
5
|
"main": "build/index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"start": "node ./build/index.js"
|
|
8
9
|
},
|