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.
@@ -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={}] Player options for the queue
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 (_b = (_a = this.connection.audioResource) === null || _a === void 0 ? void 0 : _a.metadata) !== null && _b !== void 0 ? _b : this.tracks[0];
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
135
- if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
136
- return;
137
- const _channel = this.guild.channels.resolve(channel);
138
- if (!["GUILD_STAGE_VOICE", "GUILD_VOICE"].includes(_channel === null || _channel === void 0 ? void 0 : _channel.type))
139
- throw new PlayerError_1.PlayerError(`Channel type must be GUILD_VOICE or GUILD_STAGE_VOICE, got ${_channel === null || _channel === void 0 ? void 0 : _channel.type}!`, PlayerError_1.ErrorStatusCode.INVALID_ARG_TYPE);
140
- const connection = yield this.player.voiceUtils.connect(_channel, {
141
- deaf: this.options.autoSelfDeaf
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
- this.connection = connection;
144
- if (_channel.type === "GUILD_STAGE_VOICE") {
145
- yield _channel.guild.me.voice.setSuppressed(false).catch(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
146
- return yield _channel.guild.me.voice.setRequestToSpeak(true).catch(Util_1.Util.noop);
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
- (_a = this.connection) === null || _a === void 0 ? void 0 : _a.disconnect();
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 (!((_b = (_a = this.connection) === null || _a === void 0 ? void 0 : _a.audioResource) === null || _b === void 0 ? void 0 : _b.encoder))
270
+ if (!this.connection?.audioResource?.encoder)
280
271
  return;
281
272
  if (bitrate === "auto")
282
- bitrate = (_d = (_c = this.connection.channel) === null || _c === void 0 ? void 0 : _c.bitrate) !== null && _d !== void 0 ? _d : 64000;
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
374
- if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
375
- return;
376
- if (!filters || !Object.keys(filters).length) {
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 = _filters;
397
- return yield this.play(this.current, {
369
+ this._activeFilters = [];
370
+ return await this.play(this.current, {
398
371
  immediate: true,
399
372
  filtersUpdate: true,
400
373
  seek: streamTime,
401
- encoderArgs: !_filters.length ? undefined : ["-af", newFilters]
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
412
- if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
413
- return;
414
- if (!this.playing || !this.current)
415
- return false;
416
- if (position < 1)
417
- position = 0;
418
- if (position >= this.current.durationMS)
419
- return this.skip();
420
- yield this.play(this.current, {
421
- immediate: true,
422
- filtersUpdate: true,
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
434
- if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
435
- return;
436
- const prev = this.previousTracks[this.previousTracks.length - 2]; // because last item is the current track
437
- if (!prev)
438
- throw new PlayerError_1.PlayerError("Could not find previous track", PlayerError_1.ErrorStatusCode.TRACK_NOT_FOUND);
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|Snowflake|number} track The track to remove
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|Snowflake} track The 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={}] The options
609
+ * @param {PlayOptions} [options] The options
625
610
  * @returns {Promise<void>}
626
611
  */
627
- play(src, options = {}) {
628
- var _a, _b, _c, _d;
629
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
630
- if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this, false))
631
- return;
632
- if (!this.connection || !this.connection.voiceConnection)
633
- throw new PlayerError_1.PlayerError("Voice connection is not available, use <Queue>.connect()!", PlayerError_1.ErrorStatusCode.NO_CONNECTION);
634
- if (src && (this.playing || this.tracks.length) && !options.immediate)
635
- return this.addTrack(src);
636
- const track = options.filtersUpdate && !options.immediate ? src || this.current : src !== null && src !== void 0 ? src : this.tracks.shift();
637
- if (!track)
638
- return;
639
- this.player.emit("debug", this, "Received play request");
640
- if (!options.filtersUpdate) {
641
- this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
642
- this.previousTracks.push(track);
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
- let stream = null;
645
- const customDownloader = typeof this.onBeforeCreateStream === "function";
646
- if (["youtube", "spotify"].includes(track.raw.source)) {
647
- let spotifyResolved = false;
648
- if (this.options.spotifyBridge && track.raw.source === "spotify" && !track.raw.engine) {
649
- track.raw.engine = yield youtube_sr_1.default.search(`${track.author} ${track.title}`, { type: "video" })
650
- .then((x) => x[0].url)
651
- .catch(() => null);
652
- spotifyResolved = true;
653
- }
654
- const link = track.raw.source === "spotify" ? track.raw.engine : track.url;
655
- if (!link)
656
- return void this.play(this.tracks.shift(), { immediate: true });
657
- if (customDownloader) {
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
- const tryArb = (customDownloader && (yield this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null;
681
- const arbitrarySource = tryArb
682
- ? tryArb
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: ((_d = options.encoderArgs) !== null && _d !== void 0 ? _d : this._activeFilters.length) ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
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
- const resource = this.connection.createStream(stream, {
700
- type: voice_1.StreamType.Raw,
701
- data: track,
702
- disableVolume: Boolean(this.options.disableVolume)
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
- if (options.seek)
705
- this._streamTime = options.seek;
706
- this._filtersUpdate = options.filtersUpdate;
707
- const volumeTransformer = resource.volume;
708
- if ((volumeTransformer === null || volumeTransformer === void 0 ? void 0 : volumeTransformer.hasSmoothness) && typeof this.options.volumeSmoothness === "number") {
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
- var _a;
726
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
727
- if (tslib_1.__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_watchDestroyed).call(this))
728
- return;
729
- if (!track || ![track.source, (_a = track.raw) === null || _a === void 0 ? void 0 : _a.source].includes("youtube")) {
730
- if (this.options.leaveOnEnd)
731
- this.destroy();
732
- return void this.player.emit("queueEnd", this);
733
- }
734
- const info = yield youtube_sr_1.default.getVideo(track.url)
735
- .then((x) => x.videos[0])
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
- if (!info) {
738
- if (this.options.leaveOnEnd)
739
- this.destroy();
740
- return void this.player.emit("queueEnd", this);
741
- }
742
- const nextTrack = new Track_1.default(this.player, {
743
- title: info.title,
744
- url: `https://www.youtube.com/watch?v=${info.id}`,
745
- duration: info.durationFormatted ? Util_1.Util.buildTimeCode(Util_1.Util.parseMS(info.duration * 1000)) : "0:00",
746
- description: "",
747
- thumbnail: typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url,
748
- views: info.views,
749
- author: info.channel.name,
750
- requestedBy: track.requestedBy,
751
- source: "youtube"
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: (_b = (_a = this.connection) === null || _a === void 0 ? void 0 : _a.channel) === null || _b === void 0 ? void 0 : _b.id,
761
+ voiceChannel: this.connection?.channel?.id,
773
762
  options: this.options,
774
763
  tracks: this.tracks.map((m) => m.toJSON())
775
764
  };