@kattowo/distube 6.2.1 → 6.2.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/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 = "6.2.1";
5
+ var version = "6.2.2";
6
6
  var AUDIO_SAMPLE_RATE = 48e3;
7
7
  var AUDIO_CHANNELS = 2;
8
8
  var DEFAULT_VOLUME = 50;
@@ -2548,8 +2548,8 @@ var Options = class {
2548
2548
  if (typeof value !== "object" || Array.isArray(value)) {
2549
2549
  throw new DisTubeError("INVALID_TYPE", "object", value, "DisTubeOptions.crossfade");
2550
2550
  }
2551
- checkInvalidKey(value, ["duration", "curve", "warmup"], "DisTubeOptions.crossfade");
2552
- const { duration, curve, warmup } = value;
2551
+ checkInvalidKey(value, ["duration", "curve", "warmup", "preparePrimaryInput"], "DisTubeOptions.crossfade");
2552
+ const { duration, curve, warmup, preparePrimaryInput } = value;
2553
2553
  if (duration !== void 0 && (typeof duration !== "number" || Number.isNaN(duration) || duration < 0)) {
2554
2554
  throw new DisTubeError(
2555
2555
  "INVALID_TYPE",
@@ -2572,10 +2572,19 @@ var Options = class {
2572
2572
  if (warmup !== void 0 && (typeof warmup !== "number" || Number.isNaN(warmup) || warmup < 0)) {
2573
2573
  throw new DisTubeError("INVALID_TYPE", "number >= 0", warmup, "DisTubeOptions.crossfade.warmup");
2574
2574
  }
2575
+ if (preparePrimaryInput !== void 0 && typeof preparePrimaryInput !== "function") {
2576
+ throw new DisTubeError(
2577
+ "INVALID_TYPE",
2578
+ "function",
2579
+ preparePrimaryInput,
2580
+ "DisTubeOptions.crossfade.preparePrimaryInput"
2581
+ );
2582
+ }
2575
2583
  return {
2576
2584
  duration: duration ?? DEFAULT_CROSSFADE_DURATION_SECS,
2577
2585
  curve: curve ?? DEFAULT_CROSSFADE_CURVE,
2578
- warmup: warmup ?? DEFAULT_CROSSFADE_WARMUP_SECS
2586
+ warmup: warmup ?? DEFAULT_CROSSFADE_WARMUP_SECS,
2587
+ preparePrimaryInput
2579
2588
  };
2580
2589
  }
2581
2590
  #validateOptions(options = this) {
@@ -2798,13 +2807,15 @@ var DisTubeStream = class extends TypedEmitter2 {
2798
2807
  const extraFilters = typeof outputArgs.af === "string" ? outputArgs.af : Array.isArray(outputArgs.af) ? outputArgs.af.filter(Boolean).join(",") : void 0;
2799
2808
  delete outputArgs.af;
2800
2809
  const primaryOpts = {
2801
- reconnect: 1,
2802
- reconnect_streamed: 1,
2803
- reconnect_delay_max: 5,
2804
- analyzeduration: 0,
2805
2810
  hide_banner: true,
2806
2811
  ...ffmpeg.args.global,
2807
- ...ffmpeg.args.input,
2812
+ ...crossfade.primaryInputArgs ?? {
2813
+ reconnect: 1,
2814
+ reconnect_streamed: 1,
2815
+ reconnect_delay_max: 5,
2816
+ analyzeduration: 0,
2817
+ ...ffmpeg.args.input
2818
+ },
2808
2819
  ss: typeof primarySeek === "number" && primarySeek > 0 ? primarySeek.toString() : null,
2809
2820
  i: url
2810
2821
  };
@@ -3383,7 +3394,28 @@ var QueueManager = class extends GuildIdManager {
3383
3394
  if (!primary?.stream.playFromSource || !primary.stream.url) return;
3384
3395
  if (!secondary?.stream.playFromSource || !secondary.stream.url) return;
3385
3396
  this.debug(`[${queue.id}] Warming up crossfade stream: ${song} -> ${nextSong}`);
3386
- transitionStream = new DisTubeStream(primary.stream.url, {
3397
+ const boundarySeek = Math.max(0, songDuration - fade);
3398
+ let primaryUrl = primary.stream.url;
3399
+ let primarySeek = boundarySeek;
3400
+ let primaryInputArgs;
3401
+ const prepare = this.options.crossfade.preparePrimaryInput;
3402
+ if (prepare) {
3403
+ try {
3404
+ const prepared = await prepare(primary.stream.url, { seek: boundarySeek, song });
3405
+ if (prepared?.url) {
3406
+ primaryUrl = prepared.url;
3407
+ if (typeof prepared.seek === "number" && Number.isFinite(prepared.seek) && prepared.seek >= 0) {
3408
+ primarySeek = prepared.seek;
3409
+ }
3410
+ primaryInputArgs = prepared.inputArgs;
3411
+ this.debug(`[${queue.id}] Crossfade primary input prepared by the adapter`);
3412
+ }
3413
+ } catch (e) {
3414
+ const errorMessage = e instanceof Error ? e.message : String(e);
3415
+ this.debug(`[${queue.id}] Crossfade primary input preparation failed: ${errorMessage}`);
3416
+ }
3417
+ }
3418
+ transitionStream = new DisTubeStream(primaryUrl, {
3387
3419
  ffmpeg: {
3388
3420
  path: this.options.ffmpeg.path,
3389
3421
  args: {
@@ -3394,10 +3426,11 @@ var QueueManager = class extends GuildIdManager {
3394
3426
  },
3395
3427
  crossfade: {
3396
3428
  duration: fade,
3397
- primarySeek: Math.max(0, songDuration - fade),
3429
+ primarySeek,
3398
3430
  secondaryUrl: secondary.stream.url,
3399
3431
  inCurve: this.options.crossfade.curve,
3400
- outCurve: this.options.crossfade.curve
3432
+ outCurve: this.options.crossfade.curve,
3433
+ primaryInputArgs
3401
3434
  }
3402
3435
  });
3403
3436
  transitionStream.on("debug", (data) => this.emit("ffmpegDebug" /* FFMPEG_DEBUG */, `[${queue.id}] [crossfade] ${data}`));