yukimu 2.0.8 → 3.0.0
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/BitrateOptimizer.d.ts +52 -0
- package/dist/BitrateOptimizer.d.ts.map +1 -0
- package/dist/BitrateOptimizer.js +115 -0
- package/dist/BitrateOptimizer.js.map +1 -0
- package/dist/ConnectionPool.d.ts +84 -0
- package/dist/ConnectionPool.d.ts.map +1 -0
- package/dist/ConnectionPool.js +203 -0
- package/dist/ConnectionPool.js.map +1 -0
- package/dist/Constants.d.ts +47 -0
- package/dist/Constants.d.ts.map +1 -0
- package/dist/Constants.js +170 -0
- package/dist/Constants.js.map +1 -0
- package/dist/Logger.d.ts +22 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/Logger.js +74 -0
- package/dist/Logger.js.map +1 -0
- package/dist/Node.d.ts +61 -0
- package/dist/Node.d.ts.map +1 -0
- package/dist/Node.js +446 -0
- package/dist/Node.js.map +1 -0
- package/dist/Player.d.ts +143 -0
- package/dist/Player.d.ts.map +1 -0
- package/dist/Player.js +574 -0
- package/dist/Player.js.map +1 -0
- package/dist/Plugin.d.ts +25 -0
- package/dist/Plugin.d.ts.map +1 -0
- package/dist/Plugin.js +15 -0
- package/dist/Plugin.js.map +1 -0
- package/dist/Queue.d.ts +89 -0
- package/dist/Queue.d.ts.map +1 -0
- package/dist/Queue.js +188 -0
- package/dist/Queue.js.map +1 -0
- package/dist/Resolver.d.ts +68 -0
- package/dist/Resolver.d.ts.map +1 -0
- package/dist/Resolver.js +361 -0
- package/dist/Resolver.js.map +1 -0
- package/dist/Rest.d.ts +46 -0
- package/dist/Rest.d.ts.map +1 -0
- package/dist/Rest.js +247 -0
- package/dist/Rest.js.map +1 -0
- package/dist/TrackCache.d.ts +41 -0
- package/dist/TrackCache.d.ts.map +1 -0
- package/dist/TrackCache.js +144 -0
- package/dist/TrackCache.js.map +1 -0
- package/dist/WsQueue.d.ts +41 -0
- package/dist/WsQueue.d.ts.map +1 -0
- package/dist/WsQueue.js +116 -0
- package/dist/WsQueue.js.map +1 -0
- package/dist/Yukimu.d.ts +84 -0
- package/dist/Yukimu.d.ts.map +1 -0
- package/dist/Yukimu.js +290 -0
- package/dist/Yukimu.js.map +1 -0
- package/dist/connector/Connector.d.ts +34 -0
- package/dist/connector/Connector.d.ts.map +1 -0
- package/dist/connector/Connector.js +39 -0
- package/dist/connector/Connector.js.map +1 -0
- package/dist/connector/DiscordJS.d.ts +27 -0
- package/dist/connector/DiscordJS.d.ts.map +1 -0
- package/dist/connector/DiscordJS.js +69 -0
- package/dist/connector/DiscordJS.js.map +1 -0
- package/dist/connector/Eris.d.ts +19 -0
- package/dist/connector/Eris.d.ts.map +1 -0
- package/dist/connector/Eris.js +62 -0
- package/dist/connector/Eris.js.map +1 -0
- package/dist/connector/Oceanic.d.ts +19 -0
- package/dist/connector/Oceanic.d.ts.map +1 -0
- package/dist/connector/Oceanic.js +60 -0
- package/dist/connector/Oceanic.js.map +1 -0
- package/dist/errors/YukimuError.d.ts +51 -0
- package/dist/errors/YukimuError.d.ts.map +1 -0
- package/dist/errors/YukimuError.js +105 -0
- package/dist/errors/YukimuError.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/AutoResume.d.ts +25 -0
- package/dist/plugins/AutoResume.d.ts.map +1 -0
- package/dist/plugins/AutoResume.js +132 -0
- package/dist/plugins/AutoResume.js.map +1 -0
- package/dist/plugins/AutoplayPlugin.d.ts +35 -0
- package/dist/plugins/AutoplayPlugin.d.ts.map +1 -0
- package/dist/plugins/AutoplayPlugin.js +111 -0
- package/dist/plugins/AutoplayPlugin.js.map +1 -0
- package/dist/plugins/InactivityPlugin.d.ts +30 -0
- package/dist/plugins/InactivityPlugin.d.ts.map +1 -0
- package/dist/plugins/InactivityPlugin.js +86 -0
- package/dist/plugins/InactivityPlugin.js.map +1 -0
- package/dist/plugins/PlayerMoved.d.ts +29 -0
- package/dist/plugins/PlayerMoved.d.ts.map +1 -0
- package/dist/plugins/PlayerMoved.js +75 -0
- package/dist/plugins/PlayerMoved.js.map +1 -0
- package/dist/types.d.ts +309 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +4 -4
package/dist/Queue.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Yukimu v2.0.0 — Track Queue with Enhanced Operations */
|
|
2
|
+
import type { Track } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Manages the track queue for a player.
|
|
5
|
+
*
|
|
6
|
+
* Improvements from v1:
|
|
7
|
+
* - Configurable previous history size
|
|
8
|
+
* - New methods: reverse(), removeDuplicates(), swap(), insertAt()
|
|
9
|
+
* - Serialization/deserialization for persistence
|
|
10
|
+
* - Bounds checking with meaningful errors
|
|
11
|
+
* - Proper readonly access
|
|
12
|
+
*/
|
|
13
|
+
export declare class Queue {
|
|
14
|
+
current: Track | null;
|
|
15
|
+
previous: Track[];
|
|
16
|
+
private tracks;
|
|
17
|
+
private readonly maxPreviousSize;
|
|
18
|
+
constructor(maxPreviousSize?: 25);
|
|
19
|
+
/**
|
|
20
|
+
* Add one or more tracks to the queue.
|
|
21
|
+
* @param tracks - Track or array of tracks to add
|
|
22
|
+
* @param position - Optional position to insert at (default: end of queue)
|
|
23
|
+
*/
|
|
24
|
+
add(tracks: Track | Track[], position?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Advance the queue: move current to previous, shift next track to current.
|
|
27
|
+
* @returns The new current track, or null if the queue is empty
|
|
28
|
+
*/
|
|
29
|
+
next(): Track | null;
|
|
30
|
+
/**
|
|
31
|
+
* Remove a track at a specific index.
|
|
32
|
+
* @returns The removed track, or null if index is out of bounds
|
|
33
|
+
*/
|
|
34
|
+
remove(index: number): Track | null;
|
|
35
|
+
/**
|
|
36
|
+
* Remove a range of tracks.
|
|
37
|
+
* @param start - Start index (inclusive)
|
|
38
|
+
* @param end - End index (exclusive)
|
|
39
|
+
*/
|
|
40
|
+
removeRange(start: number, end: number): Track[];
|
|
41
|
+
/** Clear the entire queue, current track, and history */
|
|
42
|
+
clear(): void;
|
|
43
|
+
/** Clear only the queue (keep current track and history) */
|
|
44
|
+
clearQueue(): void;
|
|
45
|
+
/** Shuffle the queue using Fisher-Yates algorithm */
|
|
46
|
+
shuffle(): void;
|
|
47
|
+
/** Move a track from one position to another */
|
|
48
|
+
move(from: number, to: number): boolean;
|
|
49
|
+
/** Swap two tracks in the queue */
|
|
50
|
+
swap(i: number, j: number): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Skip to a specific index in the queue, removing everything before it.
|
|
53
|
+
* @returns The track at the given index, or null if out of bounds
|
|
54
|
+
*/
|
|
55
|
+
skipto(index: number): Track | null;
|
|
56
|
+
/** Reverse the queue order */
|
|
57
|
+
reverse(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Remove duplicate tracks based on their encoded data.
|
|
60
|
+
* Keeps the first occurrence.
|
|
61
|
+
*/
|
|
62
|
+
removeDuplicates(): number;
|
|
63
|
+
/** Peek at the next N tracks without modifying the queue */
|
|
64
|
+
peek(count?: number): Track[];
|
|
65
|
+
/** Find the first track matching a predicate */
|
|
66
|
+
find(predicate: (track: Track) => boolean): Track | undefined;
|
|
67
|
+
/** Filter tracks by a predicate */
|
|
68
|
+
filter(predicate: (track: Track) => boolean): Track[];
|
|
69
|
+
/** Get the index of a track by its encoded data */
|
|
70
|
+
indexOf(encoded: string): number;
|
|
71
|
+
/** Serialize the queue state for persistence */
|
|
72
|
+
toJSON(): {
|
|
73
|
+
current: Track | null;
|
|
74
|
+
tracks: Track[];
|
|
75
|
+
previous: Track[];
|
|
76
|
+
};
|
|
77
|
+
/** Restore queue state from serialized data */
|
|
78
|
+
fromJSON(data: {
|
|
79
|
+
current?: Track | null;
|
|
80
|
+
tracks?: Track[];
|
|
81
|
+
previous?: Track[];
|
|
82
|
+
}): void;
|
|
83
|
+
get size(): number;
|
|
84
|
+
get isEmpty(): boolean;
|
|
85
|
+
get totalDuration(): number;
|
|
86
|
+
/** Readonly access to the underlying track array */
|
|
87
|
+
get list(): readonly Track[];
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=Queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAG3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;;;;GASG;AACH,qBAAa,KAAK;IACT,OAAO,EAAE,KAAK,GAAG,IAAI,CAAQ;IAC7B,QAAQ,EAAE,KAAK,EAAE,CAAM;IAC9B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,eAAe,KAAiC;IAI5D;;;;OAIG;IACI,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;IAW5D;;;OAGG;IACI,IAAI,IAAI,KAAK,GAAG,IAAI;IAW3B;;;OAGG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAM1C;;;;OAIG;IACI,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,EAAE;IAOvD,yDAAyD;IAClD,KAAK,IAAI,IAAI;IAMpB,4DAA4D;IACrD,UAAU,IAAI,IAAI;IAIzB,qDAAqD;IAC9C,OAAO,IAAI,IAAI;IAOtB,gDAAgD;IACzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAQ9C,mCAAmC;IAC5B,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAM1C;;;OAGG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAM1C,8BAA8B;IACvB,OAAO,IAAI,IAAI;IAItB;;;OAGG;IACI,gBAAgB,IAAI,MAAM;IAWjC,4DAA4D;IACrD,IAAI,CAAC,KAAK,SAAK,GAAG,KAAK,EAAE;IAIhC,gDAAgD;IACzC,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GAAG,KAAK,GAAG,SAAS;IAIpE,mCAAmC;IAC5B,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GAAG,KAAK,EAAE;IAI5D,mDAAmD;IAC5C,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAMvC,gDAAgD;IACzC,MAAM,IAAI;QACf,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC;QACtB,MAAM,EAAE,KAAK,EAAE,CAAC;QAChB,QAAQ,EAAE,KAAK,EAAE,CAAC;KACnB;IAQD,+CAA+C;IACxC,QAAQ,CAAC,IAAI,EAAE;QACpB,OAAO,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;QACjB,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;KACpB,GAAG,IAAI;IAQR,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,oDAAoD;IACpD,IAAI,IAAI,IAAI,SAAS,KAAK,EAAE,CAE3B;CACF"}
|
package/dist/Queue.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Yukimu v2.0.0 — Track Queue with Enhanced Operations */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Queue = void 0;
|
|
5
|
+
const Constants_1 = require("./Constants");
|
|
6
|
+
/**
|
|
7
|
+
* Manages the track queue for a player.
|
|
8
|
+
*
|
|
9
|
+
* Improvements from v1:
|
|
10
|
+
* - Configurable previous history size
|
|
11
|
+
* - New methods: reverse(), removeDuplicates(), swap(), insertAt()
|
|
12
|
+
* - Serialization/deserialization for persistence
|
|
13
|
+
* - Bounds checking with meaningful errors
|
|
14
|
+
* - Proper readonly access
|
|
15
|
+
*/
|
|
16
|
+
class Queue {
|
|
17
|
+
current = null;
|
|
18
|
+
previous = [];
|
|
19
|
+
tracks = [];
|
|
20
|
+
maxPreviousSize;
|
|
21
|
+
constructor(maxPreviousSize = Constants_1.DEFAULTS.PREVIOUS_HISTORY_SIZE) {
|
|
22
|
+
this.maxPreviousSize = maxPreviousSize;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Add one or more tracks to the queue.
|
|
26
|
+
* @param tracks - Track or array of tracks to add
|
|
27
|
+
* @param position - Optional position to insert at (default: end of queue)
|
|
28
|
+
*/
|
|
29
|
+
add(tracks, position) {
|
|
30
|
+
const arr = Array.isArray(tracks) ? tracks : [tracks];
|
|
31
|
+
if (arr.length === 0)
|
|
32
|
+
return;
|
|
33
|
+
if (position !== undefined && position >= 0 && position <= this.tracks.length) {
|
|
34
|
+
this.tracks.splice(position, 0, ...arr);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.tracks.push(...arr);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Advance the queue: move current to previous, shift next track to current.
|
|
42
|
+
* @returns The new current track, or null if the queue is empty
|
|
43
|
+
*/
|
|
44
|
+
next() {
|
|
45
|
+
if (this.current) {
|
|
46
|
+
this.previous.unshift(this.current);
|
|
47
|
+
if (this.previous.length > this.maxPreviousSize) {
|
|
48
|
+
this.previous.length = this.maxPreviousSize;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.current = this.tracks.shift() ?? null;
|
|
52
|
+
return this.current;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Remove a track at a specific index.
|
|
56
|
+
* @returns The removed track, or null if index is out of bounds
|
|
57
|
+
*/
|
|
58
|
+
remove(index) {
|
|
59
|
+
if (index < 0 || index >= this.tracks.length)
|
|
60
|
+
return null;
|
|
61
|
+
const [removed] = this.tracks.splice(index, 1);
|
|
62
|
+
return removed ?? null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Remove a range of tracks.
|
|
66
|
+
* @param start - Start index (inclusive)
|
|
67
|
+
* @param end - End index (exclusive)
|
|
68
|
+
*/
|
|
69
|
+
removeRange(start, end) {
|
|
70
|
+
if (start < 0)
|
|
71
|
+
start = 0;
|
|
72
|
+
if (end > this.tracks.length)
|
|
73
|
+
end = this.tracks.length;
|
|
74
|
+
if (start >= end)
|
|
75
|
+
return [];
|
|
76
|
+
return this.tracks.splice(start, end - start);
|
|
77
|
+
}
|
|
78
|
+
/** Clear the entire queue, current track, and history */
|
|
79
|
+
clear() {
|
|
80
|
+
this.tracks = [];
|
|
81
|
+
this.current = null;
|
|
82
|
+
this.previous = [];
|
|
83
|
+
}
|
|
84
|
+
/** Clear only the queue (keep current track and history) */
|
|
85
|
+
clearQueue() {
|
|
86
|
+
this.tracks = [];
|
|
87
|
+
}
|
|
88
|
+
/** Shuffle the queue using Fisher-Yates algorithm */
|
|
89
|
+
shuffle() {
|
|
90
|
+
for (let i = this.tracks.length - 1; i > 0; i--) {
|
|
91
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
92
|
+
[this.tracks[i], this.tracks[j]] = [this.tracks[j], this.tracks[i]];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Move a track from one position to another */
|
|
96
|
+
move(from, to) {
|
|
97
|
+
if (from < 0 || to < 0 || from >= this.tracks.length || to >= this.tracks.length)
|
|
98
|
+
return false;
|
|
99
|
+
const [track] = this.tracks.splice(from, 1);
|
|
100
|
+
if (!track)
|
|
101
|
+
return false;
|
|
102
|
+
this.tracks.splice(to, 0, track);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
/** Swap two tracks in the queue */
|
|
106
|
+
swap(i, j) {
|
|
107
|
+
if (i < 0 || j < 0 || i >= this.tracks.length || j >= this.tracks.length)
|
|
108
|
+
return false;
|
|
109
|
+
[this.tracks[i], this.tracks[j]] = [this.tracks[j], this.tracks[i]];
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Skip to a specific index in the queue, removing everything before it.
|
|
114
|
+
* @returns The track at the given index, or null if out of bounds
|
|
115
|
+
*/
|
|
116
|
+
skipto(index) {
|
|
117
|
+
if (index < 0 || index >= this.tracks.length)
|
|
118
|
+
return null;
|
|
119
|
+
this.tracks.splice(0, index);
|
|
120
|
+
return this.next();
|
|
121
|
+
}
|
|
122
|
+
/** Reverse the queue order */
|
|
123
|
+
reverse() {
|
|
124
|
+
this.tracks.reverse();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Remove duplicate tracks based on their encoded data.
|
|
128
|
+
* Keeps the first occurrence.
|
|
129
|
+
*/
|
|
130
|
+
removeDuplicates() {
|
|
131
|
+
const seen = new Set();
|
|
132
|
+
const before = this.tracks.length;
|
|
133
|
+
this.tracks = this.tracks.filter((track) => {
|
|
134
|
+
if (seen.has(track.encoded))
|
|
135
|
+
return false;
|
|
136
|
+
seen.add(track.encoded);
|
|
137
|
+
return true;
|
|
138
|
+
});
|
|
139
|
+
return before - this.tracks.length;
|
|
140
|
+
}
|
|
141
|
+
/** Peek at the next N tracks without modifying the queue */
|
|
142
|
+
peek(count = 10) {
|
|
143
|
+
return this.tracks.slice(0, count);
|
|
144
|
+
}
|
|
145
|
+
/** Find the first track matching a predicate */
|
|
146
|
+
find(predicate) {
|
|
147
|
+
return this.tracks.find(predicate);
|
|
148
|
+
}
|
|
149
|
+
/** Filter tracks by a predicate */
|
|
150
|
+
filter(predicate) {
|
|
151
|
+
return this.tracks.filter(predicate);
|
|
152
|
+
}
|
|
153
|
+
/** Get the index of a track by its encoded data */
|
|
154
|
+
indexOf(encoded) {
|
|
155
|
+
return this.tracks.findIndex((t) => t.encoded === encoded);
|
|
156
|
+
}
|
|
157
|
+
// ─── Serialization ────────────────────────────────────────────────────
|
|
158
|
+
/** Serialize the queue state for persistence */
|
|
159
|
+
toJSON() {
|
|
160
|
+
return {
|
|
161
|
+
current: this.current,
|
|
162
|
+
tracks: [...this.tracks],
|
|
163
|
+
previous: [...this.previous],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Restore queue state from serialized data */
|
|
167
|
+
fromJSON(data) {
|
|
168
|
+
this.current = data.current ?? null;
|
|
169
|
+
this.tracks = data.tracks ? [...data.tracks] : [];
|
|
170
|
+
this.previous = data.previous ? [...data.previous] : [];
|
|
171
|
+
}
|
|
172
|
+
// ─── Getters ──────────────────────────────────────────────────────────
|
|
173
|
+
get size() {
|
|
174
|
+
return this.tracks.length;
|
|
175
|
+
}
|
|
176
|
+
get isEmpty() {
|
|
177
|
+
return this.tracks.length === 0;
|
|
178
|
+
}
|
|
179
|
+
get totalDuration() {
|
|
180
|
+
return this.tracks.reduce((acc, t) => acc + (t.info?.length ?? 0), 0);
|
|
181
|
+
}
|
|
182
|
+
/** Readonly access to the underlying track array */
|
|
183
|
+
get list() {
|
|
184
|
+
return this.tracks;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.Queue = Queue;
|
|
188
|
+
//# sourceMappingURL=Queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Queue.js","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":";AAAA,2DAA2D;;;AAE3D,2CAAuC;AAGvC;;;;;;;;;GASG;AACH,MAAa,KAAK;IACT,OAAO,GAAiB,IAAI,CAAC;IAC7B,QAAQ,GAAY,EAAE,CAAC;IACtB,MAAM,GAAY,EAAE,CAAC;IACZ,eAAe,CAAS;IAEzC,YAAY,eAAe,GAAG,oBAAQ,CAAC,qB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GAAG,IAAI,CAAC,MAAM,CAAC;YACxB,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;SAC7B,CAAC;IACJ,CAAC;IAED,+CAA+C;IACxC,QAAQ,CAAC,IAIf;QACC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1D,CAAC;IAED,yEAAyE;IAEzE,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,oDAAoD;IACpD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAjMD,sBAiMC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Yukimu v2.0.0 — Track Resolver with Retry, Caching & Fallback */
|
|
2
|
+
import type { Yukimu } from "./Yukimu";
|
|
3
|
+
import type { Node } from "./Node";
|
|
4
|
+
import type { SearchResult, SearchSource } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Resolves search queries and URLs into playable tracks.
|
|
7
|
+
*
|
|
8
|
+
* Improvements from v1:
|
|
9
|
+
* - Accepts optional `node` parameter (loads on the correct node for a player)
|
|
10
|
+
* - Search retry with fallback sources
|
|
11
|
+
* - Search result caching
|
|
12
|
+
* - Spotify playlist/album resolution
|
|
13
|
+
* - Spotify token refresh with retry and timeout
|
|
14
|
+
* - Rate limit handling for Spotify API
|
|
15
|
+
*/
|
|
16
|
+
export declare class Resolver {
|
|
17
|
+
private readonly manager;
|
|
18
|
+
private spotifyToken;
|
|
19
|
+
private spotifyExpiry;
|
|
20
|
+
private spotifyRefreshing;
|
|
21
|
+
constructor(manager: Yukimu);
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a query (URL or search term) into tracks.
|
|
24
|
+
*
|
|
25
|
+
* @param query - A URL or search query string
|
|
26
|
+
* @param source - The search source to use (ignored for URLs)
|
|
27
|
+
* @param requester - Optional requester metadata to attach to tracks
|
|
28
|
+
* @param node - Optional specific node to use for loading
|
|
29
|
+
*/
|
|
30
|
+
resolve(query: string, source: SearchSource, requester?: unknown, node?: Node): Promise<SearchResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Internal resolve with an overall timeout and node failover.
|
|
33
|
+
* If the primary node fails or times out, tries a different connected node.
|
|
34
|
+
*/
|
|
35
|
+
private resolveWithTimeout;
|
|
36
|
+
/**
|
|
37
|
+
* Try loading tracks with retries on a specific node.
|
|
38
|
+
* Separated so we can run this against different nodes for failover.
|
|
39
|
+
*/
|
|
40
|
+
private tryLoadWithRetries;
|
|
41
|
+
/**
|
|
42
|
+
* Race a promise against a timeout. Returns null if the timeout fires first.
|
|
43
|
+
*/
|
|
44
|
+
private raceTimeout;
|
|
45
|
+
/**
|
|
46
|
+
* Detect the source platform from a URL.
|
|
47
|
+
*/
|
|
48
|
+
detectSource(url: string): SearchSource | null;
|
|
49
|
+
private trySpotifyFallback;
|
|
50
|
+
private getSpotifyToken;
|
|
51
|
+
private resolveSpotifyMeta;
|
|
52
|
+
private resolveSpotifyPlaylist;
|
|
53
|
+
private resolveSpotifyAlbum;
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a batch of Spotify track metadata concurrently with a concurrency
|
|
56
|
+
* limit. Prevents the sequential N × 15s timeout that caused player freezes.
|
|
57
|
+
*/
|
|
58
|
+
private resolveSpotifyBatch;
|
|
59
|
+
private getLoadNode;
|
|
60
|
+
/**
|
|
61
|
+
* Get a fallback node that is different from the given node.
|
|
62
|
+
* Used when the primary node fails or times out during search.
|
|
63
|
+
*/
|
|
64
|
+
private getFallbackNode;
|
|
65
|
+
private attachRequester;
|
|
66
|
+
private sleep;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=Resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resolver.d.ts","sourceRoot":"","sources":["../src/Resolver.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAGpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAS,MAAM,SAAS,CAAC;AASjE;;;;;;;;;;GAUG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,OAAO,EAAE,MAAM;IAI3B;;;;;;;OAOG;IACU,OAAO,CAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,YAAY,EACpB,SAAS,CAAC,EAAE,OAAO,EACnB,IAAI,CAAC,EAAE,IAAI,GACV,OAAO,CAAC,YAAY,CAAC;IAoBxB;;;OAGG;YACW,kBAAkB;IAiEhC;;;OAGG;YACW,kBAAkB;IAwBhC;;OAEG;IACH,OAAO,CAAC,WAAW;IAWnB;;OAEG;IACI,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;YASvC,kBAAkB;YAkDlB,eAAe;YAiDf,kBAAkB;YA6BlB,sBAAsB;YAqCtB,mBAAmB;IAqCjC;;;OAGG;YACW,mBAAmB;IA6BjC,OAAO,CAAC,WAAW;IAInB;;;OAGG;IACH,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,KAAK;CAGd"}
|