discord-player 5.2.3-dev → 5.3.0-dev.2
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 +23 -19
- package/dist/Player.js +307 -285
- package/dist/Structures/ExtractorModel.js +19 -24
- package/dist/Structures/Playlist.js +1 -2
- package/dist/Structures/Queue.js +226 -237
- package/dist/Structures/Track.js +11 -14
- package/dist/VoiceInterface/StreamDispatcher.js +33 -41
- package/dist/VoiceInterface/VoiceUtils.js +14 -32
- package/dist/index.d.ts +24 -20
- package/dist/smoothVolume.js +1 -1
- package/dist/utils/AudioFilters.js +2 -2
- package/dist/utils/Util.js +36 -1
- package/package.json +24 -28
package/dist/Structures/Queue.js
CHANGED
|
@@ -17,7 +17,7 @@ class Queue {
|
|
|
17
17
|
* Queue constructor
|
|
18
18
|
* @param {Player} player The player that instantiated this queue
|
|
19
19
|
* @param {Guild} guild The guild that instantiated this queue
|
|
20
|
-
* @param {PlayerOptions} [options
|
|
20
|
+
* @param {PlayerOptions} [options] Player options for the queue
|
|
21
21
|
*/
|
|
22
22
|
constructor(player, guild, options = {}) {
|
|
23
23
|
_Queue_instances.add(this);
|
|
@@ -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,10 +104,9 @@ class Queue {
|
|
|
104
104
|
* @type {Track}
|
|
105
105
|
*/
|
|
106
106
|
get current() {
|
|
107
|
-
var _a, _b;
|
|
108
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
|
|
@@ -130,75 +129,69 @@ 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
|
-
|
|
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);
|
|
142
145
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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)
|
|
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?.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);
|
|
180
|
+
}
|
|
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;
|
|
148
192
|
}
|
|
149
|
-
this.connection.on("error", (err) => {
|
|
150
|
-
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
151
|
-
return;
|
|
152
|
-
this.player.emit("connectionError", this, err);
|
|
153
|
-
});
|
|
154
|
-
this.connection.on("debug", (msg) => {
|
|
155
|
-
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
156
|
-
return;
|
|
157
|
-
this.player.emit("debug", this, msg);
|
|
158
|
-
});
|
|
159
|
-
this.player.emit("connectionCreate", this, this.connection);
|
|
160
|
-
this.connection.on("start", (resource) => {
|
|
161
|
-
var _a;
|
|
162
|
-
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
163
|
-
return;
|
|
164
|
-
this.playing = true;
|
|
165
|
-
if (!this._filtersUpdate && (resource === null || resource === void 0 ? void 0 : resource.metadata))
|
|
166
|
-
this.player.emit("trackStart", this, (_a = resource === null || resource === void 0 ? void 0 : resource.metadata) !== null && _a !== void 0 ? _a : this.current);
|
|
167
|
-
this._filtersUpdate = false;
|
|
168
|
-
});
|
|
169
|
-
this.connection.on("finish", (resource) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
171
|
-
return;
|
|
172
|
-
this.playing = false;
|
|
173
|
-
if (this._filtersUpdate)
|
|
174
|
-
return;
|
|
175
|
-
this._streamTime = 0;
|
|
176
|
-
if (resource && resource.metadata)
|
|
177
|
-
this.previousTracks.push(resource.metadata);
|
|
178
|
-
this.player.emit("trackEnd", this, resource.metadata);
|
|
179
|
-
if (!this.tracks.length && this.repeatMode === types_1.QueueRepeatMode.OFF) {
|
|
180
|
-
if (this.options.leaveOnEnd)
|
|
181
|
-
this.destroy();
|
|
182
|
-
this.player.emit("queueEnd", this);
|
|
183
|
-
}
|
|
184
|
-
else if (!this.tracks.length && this.repeatMode === types_1.QueueRepeatMode.AUTOPLAY) {
|
|
185
|
-
this._handleAutoplay(Util_1.Util.last(this.previousTracks));
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
if (this.repeatMode === types_1.QueueRepeatMode.TRACK)
|
|
189
|
-
return void this.play(Util_1.Util.last(this.previousTracks), { immediate: true });
|
|
190
|
-
if (this.repeatMode === types_1.QueueRepeatMode.QUEUE)
|
|
191
|
-
this.tracks.push(Util_1.Util.last(this.previousTracks));
|
|
192
|
-
const nextTrack = this.tracks.shift();
|
|
193
|
-
this.play(nextTrack, { immediate: true });
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
}));
|
|
197
|
-
yield this.player.voiceUtils.enterReady(this.connection.voiceConnection, {
|
|
198
|
-
maxTime: this.player.options.connectionTimeout || 30000
|
|
199
|
-
});
|
|
200
|
-
return this;
|
|
201
193
|
});
|
|
194
|
+
return this;
|
|
202
195
|
}
|
|
203
196
|
/**
|
|
204
197
|
* Destroys this queue
|
|
@@ -206,13 +199,12 @@ class Queue {
|
|
|
206
199
|
* @returns {void}
|
|
207
200
|
*/
|
|
208
201
|
destroy(disconnect = this.options.leaveOnStop) {
|
|
209
|
-
var _a;
|
|
210
202
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
211
203
|
return;
|
|
212
204
|
if (this.connection)
|
|
213
205
|
this.connection.end();
|
|
214
206
|
if (disconnect)
|
|
215
|
-
|
|
207
|
+
this.connection?.disconnect();
|
|
216
208
|
this.player.queues.delete(this.guild.id);
|
|
217
209
|
this.player.voiceUtils.cache.delete(this.guild.id);
|
|
218
210
|
tslib_1.__classPrivateFieldSet(this, _Queue_destroyed, true, "f");
|
|
@@ -273,13 +265,12 @@ class Queue {
|
|
|
273
265
|
* @returns {void}
|
|
274
266
|
*/
|
|
275
267
|
setBitrate(bitrate) {
|
|
276
|
-
var _a, _b, _c, _d;
|
|
277
268
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
278
269
|
return;
|
|
279
|
-
if (!
|
|
270
|
+
if (!this.connection?.audioResource?.encoder)
|
|
280
271
|
return;
|
|
281
272
|
if (bitrate === "auto")
|
|
282
|
-
bitrate =
|
|
273
|
+
bitrate = this.connection.channel?.bitrate ?? 64000;
|
|
283
274
|
this.connection.audioResource.encoder.setBitrate(bitrate);
|
|
284
275
|
}
|
|
285
276
|
/**
|
|
@@ -369,37 +360,35 @@ class Queue {
|
|
|
369
360
|
* @param {QueueFilters} filters Queue filters
|
|
370
361
|
* @returns {Promise<void>}
|
|
371
362
|
*/
|
|
372
|
-
setFilters(filters) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
// reset filters
|
|
378
|
-
const streamTime = this.streamTime;
|
|
379
|
-
this._activeFilters = [];
|
|
380
|
-
return yield this.play(this.current, {
|
|
381
|
-
immediate: true,
|
|
382
|
-
filtersUpdate: true,
|
|
383
|
-
seek: streamTime,
|
|
384
|
-
encoderArgs: []
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
const _filters = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
388
|
-
for (const filter in filters) {
|
|
389
|
-
if (filters[filter] === true)
|
|
390
|
-
_filters.push(filter);
|
|
391
|
-
}
|
|
392
|
-
if (this._activeFilters.join("") === _filters.join(""))
|
|
393
|
-
return;
|
|
394
|
-
const newFilters = AudioFilters_1.default.create(_filters).trim();
|
|
363
|
+
async setFilters(filters) {
|
|
364
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
365
|
+
return;
|
|
366
|
+
if (!filters || !Object.keys(filters).length) {
|
|
367
|
+
// reset filters
|
|
395
368
|
const streamTime = this.streamTime;
|
|
396
|
-
this._activeFilters =
|
|
397
|
-
return
|
|
369
|
+
this._activeFilters = [];
|
|
370
|
+
return await this.play(this.current, {
|
|
398
371
|
immediate: true,
|
|
399
372
|
filtersUpdate: true,
|
|
400
373
|
seek: streamTime,
|
|
401
|
-
encoderArgs:
|
|
374
|
+
encoderArgs: []
|
|
402
375
|
});
|
|
376
|
+
}
|
|
377
|
+
const _filters = []; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
378
|
+
for (const filter in filters) {
|
|
379
|
+
if (filters[filter] === true)
|
|
380
|
+
_filters.push(filter);
|
|
381
|
+
}
|
|
382
|
+
if (this._activeFilters.join("") === _filters.join(""))
|
|
383
|
+
return;
|
|
384
|
+
const newFilters = AudioFilters_1.default.create(_filters).trim();
|
|
385
|
+
const streamTime = this.streamTime;
|
|
386
|
+
this._activeFilters = _filters;
|
|
387
|
+
return await this.play(this.current, {
|
|
388
|
+
immediate: true,
|
|
389
|
+
filtersUpdate: true,
|
|
390
|
+
seek: streamTime,
|
|
391
|
+
encoderArgs: !_filters.length ? undefined : ["-af", newFilters]
|
|
403
392
|
});
|
|
404
393
|
}
|
|
405
394
|
/**
|
|
@@ -407,37 +396,33 @@ class Queue {
|
|
|
407
396
|
* @param {number} position The position
|
|
408
397
|
* @returns {boolean}
|
|
409
398
|
*/
|
|
410
|
-
seek(position) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
seek: position
|
|
424
|
-
});
|
|
425
|
-
return true;
|
|
399
|
+
async seek(position) {
|
|
400
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
401
|
+
return;
|
|
402
|
+
if (!this.playing || !this.current)
|
|
403
|
+
return false;
|
|
404
|
+
if (position < 1)
|
|
405
|
+
position = 0;
|
|
406
|
+
if (position >= this.current.durationMS)
|
|
407
|
+
return this.skip();
|
|
408
|
+
await this.play(this.current, {
|
|
409
|
+
immediate: true,
|
|
410
|
+
filtersUpdate: true,
|
|
411
|
+
seek: position
|
|
426
412
|
});
|
|
413
|
+
return true;
|
|
427
414
|
}
|
|
428
415
|
/**
|
|
429
416
|
* Plays previous track
|
|
430
417
|
* @returns {Promise<void>}
|
|
431
418
|
*/
|
|
432
|
-
back() {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return yield this.play(prev, { immediate: true });
|
|
440
|
-
});
|
|
419
|
+
async back() {
|
|
420
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
421
|
+
return;
|
|
422
|
+
const prev = this.previousTracks[this.previousTracks.length - 2]; // because last item is the current track
|
|
423
|
+
if (!prev)
|
|
424
|
+
throw new PlayerError_1.PlayerError("Could not find previous track", PlayerError_1.ErrorStatusCode.TRACK_NOT_FOUND);
|
|
425
|
+
return await this.play(prev, { immediate: true });
|
|
441
426
|
}
|
|
442
427
|
/**
|
|
443
428
|
* Clear this queue
|
|
@@ -476,7 +461,7 @@ class Queue {
|
|
|
476
461
|
}
|
|
477
462
|
/**
|
|
478
463
|
* Removes a track from the queue
|
|
479
|
-
* @param {Track|
|
|
464
|
+
* @param {Track|string|number} track The track to remove
|
|
480
465
|
* @returns {Track}
|
|
481
466
|
*/
|
|
482
467
|
remove(track) {
|
|
@@ -499,7 +484,7 @@ class Queue {
|
|
|
499
484
|
}
|
|
500
485
|
/**
|
|
501
486
|
* Returns the index of the specified track. If found, returns the track index else returns -1.
|
|
502
|
-
* @param {number|Track|
|
|
487
|
+
* @param {number|Track|string} track The track
|
|
503
488
|
* @returns {number}
|
|
504
489
|
*/
|
|
505
490
|
getTrackPosition(track) {
|
|
@@ -621,99 +606,102 @@ class Queue {
|
|
|
621
606
|
/**
|
|
622
607
|
* Play stream in a voice/stage channel
|
|
623
608
|
* @param {Track} [src] The track to play (if empty, uses first track from the queue)
|
|
624
|
-
* @param {PlayOptions} [options
|
|
609
|
+
* @param {PlayOptions} [options] The options
|
|
625
610
|
* @returns {Promise<void>}
|
|
626
611
|
*/
|
|
627
|
-
play(src, options = {}) {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
this.
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
612
|
+
async play(src, options = {}) {
|
|
613
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
|
|
614
|
+
return;
|
|
615
|
+
if (!this.connection || !this.connection.voiceConnection)
|
|
616
|
+
throw new PlayerError_1.PlayerError("Voice connection is not available, use <Queue>.connect()!", PlayerError_1.ErrorStatusCode.NO_CONNECTION);
|
|
617
|
+
if (src && (this.playing || this.tracks.length) && !options.immediate)
|
|
618
|
+
return this.addTrack(src);
|
|
619
|
+
const track = options.filtersUpdate && !options.immediate ? src || this.current : src ?? this.tracks.shift();
|
|
620
|
+
if (!track)
|
|
621
|
+
return;
|
|
622
|
+
this.player.emit("debug", this, "Received play request");
|
|
623
|
+
if (!options.filtersUpdate) {
|
|
624
|
+
this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
|
|
625
|
+
this.previousTracks.push(track);
|
|
626
|
+
}
|
|
627
|
+
let stream = null;
|
|
628
|
+
const customDownloader = typeof this.onBeforeCreateStream === "function";
|
|
629
|
+
if (["youtube", "spotify"].includes(track.raw.source)) {
|
|
630
|
+
let spotifyResolved = false;
|
|
631
|
+
if (this.options.spotifyBridge && track.raw.source === "spotify" && !track.raw.engine) {
|
|
632
|
+
track.raw.engine = await youtube_sr_1.default.search(`${track.author} ${track.title}`, { type: "video" })
|
|
633
|
+
.then((x) => x[0].url)
|
|
634
|
+
.catch(() => null);
|
|
635
|
+
spotifyResolved = true;
|
|
643
636
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
.
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
stream = (_a = (yield this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this))) !== null && _a !== void 0 ? _a : null;
|
|
659
|
-
if (stream)
|
|
660
|
-
stream = discord_ytdl_core_1.default
|
|
661
|
-
.arbitraryStream(stream, {
|
|
662
|
-
opusEncoded: false,
|
|
663
|
-
fmt: "s16le",
|
|
664
|
-
encoderArgs: ((_b = options.encoderArgs) !== null && _b !== void 0 ? _b : this._activeFilters.length) ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
665
|
-
seek: options.seek ? options.seek / 1000 : 0
|
|
666
|
-
})
|
|
667
|
-
.on("error", (err) => {
|
|
668
|
-
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
else {
|
|
672
|
-
stream = (0, discord_ytdl_core_1.default)(link, Object.assign(Object.assign({}, this.options.ytdlOptions), {
|
|
673
|
-
// discord-ytdl-core
|
|
674
|
-
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) => {
|
|
637
|
+
const link = track.raw.source === "spotify" ? track.raw.engine : track.url;
|
|
638
|
+
if (!link)
|
|
639
|
+
return void this.play(this.tracks.shift(), { immediate: true });
|
|
640
|
+
if (customDownloader) {
|
|
641
|
+
stream = (await this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this)) ?? null;
|
|
642
|
+
if (stream)
|
|
643
|
+
stream = discord_ytdl_core_1.default
|
|
644
|
+
.arbitraryStream(stream, {
|
|
645
|
+
opusEncoded: false,
|
|
646
|
+
fmt: "s16le",
|
|
647
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
648
|
+
seek: options.seek ? options.seek / 1000 : 0
|
|
649
|
+
})
|
|
650
|
+
.on("error", (err) => {
|
|
675
651
|
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
676
652
|
});
|
|
677
|
-
}
|
|
678
653
|
}
|
|
679
654
|
else {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
: track.raw.source === "soundcloud"
|
|
684
|
-
? yield track.raw.engine.downloadProgressive()
|
|
685
|
-
: typeof track.raw.engine === "function"
|
|
686
|
-
? yield track.raw.engine()
|
|
687
|
-
: track.raw.engine;
|
|
688
|
-
stream = discord_ytdl_core_1.default
|
|
689
|
-
.arbitraryStream(arbitrarySource, {
|
|
655
|
+
stream = (0, discord_ytdl_core_1.default)(link, {
|
|
656
|
+
...this.options.ytdlOptions,
|
|
657
|
+
// discord-ytdl-core
|
|
690
658
|
opusEncoded: false,
|
|
691
659
|
fmt: "s16le",
|
|
692
|
-
encoderArgs:
|
|
660
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
693
661
|
seek: options.seek ? options.seek / 1000 : 0
|
|
694
|
-
})
|
|
695
|
-
.on("error", (err) => {
|
|
662
|
+
}).on("error", (err) => {
|
|
696
663
|
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
697
664
|
});
|
|
698
665
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
const tryArb = (customDownloader && (await this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null;
|
|
669
|
+
const arbitrarySource = tryArb
|
|
670
|
+
? tryArb
|
|
671
|
+
: track.raw.source === "soundcloud"
|
|
672
|
+
? await track.raw.engine.downloadProgressive()
|
|
673
|
+
: typeof track.raw.engine === "function"
|
|
674
|
+
? await track.raw.engine()
|
|
675
|
+
: track.raw.engine;
|
|
676
|
+
stream = discord_ytdl_core_1.default
|
|
677
|
+
.arbitraryStream(arbitrarySource, {
|
|
678
|
+
opusEncoded: false,
|
|
679
|
+
fmt: "s16le",
|
|
680
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
681
|
+
seek: options.seek ? options.seek / 1000 : 0
|
|
682
|
+
})
|
|
683
|
+
.on("error", (err) => {
|
|
684
|
+
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
703
685
|
});
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
if (typeof volumeTransformer.setSmoothness === "function")
|
|
710
|
-
volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
|
711
|
-
}
|
|
712
|
-
this.setVolume(this.options.initialVolume);
|
|
713
|
-
setTimeout(() => {
|
|
714
|
-
this.connection.playStream(resource);
|
|
715
|
-
}, tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_getBufferingTimeout).call(this)).unref();
|
|
686
|
+
}
|
|
687
|
+
const resource = this.connection.createStream(stream, {
|
|
688
|
+
type: voice_1.StreamType.Raw,
|
|
689
|
+
data: track,
|
|
690
|
+
disableVolume: Boolean(this.options.disableVolume)
|
|
716
691
|
});
|
|
692
|
+
if (options.seek)
|
|
693
|
+
this._streamTime = options.seek;
|
|
694
|
+
this._filtersUpdate = options.filtersUpdate;
|
|
695
|
+
const volumeTransformer = resource.volume;
|
|
696
|
+
if (volumeTransformer && typeof this.options.initialVolume === "number")
|
|
697
|
+
Reflect.set(volumeTransformer, "volume", Math.pow(this.options.initialVolume / 100, 1.660964));
|
|
698
|
+
if (volumeTransformer?.hasSmoothness && typeof this.options.volumeSmoothness === "number") {
|
|
699
|
+
if (typeof volumeTransformer.setSmoothness === "function")
|
|
700
|
+
volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
|
701
|
+
}
|
|
702
|
+
setTimeout(() => {
|
|
703
|
+
this.connection.playStream(resource);
|
|
704
|
+
}, tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_getBufferingTimeout).call(this)).unref();
|
|
717
705
|
}
|
|
718
706
|
/**
|
|
719
707
|
* Private method to handle autoplay
|
|
@@ -721,37 +709,39 @@ class Queue {
|
|
|
721
709
|
* @returns {Promise<void>}
|
|
722
710
|
* @private
|
|
723
711
|
*/
|
|
724
|
-
_handleAutoplay(track) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
712
|
+
async _handleAutoplay(track) {
|
|
713
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
714
|
+
return;
|
|
715
|
+
if (!track || ![track.source, track.raw?.source].includes("youtube")) {
|
|
716
|
+
if (this.options.leaveOnEnd)
|
|
717
|
+
this.destroy();
|
|
718
|
+
return void this.player.emit("queueEnd", this);
|
|
719
|
+
}
|
|
720
|
+
let info = await youtube_sr_1.default.getVideo(track.url)
|
|
721
|
+
.then((x) => x.videos[0])
|
|
722
|
+
.catch(Util_1.Util.noop);
|
|
723
|
+
// fallback
|
|
724
|
+
if (!info)
|
|
725
|
+
info = await youtube_sr_1.default.search(track.author)
|
|
726
|
+
.then((x) => x[0])
|
|
736
727
|
.catch(Util_1.Util.noop);
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
});
|
|
753
|
-
this.play(nextTrack, { immediate: true });
|
|
728
|
+
if (!info) {
|
|
729
|
+
if (this.options.leaveOnEnd)
|
|
730
|
+
this.destroy();
|
|
731
|
+
return void this.player.emit("queueEnd", this);
|
|
732
|
+
}
|
|
733
|
+
const nextTrack = new Track_1.default(this.player, {
|
|
734
|
+
title: info.title,
|
|
735
|
+
url: `https://www.youtube.com/watch?v=${info.id}`,
|
|
736
|
+
duration: info.durationFormatted ? Util_1.Util.buildTimeCode(Util_1.Util.parseMS(info.duration * 1000)) : "0:00",
|
|
737
|
+
description: "",
|
|
738
|
+
thumbnail: typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url,
|
|
739
|
+
views: info.views,
|
|
740
|
+
author: info.channel.name,
|
|
741
|
+
requestedBy: track.requestedBy,
|
|
742
|
+
source: "youtube"
|
|
754
743
|
});
|
|
744
|
+
this.play(nextTrack, { immediate: true });
|
|
755
745
|
}
|
|
756
746
|
*[(_Queue_lastVolume = new WeakMap(), _Queue_destroyed = new WeakMap(), _Queue_instances = new WeakSet(), Symbol.iterator)]() {
|
|
757
747
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
@@ -763,13 +753,12 @@ class Queue {
|
|
|
763
753
|
* @returns {object}
|
|
764
754
|
*/
|
|
765
755
|
toJSON() {
|
|
766
|
-
var _a, _b;
|
|
767
756
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
768
757
|
return;
|
|
769
758
|
return {
|
|
770
759
|
id: this.id,
|
|
771
760
|
guild: this.guild.id,
|
|
772
|
-
voiceChannel:
|
|
761
|
+
voiceChannel: this.connection?.channel?.id,
|
|
773
762
|
options: this.options,
|
|
774
763
|
tracks: this.tracks.map((m) => m.toJSON())
|
|
775
764
|
};
|