discord-player 5.2.1 → 6.0.0-dev.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/LICENSE +21 -21
- package/README.md +3 -1
- package/dist/Player.js +279 -272
- package/dist/Structures/ExtractorModel.js +19 -24
- package/dist/Structures/Playlist.js +1 -2
- package/dist/Structures/Queue.js +259 -269
- package/dist/Structures/Track.js +11 -14
- package/dist/VoiceInterface/StreamDispatcher.js +34 -38
- package/dist/VoiceInterface/VoiceUtils.js +22 -25
- package/dist/{VolumeTransformer.js → VoiceInterface/VolumeTransformer.js} +35 -9
- package/dist/index.d.ts +12 -7
- package/dist/index.js +3 -1
- package/dist/smoothVolume.js +11 -3
- package/dist/utils/Util.js +34 -1
- package/package.json +28 -31
package/dist/Structures/Queue.js
CHANGED
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.Queue = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const discord_js_1 = require("discord.js");
|
|
7
|
-
const Track_1 =
|
|
7
|
+
const Track_1 = tslib_1.__importDefault(require("./Track"));
|
|
8
8
|
const types_1 = require("../types/types");
|
|
9
|
-
const discord_ytdl_core_1 =
|
|
9
|
+
const discord_ytdl_core_1 = tslib_1.__importDefault(require("discord-ytdl-core"));
|
|
10
10
|
const voice_1 = require("@discordjs/voice");
|
|
11
11
|
const Util_1 = require("../utils/Util");
|
|
12
|
-
const youtube_sr_1 =
|
|
13
|
-
const AudioFilters_1 =
|
|
12
|
+
const youtube_sr_1 = tslib_1.__importDefault(require("youtube-sr"));
|
|
13
|
+
const AudioFilters_1 = tslib_1.__importDefault(require("../utils/AudioFilters"));
|
|
14
14
|
const PlayerError_1 = require("./PlayerError");
|
|
15
15
|
class Queue {
|
|
16
16
|
/**
|
|
@@ -26,7 +26,7 @@ class Queue {
|
|
|
26
26
|
this.playing = false;
|
|
27
27
|
this.metadata = null;
|
|
28
28
|
this.repeatMode = 0;
|
|
29
|
-
this.id = discord_js_1.SnowflakeUtil.generate();
|
|
29
|
+
this.id = discord_js_1.SnowflakeUtil.generate().toString();
|
|
30
30
|
this._streamTime = 0;
|
|
31
31
|
this._cooldownsTimeout = new discord_js_1.Collection();
|
|
32
32
|
this._activeFilters = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
@@ -104,24 +104,23 @@ class Queue {
|
|
|
104
104
|
* @type {Track}
|
|
105
105
|
*/
|
|
106
106
|
get current() {
|
|
107
|
-
|
|
108
|
-
if ((0, tslib_1.__classPrivateFieldGet)(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
107
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
109
108
|
return;
|
|
110
|
-
return
|
|
109
|
+
return this.connection.audioResource?.metadata ?? this.tracks[0];
|
|
111
110
|
}
|
|
112
111
|
/**
|
|
113
112
|
* If this queue is destroyed
|
|
114
113
|
* @type {boolean}
|
|
115
114
|
*/
|
|
116
115
|
get destroyed() {
|
|
117
|
-
return
|
|
116
|
+
return tslib_1.__classPrivateFieldGet(this, _Queue_destroyed, "f");
|
|
118
117
|
}
|
|
119
118
|
/**
|
|
120
119
|
* Returns current track
|
|
121
120
|
* @returns {Track}
|
|
122
121
|
*/
|
|
123
122
|
nowPlaying() {
|
|
124
|
-
if (
|
|
123
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
125
124
|
return;
|
|
126
125
|
return this.current;
|
|
127
126
|
}
|
|
@@ -130,73 +129,72 @@ class Queue {
|
|
|
130
129
|
* @param {GuildChannelResolvable} channel The voice/stage channel
|
|
131
130
|
* @returns {Promise<Queue>}
|
|
132
131
|
*/
|
|
133
|
-
connect(channel) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
async connect(channel) {
|
|
133
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
134
|
+
return;
|
|
135
|
+
const _channel = this.guild.channels.resolve(channel);
|
|
136
|
+
if (![discord_js_1.ChannelType.GuildStageVoice, discord_js_1.ChannelType.GuildVoice].includes(_channel?.type))
|
|
137
|
+
throw new PlayerError_1.PlayerError(`Channel type must be GuildVoice or GuildStageVoice, got ${_channel?.type}!`, PlayerError_1.ErrorStatusCode.INVALID_ARG_TYPE);
|
|
138
|
+
const connection = await this.player.voiceUtils.connect(_channel, {
|
|
139
|
+
deaf: this.options.autoSelfDeaf
|
|
140
|
+
});
|
|
141
|
+
this.connection = connection;
|
|
142
|
+
if (_channel.type === discord_js_1.ChannelType.GuildStageVoice) {
|
|
143
|
+
await _channel.guild.members.me.voice.setSuppressed(false).catch(async () => {
|
|
144
|
+
return await _channel.guild.members.me.voice.setRequestToSpeak(true).catch(Util_1.Util.noop);
|
|
143
145
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
}
|
|
147
|
+
this.connection.on("error", (err) => {
|
|
148
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
149
|
+
return;
|
|
150
|
+
this.player.emit("connectionError", this, err);
|
|
151
|
+
});
|
|
152
|
+
this.connection.on("debug", (msg) => {
|
|
153
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
154
|
+
return;
|
|
155
|
+
this.player.emit("debug", this, msg);
|
|
156
|
+
});
|
|
157
|
+
this.player.emit("connectionCreate", this, this.connection);
|
|
158
|
+
this.connection.on("start", (resource) => {
|
|
159
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
160
|
+
return;
|
|
161
|
+
this.playing = true;
|
|
162
|
+
if (!this._filtersUpdate && resource?.metadata)
|
|
163
|
+
this.player.emit("trackStart", this, resource?.metadata ?? this.current);
|
|
164
|
+
this._filtersUpdate = false;
|
|
165
|
+
});
|
|
166
|
+
this.connection.on("finish", async (resource) => {
|
|
167
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
168
|
+
return;
|
|
169
|
+
this.playing = false;
|
|
170
|
+
if (this._filtersUpdate)
|
|
171
|
+
return;
|
|
172
|
+
this._streamTime = 0;
|
|
173
|
+
if (resource && resource.metadata)
|
|
174
|
+
this.previousTracks.push(resource.metadata);
|
|
175
|
+
this.player.emit("trackEnd", this, resource.metadata);
|
|
176
|
+
if (!this.tracks.length && this.repeatMode === types_1.QueueRepeatMode.OFF) {
|
|
177
|
+
if (this.options.leaveOnEnd)
|
|
178
|
+
this.destroy();
|
|
179
|
+
this.player.emit("queueEnd", this);
|
|
149
180
|
}
|
|
150
|
-
this.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.playing = true;
|
|
166
|
-
if (!this._filtersUpdate && (resource === null || resource === void 0 ? void 0 : resource.metadata))
|
|
167
|
-
this.player.emit("trackStart", this, (_a = resource === null || resource === void 0 ? void 0 : resource.metadata) !== null && _a !== void 0 ? _a : this.current);
|
|
168
|
-
this._filtersUpdate = false;
|
|
169
|
-
});
|
|
170
|
-
this.connection.on("finish", (resource) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
171
|
-
if ((0, tslib_1.__classPrivateFieldGet)(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
172
|
-
return;
|
|
173
|
-
this.playing = false;
|
|
174
|
-
if (this._filtersUpdate)
|
|
175
|
-
return;
|
|
176
|
-
this._streamTime = 0;
|
|
177
|
-
if (resource && resource.metadata)
|
|
178
|
-
this.previousTracks.push(resource.metadata);
|
|
179
|
-
this.player.emit("trackEnd", this, resource.metadata);
|
|
180
|
-
if (!this.tracks.length && this.repeatMode === types_1.QueueRepeatMode.OFF) {
|
|
181
|
-
if (this.options.leaveOnEnd)
|
|
182
|
-
this.destroy();
|
|
183
|
-
this.player.emit("queueEnd", this);
|
|
184
|
-
}
|
|
185
|
-
else if (!this.tracks.length && this.repeatMode === types_1.QueueRepeatMode.AUTOPLAY) {
|
|
186
|
-
this._handleAutoplay(Util_1.Util.last(this.previousTracks));
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
if (this.repeatMode === types_1.QueueRepeatMode.TRACK)
|
|
190
|
-
return void this.play(Util_1.Util.last(this.previousTracks), { immediate: true });
|
|
191
|
-
if (this.repeatMode === types_1.QueueRepeatMode.QUEUE)
|
|
192
|
-
this.tracks.push(Util_1.Util.last(this.previousTracks));
|
|
193
|
-
const nextTrack = this.tracks.shift();
|
|
194
|
-
this.play(nextTrack, { immediate: true });
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
}));
|
|
198
|
-
return this;
|
|
181
|
+
else if (!this.tracks.length && this.repeatMode === types_1.QueueRepeatMode.AUTOPLAY) {
|
|
182
|
+
this._handleAutoplay(Util_1.Util.last(this.previousTracks));
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
if (this.repeatMode === types_1.QueueRepeatMode.TRACK)
|
|
186
|
+
return void this.play(Util_1.Util.last(this.previousTracks), { immediate: true });
|
|
187
|
+
if (this.repeatMode === types_1.QueueRepeatMode.QUEUE)
|
|
188
|
+
this.tracks.push(Util_1.Util.last(this.previousTracks));
|
|
189
|
+
const nextTrack = this.tracks.shift();
|
|
190
|
+
this.play(nextTrack, { immediate: true });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
await this.player.voiceUtils.enterReady(this.connection.voiceConnection, {
|
|
195
|
+
maxTime: this.player.options.connectionTimeout || 30000
|
|
199
196
|
});
|
|
197
|
+
return this;
|
|
200
198
|
}
|
|
201
199
|
/**
|
|
202
200
|
* Destroys this queue
|
|
@@ -204,23 +202,22 @@ class Queue {
|
|
|
204
202
|
* @returns {void}
|
|
205
203
|
*/
|
|
206
204
|
destroy(disconnect = this.options.leaveOnStop) {
|
|
207
|
-
|
|
208
|
-
if ((0, tslib_1.__classPrivateFieldGet)(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
205
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
209
206
|
return;
|
|
210
207
|
if (this.connection)
|
|
211
208
|
this.connection.end();
|
|
212
209
|
if (disconnect)
|
|
213
|
-
|
|
210
|
+
this.connection?.disconnect();
|
|
214
211
|
this.player.queues.delete(this.guild.id);
|
|
215
212
|
this.player.voiceUtils.cache.delete(this.guild.id);
|
|
216
|
-
|
|
213
|
+
tslib_1.__classPrivateFieldSet(this, _Queue_destroyed, true, "f");
|
|
217
214
|
}
|
|
218
215
|
/**
|
|
219
216
|
* Skips current track
|
|
220
217
|
* @returns {boolean}
|
|
221
218
|
*/
|
|
222
219
|
skip() {
|
|
223
|
-
if (
|
|
220
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
224
221
|
return;
|
|
225
222
|
if (!this.connection)
|
|
226
223
|
return false;
|
|
@@ -234,7 +231,7 @@ class Queue {
|
|
|
234
231
|
* @returns {void}
|
|
235
232
|
*/
|
|
236
233
|
addTrack(track) {
|
|
237
|
-
if (
|
|
234
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
238
235
|
return;
|
|
239
236
|
if (!(track instanceof Track_1.default))
|
|
240
237
|
throw new PlayerError_1.PlayerError("invalid track", PlayerError_1.ErrorStatusCode.INVALID_TRACK);
|
|
@@ -246,7 +243,7 @@ class Queue {
|
|
|
246
243
|
* @param {Track[]} tracks Array of tracks to add
|
|
247
244
|
*/
|
|
248
245
|
addTracks(tracks) {
|
|
249
|
-
if (
|
|
246
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
250
247
|
return;
|
|
251
248
|
if (!tracks.every((y) => y instanceof Track_1.default))
|
|
252
249
|
throw new PlayerError_1.PlayerError("invalid track", PlayerError_1.ErrorStatusCode.INVALID_TRACK);
|
|
@@ -259,7 +256,7 @@ class Queue {
|
|
|
259
256
|
* @returns {boolean}
|
|
260
257
|
*/
|
|
261
258
|
setPaused(paused) {
|
|
262
|
-
if (
|
|
259
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
263
260
|
return;
|
|
264
261
|
if (!this.connection)
|
|
265
262
|
return false;
|
|
@@ -271,13 +268,12 @@ class Queue {
|
|
|
271
268
|
* @returns {void}
|
|
272
269
|
*/
|
|
273
270
|
setBitrate(bitrate) {
|
|
274
|
-
|
|
275
|
-
if ((0, tslib_1.__classPrivateFieldGet)(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
271
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
276
272
|
return;
|
|
277
|
-
if (!
|
|
273
|
+
if (!this.connection?.audioResource?.encoder)
|
|
278
274
|
return;
|
|
279
275
|
if (bitrate === "auto")
|
|
280
|
-
bitrate =
|
|
276
|
+
bitrate = this.connection.channel?.bitrate ?? 64000;
|
|
281
277
|
this.connection.audioResource.encoder.setBitrate(bitrate);
|
|
282
278
|
}
|
|
283
279
|
/**
|
|
@@ -286,11 +282,11 @@ class Queue {
|
|
|
286
282
|
* @returns {boolean}
|
|
287
283
|
*/
|
|
288
284
|
setVolume(amount) {
|
|
289
|
-
if (
|
|
285
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
290
286
|
return;
|
|
291
287
|
if (!this.connection)
|
|
292
288
|
return false;
|
|
293
|
-
|
|
289
|
+
tslib_1.__classPrivateFieldSet(this, _Queue_lastVolume, amount, "f");
|
|
294
290
|
this.options.initialVolume = amount;
|
|
295
291
|
return this.connection.setVolume(amount);
|
|
296
292
|
}
|
|
@@ -300,7 +296,7 @@ class Queue {
|
|
|
300
296
|
* @returns {boolean}
|
|
301
297
|
*/
|
|
302
298
|
setRepeatMode(mode) {
|
|
303
|
-
if (
|
|
299
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
304
300
|
return;
|
|
305
301
|
if (![types_1.QueueRepeatMode.OFF, types_1.QueueRepeatMode.QUEUE, types_1.QueueRepeatMode.TRACK, types_1.QueueRepeatMode.AUTOPLAY].includes(mode))
|
|
306
302
|
throw new PlayerError_1.PlayerError(`Unknown repeat mode "${mode}"!`, PlayerError_1.ErrorStatusCode.UNKNOWN_REPEAT_MODE);
|
|
@@ -314,7 +310,7 @@ class Queue {
|
|
|
314
310
|
* @type {number}
|
|
315
311
|
*/
|
|
316
312
|
get volume() {
|
|
317
|
-
if (
|
|
313
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
318
314
|
return;
|
|
319
315
|
if (!this.connection)
|
|
320
316
|
return 100;
|
|
@@ -328,7 +324,7 @@ class Queue {
|
|
|
328
324
|
* @type {number}
|
|
329
325
|
*/
|
|
330
326
|
get streamTime() {
|
|
331
|
-
if (
|
|
327
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
332
328
|
return;
|
|
333
329
|
if (!this.connection)
|
|
334
330
|
return 0;
|
|
@@ -340,7 +336,7 @@ class Queue {
|
|
|
340
336
|
return NC ? playbackTime * NC : VW ? playbackTime * VW : playbackTime;
|
|
341
337
|
}
|
|
342
338
|
set streamTime(time) {
|
|
343
|
-
if (
|
|
339
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
344
340
|
return;
|
|
345
341
|
this.seek(time);
|
|
346
342
|
}
|
|
@@ -349,7 +345,7 @@ class Queue {
|
|
|
349
345
|
* @returns {AudioFilters}
|
|
350
346
|
*/
|
|
351
347
|
getFiltersEnabled() {
|
|
352
|
-
if (
|
|
348
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
353
349
|
return;
|
|
354
350
|
return AudioFilters_1.default.names.filter((x) => this._activeFilters.includes(x));
|
|
355
351
|
}
|
|
@@ -358,7 +354,7 @@ class Queue {
|
|
|
358
354
|
* @returns {AudioFilters}
|
|
359
355
|
*/
|
|
360
356
|
getFiltersDisabled() {
|
|
361
|
-
if (
|
|
357
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
362
358
|
return;
|
|
363
359
|
return AudioFilters_1.default.names.filter((x) => !this._activeFilters.includes(x));
|
|
364
360
|
}
|
|
@@ -367,37 +363,35 @@ class Queue {
|
|
|
367
363
|
* @param {QueueFilters} filters Queue filters
|
|
368
364
|
* @returns {Promise<void>}
|
|
369
365
|
*/
|
|
370
|
-
setFilters(filters) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// reset filters
|
|
376
|
-
const streamTime = this.streamTime;
|
|
377
|
-
this._activeFilters = [];
|
|
378
|
-
return yield this.play(this.current, {
|
|
379
|
-
immediate: true,
|
|
380
|
-
filtersUpdate: true,
|
|
381
|
-
seek: streamTime,
|
|
382
|
-
encoderArgs: []
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
const _filters = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
386
|
-
for (const filter in filters) {
|
|
387
|
-
if (filters[filter] === true)
|
|
388
|
-
_filters.push(filter);
|
|
389
|
-
}
|
|
390
|
-
if (this._activeFilters.join("") === _filters.join(""))
|
|
391
|
-
return;
|
|
392
|
-
const newFilters = AudioFilters_1.default.create(_filters).trim();
|
|
366
|
+
async setFilters(filters) {
|
|
367
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
368
|
+
return;
|
|
369
|
+
if (!filters || !Object.keys(filters).length) {
|
|
370
|
+
// reset filters
|
|
393
371
|
const streamTime = this.streamTime;
|
|
394
|
-
this._activeFilters =
|
|
395
|
-
return
|
|
372
|
+
this._activeFilters = [];
|
|
373
|
+
return await this.play(this.current, {
|
|
396
374
|
immediate: true,
|
|
397
375
|
filtersUpdate: true,
|
|
398
376
|
seek: streamTime,
|
|
399
|
-
encoderArgs:
|
|
377
|
+
encoderArgs: []
|
|
400
378
|
});
|
|
379
|
+
}
|
|
380
|
+
const _filters = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
381
|
+
for (const filter in filters) {
|
|
382
|
+
if (filters[filter] === true)
|
|
383
|
+
_filters.push(filter);
|
|
384
|
+
}
|
|
385
|
+
if (this._activeFilters.join("") === _filters.join(""))
|
|
386
|
+
return;
|
|
387
|
+
const newFilters = AudioFilters_1.default.create(_filters).trim();
|
|
388
|
+
const streamTime = this.streamTime;
|
|
389
|
+
this._activeFilters = _filters;
|
|
390
|
+
return await this.play(this.current, {
|
|
391
|
+
immediate: true,
|
|
392
|
+
filtersUpdate: true,
|
|
393
|
+
seek: streamTime,
|
|
394
|
+
encoderArgs: !_filters.length ? undefined : ["-af", newFilters]
|
|
401
395
|
});
|
|
402
396
|
}
|
|
403
397
|
/**
|
|
@@ -405,43 +399,39 @@ class Queue {
|
|
|
405
399
|
* @param {number} position The position
|
|
406
400
|
* @returns {boolean}
|
|
407
401
|
*/
|
|
408
|
-
seek(position) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
seek: position
|
|
422
|
-
});
|
|
423
|
-
return true;
|
|
402
|
+
async seek(position) {
|
|
403
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
404
|
+
return;
|
|
405
|
+
if (!this.playing || !this.current)
|
|
406
|
+
return false;
|
|
407
|
+
if (position < 1)
|
|
408
|
+
position = 0;
|
|
409
|
+
if (position >= this.current.durationMS)
|
|
410
|
+
return this.skip();
|
|
411
|
+
await this.play(this.current, {
|
|
412
|
+
immediate: true,
|
|
413
|
+
filtersUpdate: true,
|
|
414
|
+
seek: position
|
|
424
415
|
});
|
|
416
|
+
return true;
|
|
425
417
|
}
|
|
426
418
|
/**
|
|
427
419
|
* Plays previous track
|
|
428
420
|
* @returns {Promise<void>}
|
|
429
421
|
*/
|
|
430
|
-
back() {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
return yield this.play(prev, { immediate: true });
|
|
438
|
-
});
|
|
422
|
+
async back() {
|
|
423
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
424
|
+
return;
|
|
425
|
+
const prev = this.previousTracks[this.previousTracks.length - 2]; // because last item is the current track
|
|
426
|
+
if (!prev)
|
|
427
|
+
throw new PlayerError_1.PlayerError("Could not find previous track", PlayerError_1.ErrorStatusCode.TRACK_NOT_FOUND);
|
|
428
|
+
return await this.play(prev, { immediate: true });
|
|
439
429
|
}
|
|
440
430
|
/**
|
|
441
431
|
* Clear this queue
|
|
442
432
|
*/
|
|
443
433
|
clear() {
|
|
444
|
-
if (
|
|
434
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
445
435
|
return;
|
|
446
436
|
this.tracks = [];
|
|
447
437
|
this.previousTracks = [];
|
|
@@ -451,7 +441,7 @@ class Queue {
|
|
|
451
441
|
* @returns {void}
|
|
452
442
|
*/
|
|
453
443
|
stop() {
|
|
454
|
-
if (
|
|
444
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
455
445
|
return;
|
|
456
446
|
return this.destroy();
|
|
457
447
|
}
|
|
@@ -460,7 +450,7 @@ class Queue {
|
|
|
460
450
|
* @returns {boolean}
|
|
461
451
|
*/
|
|
462
452
|
shuffle() {
|
|
463
|
-
if (
|
|
453
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
464
454
|
return;
|
|
465
455
|
if (!this.tracks.length || this.tracks.length < 3)
|
|
466
456
|
return false;
|
|
@@ -474,11 +464,11 @@ class Queue {
|
|
|
474
464
|
}
|
|
475
465
|
/**
|
|
476
466
|
* Removes a track from the queue
|
|
477
|
-
* @param {Track|
|
|
467
|
+
* @param {Track|string|number} track The track to remove
|
|
478
468
|
* @returns {Track}
|
|
479
469
|
*/
|
|
480
470
|
remove(track) {
|
|
481
|
-
if (
|
|
471
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
482
472
|
return;
|
|
483
473
|
let trackFound = null;
|
|
484
474
|
if (typeof track === "number") {
|
|
@@ -497,11 +487,11 @@ class Queue {
|
|
|
497
487
|
}
|
|
498
488
|
/**
|
|
499
489
|
* Returns the index of the specified track. If found, returns the track index else returns -1.
|
|
500
|
-
* @param {number|Track|
|
|
490
|
+
* @param {number|Track|string} track The track
|
|
501
491
|
* @returns {number}
|
|
502
492
|
*/
|
|
503
493
|
getTrackPosition(track) {
|
|
504
|
-
if (
|
|
494
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
505
495
|
return;
|
|
506
496
|
if (typeof track === "number")
|
|
507
497
|
return this.tracks[track] != null ? track : -1;
|
|
@@ -513,7 +503,7 @@ class Queue {
|
|
|
513
503
|
* @returns {void}
|
|
514
504
|
*/
|
|
515
505
|
jump(track) {
|
|
516
|
-
if (
|
|
506
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
517
507
|
return;
|
|
518
508
|
const foundTrack = this.remove(track);
|
|
519
509
|
if (!foundTrack)
|
|
@@ -527,7 +517,7 @@ class Queue {
|
|
|
527
517
|
* @returns {void}
|
|
528
518
|
*/
|
|
529
519
|
skipTo(track) {
|
|
530
|
-
if (
|
|
520
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
531
521
|
return;
|
|
532
522
|
const trackIndex = this.getTrackPosition(track);
|
|
533
523
|
const removedTrack = this.remove(track);
|
|
@@ -542,7 +532,7 @@ class Queue {
|
|
|
542
532
|
* @param {number} [index=0] The index where this track should be
|
|
543
533
|
*/
|
|
544
534
|
insert(track, index = 0) {
|
|
545
|
-
if (
|
|
535
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
546
536
|
return;
|
|
547
537
|
if (!track || !(track instanceof Track_1.default))
|
|
548
538
|
throw new PlayerError_1.PlayerError("track must be the instance of Track", PlayerError_1.ErrorStatusCode.INVALID_TRACK);
|
|
@@ -562,7 +552,7 @@ class Queue {
|
|
|
562
552
|
* @returns {PlayerTimestamp}
|
|
563
553
|
*/
|
|
564
554
|
getPlayerTimestamp() {
|
|
565
|
-
if (
|
|
555
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
566
556
|
return;
|
|
567
557
|
const currentStreamTime = this.streamTime;
|
|
568
558
|
const totalTime = this.current.durationMS;
|
|
@@ -580,7 +570,7 @@ class Queue {
|
|
|
580
570
|
* @returns {string}
|
|
581
571
|
*/
|
|
582
572
|
createProgressBar(options = { timecodes: true }) {
|
|
583
|
-
if (
|
|
573
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
584
574
|
return;
|
|
585
575
|
const length = typeof options.length === "number" ? (options.length <= 0 || options.length === Infinity ? 15 : options.length) : 15;
|
|
586
576
|
const index = Math.round((this.streamTime / this.current.durationMS) * length);
|
|
@@ -612,7 +602,7 @@ class Queue {
|
|
|
612
602
|
* @type {Number}
|
|
613
603
|
*/
|
|
614
604
|
get totalTime() {
|
|
615
|
-
if (
|
|
605
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
616
606
|
return;
|
|
617
607
|
return this.tracks.length > 0 ? this.tracks.map((t) => t.durationMS).reduce((p, c) => p + c) : 0;
|
|
618
608
|
}
|
|
@@ -622,94 +612,98 @@ class Queue {
|
|
|
622
612
|
* @param {PlayOptions} [options={}] The options
|
|
623
613
|
* @returns {Promise<void>}
|
|
624
614
|
*/
|
|
625
|
-
play(src, options = {}) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
this.
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
615
|
+
async play(src, options = {}) {
|
|
616
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
617
|
+
return;
|
|
618
|
+
if (!this.connection || !this.connection.voiceConnection)
|
|
619
|
+
throw new PlayerError_1.PlayerError("Voice connection is not available, use <Queue>.connect()!", PlayerError_1.ErrorStatusCode.NO_CONNECTION);
|
|
620
|
+
if (src && (this.playing || this.tracks.length) && !options.immediate)
|
|
621
|
+
return this.addTrack(src);
|
|
622
|
+
const track = options.filtersUpdate && !options.immediate ? src || this.current : src ?? this.tracks.shift();
|
|
623
|
+
if (!track)
|
|
624
|
+
return;
|
|
625
|
+
this.player.emit("debug", this, "Received play request");
|
|
626
|
+
if (!options.filtersUpdate) {
|
|
627
|
+
this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
|
|
628
|
+
this.previousTracks.push(track);
|
|
629
|
+
}
|
|
630
|
+
let stream = null;
|
|
631
|
+
const customDownloader = typeof this.onBeforeCreateStream === "function";
|
|
632
|
+
if (["youtube", "spotify"].includes(track.raw.source)) {
|
|
633
|
+
let spotifyResolved = false;
|
|
634
|
+
if (this.options.spotifyBridge && track.raw.source === "spotify" && !track.raw.engine) {
|
|
635
|
+
track.raw.engine = await youtube_sr_1.default.search(`${track.author} ${track.title}`, { type: "video" })
|
|
636
|
+
.then((x) => x[0].url)
|
|
637
|
+
.catch(() => null);
|
|
638
|
+
spotifyResolved = true;
|
|
641
639
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
.
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
stream = (_a = (yield this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this))) !== null && _a !== void 0 ? _a : null;
|
|
657
|
-
if (stream)
|
|
658
|
-
stream = discord_ytdl_core_1.default
|
|
659
|
-
.arbitraryStream(stream, {
|
|
660
|
-
opusEncoded: false,
|
|
661
|
-
fmt: "s16le",
|
|
662
|
-
encoderArgs: ((_b = options.encoderArgs) !== null && _b !== void 0 ? _b : this._activeFilters.length) ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
663
|
-
seek: options.seek ? options.seek / 1000 : 0
|
|
664
|
-
})
|
|
665
|
-
.on("error", (err) => {
|
|
666
|
-
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
670
|
-
stream = (0, discord_ytdl_core_1.default)(link, Object.assign(Object.assign({}, this.options.ytdlOptions), {
|
|
671
|
-
// discord-ytdl-core
|
|
672
|
-
opusEncoded: false, fmt: "s16le", encoderArgs: ((_c = options.encoderArgs) !== null && _c !== void 0 ? _c : this._activeFilters.length) ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [], seek: options.seek ? options.seek / 1000 : 0 })).on("error", (err) => {
|
|
640
|
+
const link = track.raw.source === "spotify" ? track.raw.engine : track.url;
|
|
641
|
+
if (!link)
|
|
642
|
+
return void this.play(this.tracks.shift(), { immediate: true });
|
|
643
|
+
if (customDownloader) {
|
|
644
|
+
stream = (await this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this)) ?? null;
|
|
645
|
+
if (stream)
|
|
646
|
+
stream = discord_ytdl_core_1.default
|
|
647
|
+
.arbitraryStream(stream, {
|
|
648
|
+
opusEncoded: false,
|
|
649
|
+
fmt: "s16le",
|
|
650
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
651
|
+
seek: options.seek ? options.seek / 1000 : 0
|
|
652
|
+
})
|
|
653
|
+
.on("error", (err) => {
|
|
673
654
|
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
674
655
|
});
|
|
675
|
-
}
|
|
676
656
|
}
|
|
677
657
|
else {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
: track.raw.source === "soundcloud"
|
|
682
|
-
? yield track.raw.engine.downloadProgressive()
|
|
683
|
-
: typeof track.raw.engine === "function"
|
|
684
|
-
? yield track.raw.engine()
|
|
685
|
-
: track.raw.engine;
|
|
686
|
-
stream = discord_ytdl_core_1.default
|
|
687
|
-
.arbitraryStream(arbitrarySource, {
|
|
658
|
+
stream = (0, discord_ytdl_core_1.default)(link, {
|
|
659
|
+
...this.options.ytdlOptions,
|
|
660
|
+
// discord-ytdl-core
|
|
688
661
|
opusEncoded: false,
|
|
689
662
|
fmt: "s16le",
|
|
690
|
-
encoderArgs:
|
|
663
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
691
664
|
seek: options.seek ? options.seek / 1000 : 0
|
|
692
|
-
})
|
|
693
|
-
.on("error", (err) => {
|
|
665
|
+
}).on("error", (err) => {
|
|
694
666
|
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
695
667
|
});
|
|
696
668
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
const tryArb = (customDownloader && (await this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null;
|
|
672
|
+
const arbitrarySource = tryArb
|
|
673
|
+
? tryArb
|
|
674
|
+
: track.raw.source === "soundcloud"
|
|
675
|
+
? await track.raw.engine.downloadProgressive()
|
|
676
|
+
: typeof track.raw.engine === "function"
|
|
677
|
+
? await track.raw.engine()
|
|
678
|
+
: track.raw.engine;
|
|
679
|
+
stream = discord_ytdl_core_1.default
|
|
680
|
+
.arbitraryStream(arbitrarySource, {
|
|
681
|
+
opusEncoded: false,
|
|
682
|
+
fmt: "s16le",
|
|
683
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
684
|
+
seek: options.seek ? options.seek / 1000 : 0
|
|
685
|
+
})
|
|
686
|
+
.on("error", (err) => {
|
|
687
|
+
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
701
688
|
});
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
this.setVolume(this.options.initialVolume);
|
|
709
|
-
setTimeout(() => {
|
|
710
|
-
this.connection.playStream(resource);
|
|
711
|
-
}, (0, tslib_1.__classPrivateFieldGet)(this, _Queue_instances, "m", _Queue_getBufferingTimeout).call(this)).unref();
|
|
689
|
+
}
|
|
690
|
+
const resource = this.connection.createStream(stream, {
|
|
691
|
+
type: voice_1.StreamType.Raw,
|
|
692
|
+
data: track,
|
|
693
|
+
disableVolume: Boolean(this.options.disableVolume)
|
|
712
694
|
});
|
|
695
|
+
if (options.seek)
|
|
696
|
+
this._streamTime = options.seek;
|
|
697
|
+
this._filtersUpdate = options.filtersUpdate;
|
|
698
|
+
const volumeTransformer = resource.volume;
|
|
699
|
+
if (volumeTransformer?.hasSmoothness && typeof this.options.volumeSmoothness === "number") {
|
|
700
|
+
if (typeof volumeTransformer.setSmoothness === "function")
|
|
701
|
+
volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
|
702
|
+
}
|
|
703
|
+
this.setVolume(this.options.initialVolume);
|
|
704
|
+
setTimeout(() => {
|
|
705
|
+
this.connection.playStream(resource);
|
|
706
|
+
}, tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_getBufferingTimeout).call(this)).unref();
|
|
713
707
|
}
|
|
714
708
|
/**
|
|
715
709
|
* Private method to handle autoplay
|
|
@@ -717,40 +711,37 @@ class Queue {
|
|
|
717
711
|
* @returns {Promise<void>}
|
|
718
712
|
* @private
|
|
719
713
|
*/
|
|
720
|
-
_handleAutoplay(track) {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
requestedBy: track.requestedBy,
|
|
747
|
-
source: "youtube"
|
|
748
|
-
});
|
|
749
|
-
this.play(nextTrack, { immediate: true });
|
|
714
|
+
async _handleAutoplay(track) {
|
|
715
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
716
|
+
return;
|
|
717
|
+
if (!track || ![track.source, track.raw?.source].includes("youtube")) {
|
|
718
|
+
if (this.options.leaveOnEnd)
|
|
719
|
+
this.destroy();
|
|
720
|
+
return void this.player.emit("queueEnd", this);
|
|
721
|
+
}
|
|
722
|
+
const info = await youtube_sr_1.default.getVideo(track.url)
|
|
723
|
+
.then((x) => x.videos[0])
|
|
724
|
+
.catch(Util_1.Util.noop);
|
|
725
|
+
if (!info) {
|
|
726
|
+
if (this.options.leaveOnEnd)
|
|
727
|
+
this.destroy();
|
|
728
|
+
return void this.player.emit("queueEnd", this);
|
|
729
|
+
}
|
|
730
|
+
const nextTrack = new Track_1.default(this.player, {
|
|
731
|
+
title: info.title,
|
|
732
|
+
url: `https://www.youtube.com/watch?v=${info.id}`,
|
|
733
|
+
duration: info.durationFormatted ? Util_1.Util.buildTimeCode(Util_1.Util.parseMS(info.duration * 1000)) : "0:00",
|
|
734
|
+
description: "",
|
|
735
|
+
thumbnail: typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url,
|
|
736
|
+
views: info.views,
|
|
737
|
+
author: info.channel.name,
|
|
738
|
+
requestedBy: track.requestedBy,
|
|
739
|
+
source: "youtube"
|
|
750
740
|
});
|
|
741
|
+
this.play(nextTrack, { immediate: true });
|
|
751
742
|
}
|
|
752
743
|
*[(_Queue_lastVolume = new WeakMap(), _Queue_destroyed = new WeakMap(), _Queue_instances = new WeakSet(), Symbol.iterator)]() {
|
|
753
|
-
if (
|
|
744
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
754
745
|
return;
|
|
755
746
|
yield* this.tracks;
|
|
756
747
|
}
|
|
@@ -759,13 +750,12 @@ class Queue {
|
|
|
759
750
|
* @returns {object}
|
|
760
751
|
*/
|
|
761
752
|
toJSON() {
|
|
762
|
-
|
|
763
|
-
if ((0, tslib_1.__classPrivateFieldGet)(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
753
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
764
754
|
return;
|
|
765
755
|
return {
|
|
766
756
|
id: this.id,
|
|
767
757
|
guild: this.guild.id,
|
|
768
|
-
voiceChannel:
|
|
758
|
+
voiceChannel: this.connection?.channel?.id,
|
|
769
759
|
options: this.options,
|
|
770
760
|
tracks: this.tracks.map((m) => m.toJSON())
|
|
771
761
|
};
|
|
@@ -775,7 +765,7 @@ class Queue {
|
|
|
775
765
|
* @returns {string}
|
|
776
766
|
*/
|
|
777
767
|
toString() {
|
|
778
|
-
if (
|
|
768
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
779
769
|
return;
|
|
780
770
|
if (!this.tracks.length)
|
|
781
771
|
return "No songs available to display!";
|
|
@@ -784,7 +774,7 @@ class Queue {
|
|
|
784
774
|
}
|
|
785
775
|
exports.Queue = Queue;
|
|
786
776
|
_Queue_watchDestroyed = function _Queue_watchDestroyed(emit = true) {
|
|
787
|
-
if (
|
|
777
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_destroyed, "f")) {
|
|
788
778
|
if (emit)
|
|
789
779
|
this.player.emit("error", this, new PlayerError_1.PlayerError("Cannot use destroyed queue", PlayerError_1.ErrorStatusCode.DESTROYED_QUEUE));
|
|
790
780
|
return true;
|