distube 4.0.0-dev.6 → 4.0.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
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  "package.json"(exports, module) {
45
45
  module.exports = {
46
46
  name: "distube",
47
- version: "4.0.0-dev.6",
47
+ version: "4.0.2",
48
48
  description: "A Discord.js module to simplify your music commands and play songs with audio filters on Discord without any API key.",
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -68,7 +68,7 @@ var require_package = __commonJS({
68
68
  prettier: 'prettier --write "**/*.{ts,json,yml,yaml,md}"',
69
69
  build: "tsup",
70
70
  "build:check": "tsc --noEmit",
71
- update: "ncu -u --dep dev,prod && yarn up '**' -R",
71
+ update: "ncu -u && yarn up '**' -R",
72
72
  postinstall: "husky install",
73
73
  prepublishOnly: "yarn lint && yarn test",
74
74
  prepack: "yarn build && pinst --disable",
@@ -110,28 +110,29 @@ var require_package = __commonJS({
110
110
  dependencies: {
111
111
  "@distube/ytdl-core": "^4.11.3",
112
112
  "@distube/ytpl": "^1.1.1",
113
- "@distube/ytsr": "^1.1.7",
113
+ "@distube/ytsr": "^1.1.8",
114
114
  "prism-media": "https://codeload.github.com/distubejs/prism-media/tar.gz/main#workaround.tar.gz",
115
115
  "tiny-typed-emitter": "^2.1.0",
116
- tslib: "^2.4.0"
116
+ tslib: "^2.4.0",
117
+ undici: "^5.8.0"
117
118
  },
118
119
  devDependencies: {
119
- "@babel/core": "^7.18.6",
120
+ "@babel/core": "^7.18.9",
120
121
  "@babel/plugin-proposal-class-properties": "^7.18.6",
121
- "@babel/plugin-proposal-object-rest-spread": "^7.18.6",
122
- "@babel/preset-env": "^7.18.6",
122
+ "@babel/plugin-proposal-object-rest-spread": "^7.18.9",
123
+ "@babel/preset-env": "^7.18.9",
123
124
  "@babel/preset-typescript": "^7.18.6",
124
125
  "@commitlint/cli": "^17.0.3",
125
126
  "@commitlint/config-conventional": "^17.0.3",
126
- "@discordjs/voice": "dev",
127
+ "@discordjs/voice": "^0.11.0",
127
128
  "@distube/docgen": "distubejs/docgen",
128
- "@types/jest": "^28.1.5",
129
- "@types/node": "^18.0.4",
130
- "@typescript-eslint/eslint-plugin": "^5.30.6",
131
- "@typescript-eslint/parser": "^5.30.6",
129
+ "@types/jest": "^28.1.6",
130
+ "@types/node": "^18.0.6",
131
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
132
+ "@typescript-eslint/parser": "^5.30.7",
132
133
  "babel-jest": "^28.1.3",
133
- "discord.js": "dev",
134
- eslint: "^8.19.0",
134
+ "discord.js": "^14.0.2",
135
+ eslint: "^8.20.0",
135
136
  "eslint-config-distube": "^1.6.4",
136
137
  "eslint-config-prettier": "^8.5.0",
137
138
  "eslint-plugin-deprecation": "^1.3.2",
@@ -140,7 +141,7 @@ var require_package = __commonJS({
140
141
  jest: "^28.1.3",
141
142
  "jsdoc-babel": "^0.5.0",
142
143
  "nano-staged": "^0.8.0",
143
- "npm-check-updates": "^15.3.0",
144
+ "npm-check-updates": "^15.3.4",
144
145
  pinst: "^3.0.0",
145
146
  prettier: "^2.7.1",
146
147
  tsup: "^6.1.3",
@@ -149,7 +150,7 @@ var require_package = __commonJS({
149
150
  peerDependencies: {
150
151
  "@discordjs/opus": "*",
151
152
  "@discordjs/voice": "*",
152
- "discord.js": "14||^14.0.0-dev"
153
+ "discord.js": "14"
153
154
  },
154
155
  peerDependenciesMeta: {
155
156
  "@discordjs/opus": {
@@ -168,8 +169,7 @@ var require_package = __commonJS({
168
169
  engines: {
169
170
  node: ">=16.9.0"
170
171
  },
171
- packageManager: "yarn@3.2.0",
172
- stableVersion: "4.0.0-dev"
172
+ packageManager: "yarn@3.2.0"
173
173
  };
174
174
  }
175
175
  });
@@ -230,7 +230,8 @@ var defaultOptions = {
230
230
  emitAddSongWhenCreatingQueue: true,
231
231
  emitAddListWhenCreatingQueue: true,
232
232
  joinNewVoiceChannel: true,
233
- streamType: 0 /* OPUS */
233
+ streamType: 0 /* OPUS */,
234
+ directLink: true
234
235
  };
235
236
 
236
237
  // src/struct/DisTubeError.ts
@@ -355,6 +356,7 @@ var Playlist = class {
355
356
  this.songs = playlist;
356
357
  this.name = this.songs[0].name ? `${this.songs[0].name} and ${this.songs.length - 1} more songs.` : `${this.songs.length} songs playlist`;
357
358
  this.thumbnail = this.songs[0].thumbnail;
359
+ this.member = member || void 0;
358
360
  } else {
359
361
  this.source = (playlist.source || "youtube").toLowerCase();
360
362
  if (!Array.isArray(playlist.songs) || !playlist.songs.length)
@@ -363,12 +365,12 @@ var Playlist = class {
363
365
  this.name = playlist.name || playlist.title || (this.songs[0].name ? `${this.songs[0].name} and ${this.songs.length - 1} more songs.` : `${this.songs.length} songs playlist`);
364
366
  this.url = playlist.url || playlist.webpage_url;
365
367
  this.thumbnail = playlist.thumbnail || this.songs[0].thumbnail;
368
+ this.member = member || playlist.member || void 0;
366
369
  }
367
370
  this.songs.map((s) => s.constructor.name === "Song" && (s.playlist = this));
368
371
  if (properties)
369
372
  for (const [key, value] of Object.entries(properties))
370
373
  this[key] = value;
371
- this.member = member;
372
374
  this.metadata = metadata;
373
375
  }
374
376
  get duration() {
@@ -1132,6 +1134,8 @@ Name: ${song.name}`;
1132
1134
  }
1133
1135
  this.emitError(error, queue.textChannel);
1134
1136
  if (queue.songs.length > 0) {
1137
+ queue._next = queue._prev = false;
1138
+ queue.beginTime = 0;
1135
1139
  this.playSong(queue).then((e) => {
1136
1140
  if (!e)
1137
1141
  this.emit("playSong", queue, queue.songs[0]);
@@ -1215,8 +1219,11 @@ var DisTubeHandler = class extends DisTubeBase {
1215
1219
  return new Song(song, options);
1216
1220
  if (song instanceof SearchResultPlaylist)
1217
1221
  return this.resolvePlaylist(song.url, options);
1218
- if (isObject(song))
1222
+ if (isObject(song)) {
1223
+ if (!("url" in song) && !("id" in song))
1224
+ throw new DisTubeError("CANNOT_RESOLVE_SONG", song);
1219
1225
  return new Song(song, options);
1226
+ }
1220
1227
  if (ytpl.validateID(song))
1221
1228
  return this.resolvePlaylist(song, options);
1222
1229
  if (ytdl.validateURL(song))
@@ -1408,6 +1415,7 @@ var Options = class {
1408
1415
  __publicField(this, "emitAddListWhenCreatingQueue");
1409
1416
  __publicField(this, "joinNewVoiceChannel");
1410
1417
  __publicField(this, "streamType");
1418
+ __publicField(this, "directLink");
1411
1419
  if (typeof options !== "object" || Array.isArray(options)) {
1412
1420
  throw new DisTubeError("INVALID_TYPE", "object", options, "DisTubeOptions");
1413
1421
  }
@@ -1430,6 +1438,7 @@ var Options = class {
1430
1438
  this.emitAddListWhenCreatingQueue = opts.emitAddListWhenCreatingQueue;
1431
1439
  this.joinNewVoiceChannel = opts.joinNewVoiceChannel;
1432
1440
  this.streamType = opts.streamType;
1441
+ this.directLink = opts.directLink;
1433
1442
  checkInvalidKey(opts, this, "DisTubeOptions");
1434
1443
  __privateMethod(this, _validateOptions, validateOptions_fn).call(this);
1435
1444
  }
@@ -1491,6 +1500,9 @@ validateOptions_fn = /* @__PURE__ */ __name(function(options = this) {
1491
1500
  if (typeof options.streamType !== "number" || isNaN(options.streamType) || !StreamType[options.streamType]) {
1492
1501
  throw new DisTubeError("INVALID_TYPE", "StreamType", options.streamType, "DisTubeOptions.streamType");
1493
1502
  }
1503
+ if (typeof options.directLink !== "boolean") {
1504
+ throw new DisTubeError("INVALID_TYPE", "boolean", options.directLink, "DisTubeOptions.directLink");
1505
+ }
1494
1506
  }, "#validateOptions");
1495
1507
 
1496
1508
  // src/core/DisTubeStream.ts
@@ -1971,7 +1983,7 @@ function isMemberInstance(member) {
1971
1983
  }
1972
1984
  __name(isMemberInstance, "isMemberInstance");
1973
1985
  function isTextChannelInstance(channel) {
1974
- return !!channel && isSnowflake(channel.id) && isSnowflake(channel.guildId) && typeof channel.name === "string" && Constants.TextBasedChannelTypes.includes(channel.type) && typeof channel.nsfw === "boolean" && typeof channel.messages?.cache === "object" && typeof channel.send === "function";
1986
+ return !!channel && isSnowflake(channel.id) && isSnowflake(channel.guildId) && typeof channel.name === "string" && Constants.TextBasedChannelTypes.includes(channel.type) && typeof channel.nsfw === "boolean" && "messages" in channel && typeof channel.send === "function";
1975
1987
  }
1976
1988
  __name(isTextChannelInstance, "isTextChannelInstance");
1977
1989
  function isMessageInstance(message) {
@@ -2026,52 +2038,28 @@ function isRecord(obj) {
2026
2038
  }
2027
2039
  __name(isRecord, "isRecord");
2028
2040
 
2029
- // src/plugin/http.ts
2030
- import http from "http";
2031
- var HTTPPlugin = class extends ExtractorPlugin {
2041
+ // src/plugin/DirectLink.ts
2042
+ import { request } from "undici";
2043
+ var DirectLinkPlugin = class extends ExtractorPlugin {
2032
2044
  async validate(url) {
2033
- return validateAudioURL(http, "http:", url);
2034
- }
2035
- async resolve(url, options = {}) {
2036
- return resolveHttpSong(url, { ...options, source: "http" });
2037
- }
2038
- };
2039
- __name(HTTPPlugin, "HTTPPlugin");
2040
-
2041
- // src/plugin/https.ts
2042
- import https from "https";
2043
- import { URL as URL2 } from "url";
2044
- var getResponseHeaders = /* @__PURE__ */ __name(async (httpModule, url) => new Promise((resolve, reject) => {
2045
- httpModule.get(url).on("response", (res) => {
2046
- resolve(res.headers);
2047
- }).on("error", reject);
2048
- }), "getResponseHeaders");
2049
- var validateAudioURL = /* @__PURE__ */ __name(async (httpModule, protocol, url) => {
2050
- if (new URL2(url).protocol.toLowerCase() !== protocol) {
2045
+ try {
2046
+ const headers = await request(url, { method: "HEAD" }).then((res) => res.headers);
2047
+ const type = headers["content-type"];
2048
+ if (type?.startsWith("audio"))
2049
+ return true;
2050
+ } catch {
2051
+ }
2051
2052
  return false;
2052
2053
  }
2053
- const headers = await getResponseHeaders(httpModule, url), type = headers["content-type"];
2054
- if (type?.startsWith("audio")) {
2055
- return true;
2056
- }
2057
- return false;
2058
- }, "validateAudioURL");
2059
- var resolveHttpSong = /* @__PURE__ */ __name(async (url, options) => {
2060
- url = url.replace(/\/+$/, "");
2061
- return new Song({
2062
- name: url.substring(url.lastIndexOf("/") + 1).replace(/((\?|#).*)?$/, "") || url,
2063
- url
2064
- }, options);
2065
- }, "resolveHttpSong");
2066
- var HTTPSPlugin = class extends ExtractorPlugin {
2067
- async validate(url) {
2068
- return validateAudioURL(https, "https:", url);
2069
- }
2070
2054
  async resolve(url, options = {}) {
2071
- return resolveHttpSong(url, { ...options, source: "https" });
2055
+ url = url.replace(/\/+$/, "");
2056
+ return new Song({
2057
+ name: url.substring(url.lastIndexOf("/") + 1).replace(/((\?|#).*)?$/, "") || url,
2058
+ url
2059
+ }, options);
2072
2060
  }
2073
2061
  };
2074
- __name(HTTPSPlugin, "HTTPSPlugin");
2062
+ __name(DirectLinkPlugin, "DirectLinkPlugin");
2075
2063
 
2076
2064
  // src/DisTube.ts
2077
2065
  import ytsr from "@distube/ytsr";
@@ -2098,7 +2086,8 @@ var DisTube = class extends TypedEmitter2 {
2098
2086
  this.handler = new DisTubeHandler(this);
2099
2087
  this.queues = new QueueManager(this);
2100
2088
  this.filters = { ...defaultFilters, ...this.options.customFilters };
2101
- this.options.plugins.push(new HTTPPlugin(), new HTTPSPlugin());
2089
+ if (this.options.directLink)
2090
+ this.options.plugins.push(new DirectLinkPlugin());
2102
2091
  this.options.plugins.map((p) => p.init(this));
2103
2092
  this.extractorPlugins = this.options.plugins.filter((p) => p.type === "extractor");
2104
2093
  this.customPlugins = this.options.plugins.filter((p) => p.type === "custom");
@@ -2321,6 +2310,7 @@ __name(DisTube, "DisTube");
2321
2310
  export {
2322
2311
  BaseManager,
2323
2312
  CustomPlugin,
2313
+ DirectLinkPlugin,
2324
2314
  DisTube,
2325
2315
  DisTubeBase,
2326
2316
  DisTubeError,
@@ -2331,8 +2321,6 @@ export {
2331
2321
  ExtractorPlugin,
2332
2322
  FilterManager,
2333
2323
  GuildIdManager,
2334
- HTTPPlugin,
2335
- HTTPSPlugin,
2336
2324
  Options,
2337
2325
  Playlist,
2338
2326
  Plugin,
@@ -2353,7 +2341,6 @@ export {
2353
2341
  defaultFilters,
2354
2342
  defaultOptions,
2355
2343
  formatDuration,
2356
- getResponseHeaders,
2357
2344
  isClientInstance,
2358
2345
  isGuildInstance,
2359
2346
  isMemberInstance,
@@ -2367,9 +2354,7 @@ export {
2367
2354
  isVoiceChannelEmpty,
2368
2355
  parseNumber,
2369
2356
  resolveGuildId,
2370
- resolveHttpSong,
2371
2357
  toSecond,
2372
- validateAudioURL,
2373
2358
  version
2374
2359
  };
2375
2360
  //# sourceMappingURL=index.mjs.map