discord-player 5.3.0-dev.2 → 5.3.0-dev.3

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.
@@ -6,12 +6,13 @@ const tslib_1 = require("tslib");
6
6
  const discord_js_1 = require("discord.js");
7
7
  const Track_1 = tslib_1.__importDefault(require("./Track"));
8
8
  const types_1 = require("../types/types");
9
- const discord_ytdl_core_1 = tslib_1.__importDefault(require("discord-ytdl-core"));
9
+ const ytdl_core_1 = tslib_1.__importDefault(require("ytdl-core"));
10
10
  const voice_1 = require("@discordjs/voice");
11
11
  const Util_1 = require("../utils/Util");
12
12
  const youtube_sr_1 = tslib_1.__importDefault(require("youtube-sr"));
13
13
  const AudioFilters_1 = tslib_1.__importDefault(require("../utils/AudioFilters"));
14
14
  const PlayerError_1 = require("./PlayerError");
15
+ const FFmpegStream_1 = require("../utils/FFmpegStream");
15
16
  class Queue {
16
17
  /**
17
18
  * Queue constructor
@@ -625,66 +626,43 @@ class Queue {
625
626
  this.previousTracks.push(track);
626
627
  }
627
628
  let stream = null;
628
- const customDownloader = typeof this.onBeforeCreateStream === "function";
629
+ const hasCustomDownloader = typeof this.onBeforeCreateStream === "function";
629
630
  if (["youtube", "spotify"].includes(track.raw.source)) {
630
631
  let spotifyResolved = false;
631
632
  if (this.options.spotifyBridge && track.raw.source === "spotify" && !track.raw.engine) {
632
633
  track.raw.engine = await youtube_sr_1.default.search(`${track.author} ${track.title}`, { type: "video" })
633
- .then((x) => x[0].url)
634
+ .then((res) => res[0].url)
634
635
  .catch(() => null);
635
636
  spotifyResolved = true;
636
637
  }
637
- const link = track.raw.source === "spotify" ? track.raw.engine : track.url;
638
- if (!link)
638
+ const url = track.raw.source === "spotify" ? track.raw.engine : track.url;
639
+ if (!url)
639
640
  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) => {
651
- return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
652
- });
641
+ if (hasCustomDownloader) {
642
+ stream = (await this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this)) || null;
653
643
  }
654
- else {
655
- stream = (0, discord_ytdl_core_1.default)(link, {
656
- ...this.options.ytdlOptions,
657
- // discord-ytdl-core
658
- opusEncoded: false,
659
- fmt: "s16le",
660
- encoderArgs: options.encoderArgs ?? this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
661
- seek: options.seek ? options.seek / 1000 : 0
662
- }).on("error", (err) => {
663
- return err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err);
664
- });
644
+ if (!stream) {
645
+ stream = (0, ytdl_core_1.default)(url, this.options.ytdlOptions);
665
646
  }
666
647
  }
667
648
  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"
649
+ const arbitraryStream = (hasCustomDownloader && (await this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null;
650
+ stream =
651
+ arbitraryStream || track.raw.source === "soundcloud"
672
652
  ? await track.raw.engine.downloadProgressive()
673
653
  : typeof track.raw.engine === "function"
674
- ? await track.raw.engine()
654
+ ? await track.raw.engine
675
655
  : 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);
685
- });
686
656
  }
687
- const resource = this.connection.createStream(stream, {
657
+ const ffmpegStream = (0, FFmpegStream_1.createFFmpegStream)(stream, {
658
+ encoderArgs: options.encoderArgs || this._activeFilters.length ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [],
659
+ seek: options.seek ? options.seek / 1000 : 0,
660
+ fmt: "s16le"
661
+ }).on("error", (err) => {
662
+ if (!`${err}`.toLowerCase().includes("premature close"))
663
+ this.player.emit("error", this, err);
664
+ });
665
+ const resource = this.connection.createStream(ffmpegStream, {
688
666
  type: voice_1.StreamType.Raw,
689
667
  data: track,
690
668
  disableVolume: Boolean(this.options.disableVolume)
package/dist/index.d.ts CHANGED
@@ -1002,91 +1002,39 @@ interface PlayerInitOptions {
1002
1002
  connectionTimeout?: number;
1003
1003
  }
1004
1004
 
1005
- /**
1006
- * The available audio filters
1007
- * @typedef {object} AudioFilters
1008
- * @property {string} bassboost_low The bassboost filter (+15dB)
1009
- * @property {string} bassboost The bassboost filter (+20dB)
1010
- * @property {string} bassboost_high The bassboost filter (+30dB)
1011
- * @property {string} 8D The 8D filter
1012
- * @property {string} vaporwave The vaporwave filter
1013
- * @property {string} nightcore The nightcore filter
1014
- * @property {string} phaser The phaser filter
1015
- * @property {string} tremolo The tremolo filter
1016
- * @property {string} vibrato The vibrato filter
1017
- * @property {string} reverse The reverse filter
1018
- * @property {string} treble The treble filter
1019
- * @property {string} normalizer The normalizer filter (dynamic audio normalizer based)
1020
- * @property {string} normalizer2 The normalizer filter (audio compressor based)
1021
- * @property {string} surrounding The surrounding filter
1022
- * @property {string} pulsator The pulsator filter
1023
- * @property {string} subboost The subboost filter
1024
- * @property {string} karaoke The kakaoke filter
1025
- * @property {string} flanger The flanger filter
1026
- * @property {string} gate The gate filter
1027
- * @property {string} haas The haas filter
1028
- * @property {string} mcompand The mcompand filter
1029
- * @property {string} mono The mono filter
1030
- * @property {string} mstlr The mstlr filter
1031
- * @property {string} mstrr The mstrr filter
1032
- * @property {string} compressor The compressor filter
1033
- * @property {string} expander The expander filter
1034
- * @property {string} softlimiter The softlimiter filter
1035
- * @property {string} chorus The chorus filter
1036
- * @property {string} chorus2d The chorus2d filter
1037
- * @property {string} chorus3d The chorus3d filter
1038
- * @property {string} fadein The fadein filter
1039
- * @property {string} dim The dim filter
1040
- * @property {string} earrape The earrape filter
1041
- */
1042
- declare const FilterList: {
1043
- bassboost_low: string;
1044
- bassboost: string;
1045
- bassboost_high: string;
1046
- "8D": string;
1047
- vaporwave: string;
1048
- nightcore: string;
1049
- phaser: string;
1050
- tremolo: string;
1051
- vibrato: string;
1052
- reverse: string;
1053
- treble: string;
1054
- normalizer2: string;
1055
- normalizer: string;
1056
- surrounding: string;
1057
- pulsator: string;
1058
- subboost: string;
1059
- karaoke: string;
1060
- flanger: string;
1061
- gate: string;
1062
- haas: string;
1063
- mcompand: string;
1064
- mono: string;
1065
- mstlr: string;
1066
- mstrr: string;
1067
- compressor: string;
1068
- expander: string;
1069
- softlimiter: string;
1070
- chorus: string;
1071
- chorus2d: string;
1072
- chorus3d: string;
1073
- fadein: string;
1074
- dim: string;
1075
- earrape: string;
1076
- [Symbol.iterator](): IterableIterator<{
1005
+ declare class AudioFilters {
1006
+ constructor();
1007
+ static get filters(): Record<FiltersName, string>;
1008
+ static get<K extends FiltersName>(name: K): Record<keyof QueueFilters, string>[K];
1009
+ static has<K extends FiltersName>(name: K): boolean;
1010
+ static [Symbol.iterator](): IterableIterator<{
1077
1011
  name: FiltersName;
1078
1012
  value: string;
1079
1013
  }>;
1080
- readonly names: (keyof QueueFilters)[];
1081
- readonly length: number;
1082
- toString(): string;
1083
- create(filter?: FiltersName[]): string;
1084
- define(filterName: string, value: string): void;
1085
- defineBulk(filterArray: {
1014
+ static get names(): (keyof QueueFilters)[];
1015
+ static get length(): number;
1016
+ static toString(): string;
1017
+ /**
1018
+ * Create ffmpeg args from the specified filters name
1019
+ * @param filter The filter name
1020
+ * @returns
1021
+ */
1022
+ static create(filters?: FiltersName[]): string;
1023
+ /**
1024
+ * Defines audio filter
1025
+ * @param filterName The name of the filter
1026
+ * @param value The ffmpeg args
1027
+ */
1028
+ static define(filterName: string, value: string): void;
1029
+ /**
1030
+ * Defines multiple audio filters
1031
+ * @param filtersArray Array of filters containing the filter name and ffmpeg args
1032
+ */
1033
+ static defineBulk(filtersArray: {
1086
1034
  name: string;
1087
1035
  value: string;
1088
1036
  }[]): void;
1089
- };
1037
+ }
1090
1038
 
1091
1039
  declare enum ErrorStatusCode {
1092
1040
  STREAM_ERROR = "StreamError",
@@ -1190,6 +1138,21 @@ declare class Util {
1190
1138
  static getFetch(): Promise<any>;
1191
1139
  }
1192
1140
 
1141
+ interface FFmpegStreamOptions {
1142
+ fmt?: string;
1143
+ encoderArgs?: string[];
1144
+ seek?: number;
1145
+ skip?: boolean;
1146
+ }
1147
+ declare function FFMPEG_ARGS_STRING(stream: string, fmt?: string): string[];
1148
+ declare function FFMPEG_ARGS_PIPED(fmt?: string): string[];
1149
+ /**
1150
+ * Creates FFmpeg stream
1151
+ * @param stream The source stream
1152
+ * @param options FFmpeg stream options
1153
+ */
1154
+ declare function createFFmpegStream(stream: Readable | Duplex | string, options?: FFmpegStreamOptions): Readable | Duplex;
1155
+
1193
1156
  declare const version: string;
1194
1157
 
1195
- export { FilterList as AudioFilters, ErrorStatusCode, ExtractorModel, ExtractorModelData, FiltersName, PlayOptions, Player, PlayerError, PlayerEvents, PlayerInitOptions, PlayerOptions, PlayerProgressbarOptions, PlayerSearchResult, Playlist, PlaylistInitData, PlaylistJSON, QueryResolver, QueryType, Queue, QueueFilters, QueueRepeatMode, RawTrackData, SearchOptions, StreamDispatcher, TimeData, Track, TrackJSON, TrackSource, Util, VoiceEvents, VoiceUtils, version };
1158
+ export { AudioFilters, ErrorStatusCode, ExtractorModel, ExtractorModelData, FFMPEG_ARGS_PIPED, FFMPEG_ARGS_STRING, FFmpegStreamOptions, FiltersName, PlayOptions, Player, PlayerError, PlayerEvents, PlayerInitOptions, PlayerOptions, PlayerProgressbarOptions, PlayerSearchResult, Playlist, PlaylistInitData, PlaylistJSON, QueryResolver, QueryType, Queue, QueueFilters, QueueRepeatMode, RawTrackData, SearchOptions, StreamDispatcher, TimeData, Track, TrackJSON, TrackSource, Util, VoiceEvents, VoiceUtils, createFFmpegStream, version };
package/dist/index.js CHANGED
@@ -28,5 +28,6 @@ Object.defineProperty(exports, "StreamDispatcher", { enumerable: true, get: func
28
28
  var Util_1 = require("./utils/Util");
29
29
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return Util_1.Util; } });
30
30
  tslib_1.__exportStar(require("./types/types"), exports);
31
+ tslib_1.__exportStar(require("./utils/FFmpegStream"), exports);
31
32
  // eslint-disable-next-line @typescript-eslint/no-var-requires
32
33
  exports.version = require(`${__dirname}/../package.json`).version;
package/dist/index.mjs CHANGED
@@ -4,6 +4,8 @@ export default mod;
4
4
  export const AudioFilters = mod.AudioFilters;
5
5
  export const ErrorStatusCode = mod.ErrorStatusCode;
6
6
  export const ExtractorModel = mod.ExtractorModel;
7
+ export const FFMPEG_ARGS_PIPED = mod.FFMPEG_ARGS_PIPED;
8
+ export const FFMPEG_ARGS_STRING = mod.FFMPEG_ARGS_STRING;
7
9
  export const Player = mod.Player;
8
10
  export const PlayerError = mod.PlayerError;
9
11
  export const Playlist = mod.Playlist;
@@ -15,4 +17,5 @@ export const StreamDispatcher = mod.StreamDispatcher;
15
17
  export const Track = mod.Track;
16
18
  export const Util = mod.Util;
17
19
  export const VoiceUtils = mod.VoiceUtils;
20
+ export const createFFmpegStream = mod.createFFmpegStream;
18
21
  export const version = mod.version;
@@ -2,108 +2,97 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AudioFilters = void 0;
4
4
  const bass = (g) => `bass=g=${g}:f=110:w=0.3`;
5
- /**
6
- * The available audio filters
7
- * @typedef {object} AudioFilters
8
- * @property {string} bassboost_low The bassboost filter (+15dB)
9
- * @property {string} bassboost The bassboost filter (+20dB)
10
- * @property {string} bassboost_high The bassboost filter (+30dB)
11
- * @property {string} 8D The 8D filter
12
- * @property {string} vaporwave The vaporwave filter
13
- * @property {string} nightcore The nightcore filter
14
- * @property {string} phaser The phaser filter
15
- * @property {string} tremolo The tremolo filter
16
- * @property {string} vibrato The vibrato filter
17
- * @property {string} reverse The reverse filter
18
- * @property {string} treble The treble filter
19
- * @property {string} normalizer The normalizer filter (dynamic audio normalizer based)
20
- * @property {string} normalizer2 The normalizer filter (audio compressor based)
21
- * @property {string} surrounding The surrounding filter
22
- * @property {string} pulsator The pulsator filter
23
- * @property {string} subboost The subboost filter
24
- * @property {string} karaoke The kakaoke filter
25
- * @property {string} flanger The flanger filter
26
- * @property {string} gate The gate filter
27
- * @property {string} haas The haas filter
28
- * @property {string} mcompand The mcompand filter
29
- * @property {string} mono The mono filter
30
- * @property {string} mstlr The mstlr filter
31
- * @property {string} mstrr The mstrr filter
32
- * @property {string} compressor The compressor filter
33
- * @property {string} expander The expander filter
34
- * @property {string} softlimiter The softlimiter filter
35
- * @property {string} chorus The chorus filter
36
- * @property {string} chorus2d The chorus2d filter
37
- * @property {string} chorus3d The chorus3d filter
38
- * @property {string} fadein The fadein filter
39
- * @property {string} dim The dim filter
40
- * @property {string} earrape The earrape filter
41
- */
42
- const FilterList = {
43
- bassboost_low: bass(15),
44
- bassboost: bass(20),
45
- bassboost_high: bass(30),
46
- "8D": "apulsator=hz=0.09",
47
- vaporwave: "aresample=48000,asetrate=48000*0.8",
48
- nightcore: "aresample=48000,asetrate=48000*1.25",
49
- phaser: "aphaser=in_gain=0.4",
50
- tremolo: "tremolo",
51
- vibrato: "vibrato=f=6.5",
52
- reverse: "areverse",
53
- treble: "treble=g=5",
54
- normalizer2: "dynaudnorm=g=101",
55
- normalizer: "acompressor",
56
- surrounding: "surround",
57
- pulsator: "apulsator=hz=1",
58
- subboost: "asubboost",
59
- karaoke: "stereotools=mlev=0.03",
60
- flanger: "flanger",
61
- gate: "agate",
62
- haas: "haas",
63
- mcompand: "mcompand",
64
- mono: "pan=mono|c0=.5*c0+.5*c1",
65
- mstlr: "stereotools=mode=ms>lr",
66
- mstrr: "stereotools=mode=ms>rr",
67
- compressor: "compand=points=-80/-105|-62/-80|-15.4/-15.4|0/-12|20/-7.6",
68
- expander: "compand=attacks=0:points=-80/-169|-54/-80|-49.5/-64.6|-41.1/-41.1|-25.8/-15|-10.8/-4.5|0/0|20/8.3",
69
- softlimiter: "compand=attacks=0:points=-80/-80|-12.4/-12.4|-6/-8|0/-6.8|20/-2.8",
70
- chorus: "chorus=0.7:0.9:55:0.4:0.25:2",
71
- chorus2d: "chorus=0.6:0.9:50|60:0.4|0.32:0.25|0.4:2|1.3",
72
- chorus3d: "chorus=0.5:0.9:50|60|40:0.4|0.32|0.3:0.25|0.4|0.3:2|2.3|1.3",
73
- fadein: "afade=t=in:ss=0:d=10",
74
- dim: `afftfilt="'real=re * (1-clip((b/nb)*b,0,1))':imag='im * (1-clip((b/nb)*b,0,1))'"`,
75
- earrape: "channelsplit,sidechaingate=level_in=64",
76
- *[Symbol.iterator]() {
5
+ class AudioFilters {
6
+ constructor() {
7
+ return AudioFilters;
8
+ }
9
+ static get filters() {
10
+ return {
11
+ bassboost_low: bass(15),
12
+ bassboost: bass(20),
13
+ bassboost_high: bass(30),
14
+ "8D": "apulsator=hz=0.09",
15
+ vaporwave: "aresample=48000,asetrate=48000*0.8",
16
+ nightcore: "aresample=48000,asetrate=48000*1.25",
17
+ phaser: "aphaser=in_gain=0.4",
18
+ tremolo: "tremolo",
19
+ vibrato: "vibrato=f=6.5",
20
+ reverse: "areverse",
21
+ treble: "treble=g=5",
22
+ normalizer2: "dynaudnorm=g=101",
23
+ normalizer: "acompressor",
24
+ surrounding: "surround",
25
+ pulsator: "apulsator=hz=1",
26
+ subboost: "asubboost",
27
+ karaoke: "stereotools=mlev=0.03",
28
+ flanger: "flanger",
29
+ gate: "agate",
30
+ haas: "haas",
31
+ mcompand: "mcompand",
32
+ mono: "pan=mono|c0=.5*c0+.5*c1",
33
+ mstlr: "stereotools=mode=ms>lr",
34
+ mstrr: "stereotools=mode=ms>rr",
35
+ compressor: "compand=points=-80/-105|-62/-80|-15.4/-15.4|0/-12|20/-7.6",
36
+ expander: "compand=attacks=0:points=-80/-169|-54/-80|-49.5/-64.6|-41.1/-41.1|-25.8/-15|-10.8/-4.5|0/0|20/8.3",
37
+ softlimiter: "compand=attacks=0:points=-80/-80|-12.4/-12.4|-6/-8|0/-6.8|20/-2.8",
38
+ chorus: "chorus=0.7:0.9:55:0.4:0.25:2",
39
+ chorus2d: "chorus=0.6:0.9:50|60:0.4|0.32:0.25|0.4:2|1.3",
40
+ chorus3d: "chorus=0.5:0.9:50|60|40:0.4|0.32|0.3:0.25|0.4|0.3:2|2.3|1.3",
41
+ fadein: "afade=t=in:ss=0:d=10",
42
+ dim: `afftfilt="'real=re * (1-clip((b/nb)*b,0,1))':imag='im * (1-clip((b/nb)*b,0,1))'"`,
43
+ earrape: "channelsplit,sidechaingate=level_in=64"
44
+ };
45
+ }
46
+ static get(name) {
47
+ return this.filters[name];
48
+ }
49
+ static has(name) {
50
+ return name in this.filters;
51
+ }
52
+ static *[Symbol.iterator]() {
77
53
  for (const [k, v] of Object.entries(this)) {
78
- if (typeof this[k] === "string")
54
+ if (typeof this.filters[k] === "string")
79
55
  yield { name: k, value: v };
80
56
  }
81
- },
82
- get names() {
83
- return Object.keys(this).filter((p) => !["names", "length"].includes(p) && typeof this[p] !== "function");
84
- },
85
- get length() {
86
- return Object.keys(this).filter((p) => !["names", "length"].includes(p) && typeof this[p] !== "function").length;
87
- },
88
- toString() {
57
+ }
58
+ static get names() {
59
+ return Object.keys(this).filter((p) => !["names", "length"].includes(p) && typeof this.filters[p] !== "function");
60
+ }
61
+ // @ts-expect-error AudioFilters.length
62
+ static get length() {
63
+ return Object.keys(this).filter((p) => !["names", "length"].includes(p) && typeof this.filters[p] !== "function").length;
64
+ }
65
+ static toString() {
89
66
  return this.names.map((m) => this[m]).join(","); // eslint-disable-line @typescript-eslint/no-explicit-any
90
- },
91
- create(filter) {
92
- if (!filter || !Array.isArray(filter))
67
+ }
68
+ /**
69
+ * Create ffmpeg args from the specified filters name
70
+ * @param filter The filter name
71
+ * @returns
72
+ */
73
+ static create(filters) {
74
+ if (!filters || !Array.isArray(filters))
93
75
  return this.toString();
94
- return filter
76
+ return filters
95
77
  .filter((predicate) => typeof predicate === "string")
96
- .map((m) => this[m])
78
+ .map((m) => this.get(m))
97
79
  .join(",");
98
- },
99
- define(filterName, value) {
100
- if (typeof this[filterName] && typeof this[filterName] === "function")
101
- return;
102
- this[filterName] = value;
103
- },
104
- defineBulk(filterArray) {
105
- filterArray.forEach((arr) => this.define(arr.name, arr.value));
106
80
  }
107
- };
108
- exports.AudioFilters = FilterList;
109
- exports.default = FilterList;
81
+ /**
82
+ * Defines audio filter
83
+ * @param filterName The name of the filter
84
+ * @param value The ffmpeg args
85
+ */
86
+ static define(filterName, value) {
87
+ this.filters[filterName] = value;
88
+ }
89
+ /**
90
+ * Defines multiple audio filters
91
+ * @param filtersArray Array of filters containing the filter name and ffmpeg args
92
+ */
93
+ static defineBulk(filtersArray) {
94
+ filtersArray.forEach((arr) => this.define(arr.name, arr.value));
95
+ }
96
+ }
97
+ exports.AudioFilters = AudioFilters;
98
+ exports.default = AudioFilters;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFFmpegStream = exports.FFMPEG_ARGS_PIPED = exports.FFMPEG_ARGS_STRING = void 0;
4
+ const prism_media_1 = require("prism-media");
5
+ function FFMPEG_ARGS_STRING(stream, fmt) {
6
+ // prettier-ignore
7
+ return [
8
+ "-reconnect", "1",
9
+ "-reconnect_streamed", "1",
10
+ "-reconnect_delay_max", "5",
11
+ "-i", stream,
12
+ "-analyzeduration", "0",
13
+ "-loglevel", "0",
14
+ "-f", `${typeof fmt === "string" ? fmt : "s16le"}`,
15
+ "-ar", "48000",
16
+ "-ac", "2"
17
+ ];
18
+ }
19
+ exports.FFMPEG_ARGS_STRING = FFMPEG_ARGS_STRING;
20
+ function FFMPEG_ARGS_PIPED(fmt) {
21
+ // prettier-ignore
22
+ return [
23
+ "-analyzeduration", "0",
24
+ "-loglevel", "0",
25
+ "-f", `${typeof fmt === "string" ? fmt : "s16le"}`,
26
+ "-ar", "48000",
27
+ "-ac", "2"
28
+ ];
29
+ }
30
+ exports.FFMPEG_ARGS_PIPED = FFMPEG_ARGS_PIPED;
31
+ /**
32
+ * Creates FFmpeg stream
33
+ * @param stream The source stream
34
+ * @param options FFmpeg stream options
35
+ */
36
+ function createFFmpegStream(stream, options) {
37
+ if (options.skip && typeof stream !== "string")
38
+ return stream;
39
+ options ?? (options = {});
40
+ const args = typeof stream === "string" ? FFMPEG_ARGS_STRING(stream, options.fmt) : FFMPEG_ARGS_PIPED(options.fmt);
41
+ if (!Number.isNaN(options.seek))
42
+ args.unshift("-ss", String(options.seek));
43
+ if (Array.isArray(options.encoderArgs))
44
+ args.push(...options.encoderArgs);
45
+ const transcoder = new prism_media_1.FFmpeg({ shell: false, args });
46
+ transcoder.on("close", () => transcoder.destroy());
47
+ if (typeof stream !== "string") {
48
+ stream.on("error", () => transcoder.destroy());
49
+ stream.pipe(transcoder);
50
+ }
51
+ return transcoder;
52
+ }
53
+ exports.createFFmpegStream = createFFmpegStream;
@@ -117,7 +117,15 @@ class Util {
117
117
  return await Promise.resolve().then(() => __importStar(require(lib))).then((res) => res.fetch || res.default?.fetch || res.default);
118
118
  }
119
119
  catch {
120
- // uh?
120
+ try {
121
+ // eslint-disable-next-line
122
+ const res = require(lib);
123
+ if (res)
124
+ return res.fetch || res.default?.fetch || res.default;
125
+ }
126
+ catch {
127
+ // no?
128
+ }
121
129
  }
122
130
  }
123
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-player",
3
- "version": "5.3.0-dev.2",
3
+ "version": "5.3.0-dev.3",
4
4
  "description": "Complete framework to facilitate music commands using discord.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -66,7 +66,6 @@
66
66
  "homepage": "https://discord-player.js.org",
67
67
  "dependencies": {
68
68
  "@discordjs/voice": "^0.11.0",
69
- "discord-ytdl-core": "^5.0.4",
70
69
  "libsodium-wrappers": "^0.7.10",
71
70
  "soundcloud-scraper": "^5.0.3",
72
71
  "spotify-url-info": "^3.1.2",