distube 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/constant.ts
5
- var version = "5.2.0";
5
+ var version = "5.2.1";
6
6
  var AUDIO_SAMPLE_RATE = 48e3;
7
7
  var AUDIO_CHANNELS = 2;
8
8
  var DEFAULT_VOLUME = 50;
@@ -971,7 +971,7 @@ var Queue = class extends DisTubeBase {
971
971
  if (position > 0) {
972
972
  if (position >= this.songs.length) {
973
973
  if (this.autoplay) {
974
- await this.addRelatedSong();
974
+ await this._addRelatedSong();
975
975
  } else {
976
976
  throw new DisTubeError("NO_UP_NEXT");
977
977
  }
@@ -1014,12 +1014,17 @@ var Queue = class extends DisTubeBase {
1014
1014
  * @param time - Time in seconds
1015
1015
  * @returns The guild queue
1016
1016
  */
1017
- seek(time) {
1018
- if (typeof time !== "number") throw new DisTubeError("INVALID_TYPE", "number", time, "time");
1019
- if (Number.isNaN(time) || time < 0) throw new DisTubeError("NUMBER_COMPARE", "time", "bigger or equal to", 0);
1020
- this._beginTime = time;
1021
- this.play(false);
1022
- return this;
1017
+ async seek(time) {
1018
+ await this._taskQueue.queuing();
1019
+ try {
1020
+ if (typeof time !== "number") throw new DisTubeError("INVALID_TYPE", "number", time, "time");
1021
+ if (Number.isNaN(time) || time < 0) throw new DisTubeError("NUMBER_COMPARE", "time", "bigger or equal to", 0);
1022
+ this._beginTime = time;
1023
+ await this.play(false);
1024
+ return this;
1025
+ } finally {
1026
+ this._taskQueue.resolve();
1027
+ }
1023
1028
  }
1024
1029
  async #getRelatedSong(current) {
1025
1030
  const plugin = await this.handler._getPluginFromSong(current);
@@ -1027,11 +1032,11 @@ var Queue = class extends DisTubeBase {
1027
1032
  return [];
1028
1033
  }
1029
1034
  /**
1030
- * Add a related song of the playing song to the queue
1031
- * @param song - The song to get related songs from. Defaults to the current playing song.
1032
- * @returns The added song
1035
+ * Internal implementation of addRelatedSong without task queue protection.
1036
+ * Used by methods that already hold the task queue lock.
1037
+ * @internal
1033
1038
  */
1034
- async addRelatedSong(song) {
1039
+ async _addRelatedSong(song) {
1035
1040
  const current = song ?? this.songs?.[0];
1036
1041
  if (!current) throw new DisTubeError("NO_PLAYING_SONG");
1037
1042
  const prevIds = this.previousSongs.map((p) => p.id);
@@ -1049,6 +1054,19 @@ var Queue = class extends DisTubeBase {
1049
1054
  this.addToQueue(nextSong);
1050
1055
  return nextSong;
1051
1056
  }
1057
+ /**
1058
+ * Add a related song of the playing song to the queue
1059
+ * @param song - The song to get related songs from. Defaults to the current playing song.
1060
+ * @returns The added song
1061
+ */
1062
+ async addRelatedSong(song) {
1063
+ await this._taskQueue.queuing();
1064
+ try {
1065
+ return await this._addRelatedSong(song);
1066
+ } finally {
1067
+ this._taskQueue.resolve();
1068
+ }
1069
+ }
1052
1070
  /**
1053
1071
  * Stop the guild stream and delete the queue
1054
1072
  */
@@ -1959,7 +1977,7 @@ var QueueManager = class extends GuildIdManager {
1959
1977
  if (queue.songs.length === 0 && queue.autoplay) {
1960
1978
  try {
1961
1979
  this.debug(`[QueueManager] Adding related song: ${queue.id}`);
1962
- await queue.addRelatedSong(song);
1980
+ await queue._addRelatedSong(song);
1963
1981
  } catch (e) {
1964
1982
  const errorMessage = e instanceof Error ? e.message : String(e);
1965
1983
  this.debug(`[${queue.id}] Add related song error: ${errorMessage}`);
@@ -2239,16 +2257,16 @@ var DisTube = class extends TypedEmitter3 {
2239
2257
  if (!resolved.songs.length) throw new DisTubeError("EMPTY_PLAYLIST");
2240
2258
  this.debug(`[${queue.id}] Adding playlist to queue: ${resolved.songs.length} songs`);
2241
2259
  queue.addToQueue(resolved.songs, position);
2242
- if (queue.playing || this.options.emitAddListWhenCreatingQueue) this.emit("addList" /* ADD_LIST */, queue, resolved);
2260
+ if (!queue.stopped || this.options.emitAddListWhenCreatingQueue) this.emit("addList" /* ADD_LIST */, queue, resolved);
2243
2261
  } else {
2244
2262
  if (!this.options.nsfw && resolved.ageRestricted && !isNsfwChannel(queue?.textChannel || textChannel)) {
2245
2263
  throw new DisTubeError("NON_NSFW");
2246
2264
  }
2247
2265
  this.debug(`[${queue.id}] Adding song to queue: ${resolved.name || resolved.url || resolved.id || resolved}`);
2248
2266
  queue.addToQueue(resolved, position);
2249
- if (queue.playing || this.options.emitAddSongWhenCreatingQueue) this.emit("addSong" /* ADD_SONG */, queue, resolved);
2267
+ if (!queue.stopped || this.options.emitAddSongWhenCreatingQueue) this.emit("addSong" /* ADD_SONG */, queue, resolved);
2250
2268
  }
2251
- if (!queue.playing) await queue.play();
2269
+ if (queue.stopped) await queue.play();
2252
2270
  else if (skip) await queue.skip();
2253
2271
  } catch (e) {
2254
2272
  if (!(e instanceof DisTubeError)) {