discord-player 5.2.3-dev → 5.3.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 +23 -19
- package/dist/Player.js +283 -274
- package/dist/Structures/ExtractorModel.js +19 -24
- package/dist/Structures/Playlist.js +1 -2
- package/dist/Structures/Queue.js +223 -236
- package/dist/Structures/Track.js +11 -14
- package/dist/VoiceInterface/StreamDispatcher.js +32 -40
- package/dist/VoiceInterface/VoiceUtils.js +21 -29
- package/dist/index.d.ts +10 -7
- package/dist/smoothVolume.js +1 -1
- package/dist/utils/Util.js +34 -1
- package/package.json +24 -28
package/dist/Structures/Queue.js
CHANGED
|
@@ -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,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
|
-
|
|
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);
|
|
148
180
|
}
|
|
149
|
-
this.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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;
|
|
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
|
|
201
196
|
});
|
|
197
|
+
return this;
|
|
202
198
|
}
|
|
203
199
|
/**
|
|
204
200
|
* Destroys this queue
|
|
@@ -206,13 +202,12 @@ class Queue {
|
|
|
206
202
|
* @returns {void}
|
|
207
203
|
*/
|
|
208
204
|
destroy(disconnect = this.options.leaveOnStop) {
|
|
209
|
-
var _a;
|
|
210
205
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
211
206
|
return;
|
|
212
207
|
if (this.connection)
|
|
213
208
|
this.connection.end();
|
|
214
209
|
if (disconnect)
|
|
215
|
-
|
|
210
|
+
this.connection?.disconnect();
|
|
216
211
|
this.player.queues.delete(this.guild.id);
|
|
217
212
|
this.player.voiceUtils.cache.delete(this.guild.id);
|
|
218
213
|
tslib_1.__classPrivateFieldSet(this, _Queue_destroyed, true, "f");
|
|
@@ -273,13 +268,12 @@ class Queue {
|
|
|
273
268
|
* @returns {void}
|
|
274
269
|
*/
|
|
275
270
|
setBitrate(bitrate) {
|
|
276
|
-
var _a, _b, _c, _d;
|
|
277
271
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
278
272
|
return;
|
|
279
|
-
if (!
|
|
273
|
+
if (!this.connection?.audioResource?.encoder)
|
|
280
274
|
return;
|
|
281
275
|
if (bitrate === "auto")
|
|
282
|
-
bitrate =
|
|
276
|
+
bitrate = this.connection.channel?.bitrate ?? 64000;
|
|
283
277
|
this.connection.audioResource.encoder.setBitrate(bitrate);
|
|
284
278
|
}
|
|
285
279
|
/**
|
|
@@ -369,37 +363,35 @@ class Queue {
|
|
|
369
363
|
* @param {QueueFilters} filters Queue filters
|
|
370
364
|
* @returns {Promise<void>}
|
|
371
365
|
*/
|
|
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();
|
|
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
|
|
395
371
|
const streamTime = this.streamTime;
|
|
396
|
-
this._activeFilters =
|
|
397
|
-
return
|
|
372
|
+
this._activeFilters = [];
|
|
373
|
+
return await this.play(this.current, {
|
|
398
374
|
immediate: true,
|
|
399
375
|
filtersUpdate: true,
|
|
400
376
|
seek: streamTime,
|
|
401
|
-
encoderArgs:
|
|
377
|
+
encoderArgs: []
|
|
402
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]
|
|
403
395
|
});
|
|
404
396
|
}
|
|
405
397
|
/**
|
|
@@ -407,37 +399,33 @@ class Queue {
|
|
|
407
399
|
* @param {number} position The position
|
|
408
400
|
* @returns {boolean}
|
|
409
401
|
*/
|
|
410
|
-
seek(position) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
seek: position
|
|
424
|
-
});
|
|
425
|
-
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
|
|
426
415
|
});
|
|
416
|
+
return true;
|
|
427
417
|
}
|
|
428
418
|
/**
|
|
429
419
|
* Plays previous track
|
|
430
420
|
* @returns {Promise<void>}
|
|
431
421
|
*/
|
|
432
|
-
back() {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return yield this.play(prev, { immediate: true });
|
|
440
|
-
});
|
|
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 });
|
|
441
429
|
}
|
|
442
430
|
/**
|
|
443
431
|
* Clear this queue
|
|
@@ -476,7 +464,7 @@ class Queue {
|
|
|
476
464
|
}
|
|
477
465
|
/**
|
|
478
466
|
* Removes a track from the queue
|
|
479
|
-
* @param {Track|
|
|
467
|
+
* @param {Track|string|number} track The track to remove
|
|
480
468
|
* @returns {Track}
|
|
481
469
|
*/
|
|
482
470
|
remove(track) {
|
|
@@ -499,7 +487,7 @@ class Queue {
|
|
|
499
487
|
}
|
|
500
488
|
/**
|
|
501
489
|
* Returns the index of the specified track. If found, returns the track index else returns -1.
|
|
502
|
-
* @param {number|Track|
|
|
490
|
+
* @param {number|Track|string} track The track
|
|
503
491
|
* @returns {number}
|
|
504
492
|
*/
|
|
505
493
|
getTrackPosition(track) {
|
|
@@ -624,96 +612,99 @@ class Queue {
|
|
|
624
612
|
* @param {PlayOptions} [options={}] The options
|
|
625
613
|
* @returns {Promise<void>}
|
|
626
614
|
*/
|
|
627
|
-
play(src, options = {}) {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
this.
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
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;
|
|
643
639
|
}
|
|
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) => {
|
|
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) => {
|
|
675
654
|
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
676
655
|
});
|
|
677
|
-
}
|
|
678
656
|
}
|
|
679
657
|
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, {
|
|
658
|
+
stream = (0, discord_ytdl_core_1.default)(link, {
|
|
659
|
+
...this.options.ytdlOptions,
|
|
660
|
+
// discord-ytdl-core
|
|
690
661
|
opusEncoded: false,
|
|
691
662
|
fmt: "s16le",
|
|
692
|
-
encoderArgs:
|
|
663
|
+
encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
|
|
693
664
|
seek: options.seek ? options.seek / 1000 : 0
|
|
694
|
-
})
|
|
695
|
-
.on("error", (err) => {
|
|
665
|
+
}).on("error", (err) => {
|
|
696
666
|
return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
|
|
697
667
|
});
|
|
698
668
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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);
|
|
703
688
|
});
|
|
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();
|
|
689
|
+
}
|
|
690
|
+
const resource = this.connection.createStream(stream, {
|
|
691
|
+
type: voice_1.StreamType.Raw,
|
|
692
|
+
data: track,
|
|
693
|
+
disableVolume: Boolean(this.options.disableVolume)
|
|
716
694
|
});
|
|
695
|
+
if (options.seek)
|
|
696
|
+
this._streamTime = options.seek;
|
|
697
|
+
this._filtersUpdate = options.filtersUpdate;
|
|
698
|
+
const volumeTransformer = resource.volume;
|
|
699
|
+
if (volumeTransformer && typeof this.options.initialVolume === "number")
|
|
700
|
+
Reflect.set(volumeTransformer, "volume", Math.pow(this.options.initialVolume, 1.660964));
|
|
701
|
+
if (volumeTransformer?.hasSmoothness && typeof this.options.volumeSmoothness === "number") {
|
|
702
|
+
if (typeof volumeTransformer.setSmoothness === "function")
|
|
703
|
+
volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
|
704
|
+
}
|
|
705
|
+
setTimeout(() => {
|
|
706
|
+
this.connection.playStream(resource);
|
|
707
|
+
}, tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_getBufferingTimeout).call(this)).unref();
|
|
717
708
|
}
|
|
718
709
|
/**
|
|
719
710
|
* Private method to handle autoplay
|
|
@@ -721,37 +712,34 @@ class Queue {
|
|
|
721
712
|
* @returns {Promise<void>}
|
|
722
713
|
* @private
|
|
723
714
|
*/
|
|
724
|
-
_handleAutoplay(track) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
requestedBy: track.requestedBy,
|
|
751
|
-
source: "youtube"
|
|
752
|
-
});
|
|
753
|
-
this.play(nextTrack, { immediate: true });
|
|
715
|
+
async _handleAutoplay(track) {
|
|
716
|
+
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
717
|
+
return;
|
|
718
|
+
if (!track || ![track.source, track.raw?.source].includes("youtube")) {
|
|
719
|
+
if (this.options.leaveOnEnd)
|
|
720
|
+
this.destroy();
|
|
721
|
+
return void this.player.emit("queueEnd", this);
|
|
722
|
+
}
|
|
723
|
+
const info = await youtube_sr_1.default.getVideo(track.url)
|
|
724
|
+
.then((x) => x.videos[0])
|
|
725
|
+
.catch(Util_1.Util.noop);
|
|
726
|
+
if (!info) {
|
|
727
|
+
if (this.options.leaveOnEnd)
|
|
728
|
+
this.destroy();
|
|
729
|
+
return void this.player.emit("queueEnd", this);
|
|
730
|
+
}
|
|
731
|
+
const nextTrack = new Track_1.default(this.player, {
|
|
732
|
+
title: info.title,
|
|
733
|
+
url: `https://www.youtube.com/watch?v=${info.id}`,
|
|
734
|
+
duration: info.durationFormatted ? Util_1.Util.buildTimeCode(Util_1.Util.parseMS(info.duration * 1000)) : "0:00",
|
|
735
|
+
description: "",
|
|
736
|
+
thumbnail: typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url,
|
|
737
|
+
views: info.views,
|
|
738
|
+
author: info.channel.name,
|
|
739
|
+
requestedBy: track.requestedBy,
|
|
740
|
+
source: "youtube"
|
|
754
741
|
});
|
|
742
|
+
this.play(nextTrack, { immediate: true });
|
|
755
743
|
}
|
|
756
744
|
*[(_Queue_lastVolume = new WeakMap(), _Queue_destroyed = new WeakMap(), _Queue_instances = new WeakSet(), Symbol.iterator)]() {
|
|
757
745
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
@@ -763,13 +751,12 @@ class Queue {
|
|
|
763
751
|
* @returns {object}
|
|
764
752
|
*/
|
|
765
753
|
toJSON() {
|
|
766
|
-
var _a, _b;
|
|
767
754
|
if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
|
|
768
755
|
return;
|
|
769
756
|
return {
|
|
770
757
|
id: this.id,
|
|
771
758
|
guild: this.guild.id,
|
|
772
|
-
voiceChannel:
|
|
759
|
+
voiceChannel: this.connection?.channel?.id,
|
|
773
760
|
options: this.options,
|
|
774
761
|
tracks: this.tracks.map((m) => m.toJSON())
|
|
775
762
|
};
|