distube 4.0.0-dev.6 → 4.0.0

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.d.ts CHANGED
@@ -6,8 +6,6 @@ import { TypedEmitter } from 'tiny-typed-emitter';
6
6
  import { AudioPlayer, VoiceConnection, AudioResource, StreamType as StreamType$1 } from '@discordjs/voice';
7
7
  import { FFmpeg } from 'prism-media';
8
8
  import * as _discordjs_collection from '@discordjs/collection';
9
- import https from 'https';
10
- import http from 'http';
11
9
 
12
10
  declare type Awaitable<T = any> = T | PromiseLike<T>;
13
11
  declare type DisTubeVoiceEvents = {
@@ -543,22 +541,7 @@ declare function checkInvalidKey(target: Record<string, any>, source: Record<str
543
541
  declare function isObject(obj: any): obj is object;
544
542
  declare function isRecord<T = unknown>(obj: any): obj is Record<string, T>;
545
543
 
546
- declare class HTTPPlugin extends ExtractorPlugin {
547
- validate(url: string): Promise<boolean>;
548
- resolve(url: string, options?: {
549
- member?: GuildMember;
550
- metadata?: any;
551
- }): Promise<Song<any>>;
552
- }
553
-
554
- declare const getResponseHeaders: (httpModule: typeof http | typeof https, url: string) => Promise<http.IncomingHttpHeaders>;
555
- declare const validateAudioURL: (httpModule: typeof http | typeof https, protocol: string, url: string) => Promise<boolean>;
556
- declare const resolveHttpSong: (url: string, options: {
557
- source: "http" | "https";
558
- member?: GuildMember;
559
- metadata?: any;
560
- }) => Promise<Song<any>>;
561
- declare class HTTPSPlugin extends ExtractorPlugin {
544
+ declare class DirectLinkPlugin extends ExtractorPlugin {
562
545
  validate(url: string): Promise<boolean>;
563
546
  resolve(url: string, options?: {
564
547
  member?: GuildMember;
@@ -580,12 +563,7 @@ declare class DisTube extends TypedEmitter<DisTubeEvents> {
580
563
  static get version(): string;
581
564
  get version(): string;
582
565
  play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist, options?: PlayOptions): Promise<void>;
583
- createCustomPlaylist(songs: (string | Song | SearchResult)[], options?: {
584
- member?: GuildMember;
585
- properties?: Record<string, any>;
586
- parallel?: boolean;
587
- metadata?: any;
588
- }): Promise<Playlist>;
566
+ createCustomPlaylist(songs: (string | Song | SearchResult)[], options?: CustomPlaylistOptions): Promise<Playlist>;
589
567
  search(string: string, options?: {
590
568
  type?: SearchResultType;
591
569
  limit?: number;
@@ -620,4 +598,4 @@ declare class DisTube extends TypedEmitter<DisTubeEvents> {
620
598
  emitError(error: Error, channel?: GuildTextBasedChannel): void;
621
599
  }
622
600
 
623
- export { Awaitable, BaseManager, Chapter, CustomPlaylistOptions, CustomPlugin, DisTube, DisTubeBase, DisTubeError, DisTubeEvents, DisTubeHandler, DisTubeOptions, DisTubeStream, DisTubeVoice, DisTubeVoiceEvents, DisTubeVoiceManager, ExtractorPlugin, Filter, FilterManager, FilterResolvable, Filters, GuildIdManager, GuildIdResolvable, HTTPPlugin, HTTPSPlugin, Options, OtherSongInfo, PlayHandlerOptions, PlayOptions, Playlist, PlaylistInfo, Plugin, PluginType, Queue, QueueManager, RelatedSong, RepeatMode, ResolveOptions, ResolvePlaylistOptions, SearchResult, SearchResultPlaylist, SearchResultType, SearchResultVideo, Song, StreamType, TaskQueue, checkIntents, checkInvalidKey, chooseBestVideoFormat, DisTube as default, defaultFilters, defaultOptions, formatDuration, getResponseHeaders, isClientInstance, isGuildInstance, isMemberInstance, isMessageInstance, isObject, isRecord, isSnowflake, isSupportedVoiceChannel, isTextChannelInstance, isURL, isVoiceChannelEmpty, parseNumber, resolveGuildId, resolveHttpSong, toSecond, validateAudioURL, version };
601
+ export { Awaitable, BaseManager, Chapter, CustomPlaylistOptions, CustomPlugin, DirectLinkPlugin, DisTube, DisTubeBase, DisTubeError, DisTubeEvents, DisTubeHandler, DisTubeOptions, DisTubeStream, DisTubeVoice, DisTubeVoiceEvents, DisTubeVoiceManager, ExtractorPlugin, Filter, FilterManager, FilterResolvable, Filters, GuildIdManager, GuildIdResolvable, Options, OtherSongInfo, PlayHandlerOptions, PlayOptions, Playlist, PlaylistInfo, Plugin, PluginType, Queue, QueueManager, RelatedSong, RepeatMode, ResolveOptions, ResolvePlaylistOptions, SearchResult, SearchResultPlaylist, SearchResultType, SearchResultVideo, Song, StreamType, TaskQueue, checkIntents, checkInvalidKey, chooseBestVideoFormat, DisTube as default, defaultFilters, defaultOptions, formatDuration, isClientInstance, isGuildInstance, isMemberInstance, isMessageInstance, isObject, isRecord, isSnowflake, isSupportedVoiceChannel, isTextChannelInstance, isURL, isVoiceChannelEmpty, parseNumber, resolveGuildId, toSecond, version };
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ var require_package = __commonJS({
57
57
  "package.json"(exports, module2) {
58
58
  module2.exports = {
59
59
  name: "distube",
60
- version: "4.0.0-dev.6",
60
+ version: "4.0.0",
61
61
  description: "A Discord.js module to simplify your music commands and play songs with audio filters on Discord without any API key.",
62
62
  main: "./dist/index.js",
63
63
  module: "./dist/index.mjs",
@@ -123,10 +123,11 @@ var require_package = __commonJS({
123
123
  dependencies: {
124
124
  "@distube/ytdl-core": "^4.11.3",
125
125
  "@distube/ytpl": "^1.1.1",
126
- "@distube/ytsr": "^1.1.7",
126
+ "@distube/ytsr": "^1.1.8",
127
127
  "prism-media": "https://codeload.github.com/distubejs/prism-media/tar.gz/main#workaround.tar.gz",
128
128
  "tiny-typed-emitter": "^2.1.0",
129
- tslib: "^2.4.0"
129
+ tslib: "^2.4.0",
130
+ undici: "^5.8.0"
130
131
  },
131
132
  devDependencies: {
132
133
  "@babel/core": "^7.18.6",
@@ -136,15 +137,15 @@ var require_package = __commonJS({
136
137
  "@babel/preset-typescript": "^7.18.6",
137
138
  "@commitlint/cli": "^17.0.3",
138
139
  "@commitlint/config-conventional": "^17.0.3",
139
- "@discordjs/voice": "dev",
140
+ "@discordjs/voice": "latest",
140
141
  "@distube/docgen": "distubejs/docgen",
141
- "@types/jest": "^28.1.5",
142
- "@types/node": "^18.0.4",
142
+ "@types/jest": "^28.1.6",
143
+ "@types/node": "^18.0.6",
143
144
  "@typescript-eslint/eslint-plugin": "^5.30.6",
144
145
  "@typescript-eslint/parser": "^5.30.6",
145
146
  "babel-jest": "^28.1.3",
146
- "discord.js": "dev",
147
- eslint: "^8.19.0",
147
+ "discord.js": "latest",
148
+ eslint: "^8.20.0",
148
149
  "eslint-config-distube": "^1.6.4",
149
150
  "eslint-config-prettier": "^8.5.0",
150
151
  "eslint-plugin-deprecation": "^1.3.2",
@@ -153,7 +154,7 @@ var require_package = __commonJS({
153
154
  jest: "^28.1.3",
154
155
  "jsdoc-babel": "^0.5.0",
155
156
  "nano-staged": "^0.8.0",
156
- "npm-check-updates": "^15.3.0",
157
+ "npm-check-updates": "^15.3.4",
157
158
  pinst: "^3.0.0",
158
159
  prettier: "^2.7.1",
159
160
  tsup: "^6.1.3",
@@ -162,7 +163,7 @@ var require_package = __commonJS({
162
163
  peerDependencies: {
163
164
  "@discordjs/opus": "*",
164
165
  "@discordjs/voice": "*",
165
- "discord.js": "14||^14.0.0-dev"
166
+ "discord.js": "14"
166
167
  },
167
168
  peerDependenciesMeta: {
168
169
  "@discordjs/opus": {
@@ -181,8 +182,7 @@ var require_package = __commonJS({
181
182
  engines: {
182
183
  node: ">=16.9.0"
183
184
  },
184
- packageManager: "yarn@3.2.0",
185
- stableVersion: "4.0.0-dev"
185
+ packageManager: "yarn@3.2.0"
186
186
  };
187
187
  }
188
188
  });
@@ -192,6 +192,7 @@ var src_exports = {};
192
192
  __export(src_exports, {
193
193
  BaseManager: () => BaseManager,
194
194
  CustomPlugin: () => CustomPlugin,
195
+ DirectLinkPlugin: () => DirectLinkPlugin,
195
196
  DisTube: () => DisTube,
196
197
  DisTubeBase: () => DisTubeBase,
197
198
  DisTubeError: () => DisTubeError,
@@ -202,8 +203,6 @@ __export(src_exports, {
202
203
  ExtractorPlugin: () => ExtractorPlugin,
203
204
  FilterManager: () => FilterManager,
204
205
  GuildIdManager: () => GuildIdManager,
205
- HTTPPlugin: () => HTTPPlugin,
206
- HTTPSPlugin: () => HTTPSPlugin,
207
206
  Options: () => Options,
208
207
  Playlist: () => Playlist,
209
208
  Plugin: () => Plugin,
@@ -224,7 +223,6 @@ __export(src_exports, {
224
223
  defaultFilters: () => defaultFilters,
225
224
  defaultOptions: () => defaultOptions,
226
225
  formatDuration: () => formatDuration,
227
- getResponseHeaders: () => getResponseHeaders,
228
226
  isClientInstance: () => isClientInstance,
229
227
  isGuildInstance: () => isGuildInstance,
230
228
  isMemberInstance: () => isMemberInstance,
@@ -238,9 +236,7 @@ __export(src_exports, {
238
236
  isVoiceChannelEmpty: () => isVoiceChannelEmpty,
239
237
  parseNumber: () => parseNumber,
240
238
  resolveGuildId: () => resolveGuildId,
241
- resolveHttpSong: () => resolveHttpSong,
242
239
  toSecond: () => toSecond,
243
- validateAudioURL: () => validateAudioURL,
244
240
  version: () => version
245
241
  });
246
242
  module.exports = __toCommonJS(src_exports);
@@ -1195,6 +1191,8 @@ Name: ${song.name}`;
1195
1191
  }
1196
1192
  this.emitError(error, queue.textChannel);
1197
1193
  if (queue.songs.length > 0) {
1194
+ queue._next = queue._prev = false;
1195
+ queue.beginTime = 0;
1198
1196
  this.playSong(queue).then((e) => {
1199
1197
  if (!e)
1200
1198
  this.emit("playSong", queue, queue.songs[0]);
@@ -1278,8 +1276,11 @@ var DisTubeHandler = class extends DisTubeBase {
1278
1276
  return new Song(song, options);
1279
1277
  if (song instanceof SearchResultPlaylist)
1280
1278
  return this.resolvePlaylist(song.url, options);
1281
- if (isObject(song))
1279
+ if (isObject(song)) {
1280
+ if (!("url" in song) && !("id" in song))
1281
+ throw new DisTubeError("CANNOT_RESOLVE_SONG", song);
1282
1282
  return new Song(song, options);
1283
+ }
1283
1284
  if (import_ytpl.default.validateID(song))
1284
1285
  return this.resolvePlaylist(song, options);
1285
1286
  if (import_ytdl_core.default.validateURL(song))
@@ -2034,7 +2035,7 @@ function isMemberInstance(member) {
2034
2035
  }
2035
2036
  __name(isMemberInstance, "isMemberInstance");
2036
2037
  function isTextChannelInstance(channel) {
2037
- return !!channel && isSnowflake(channel.id) && isSnowflake(channel.guildId) && typeof channel.name === "string" && import_discord2.Constants.TextBasedChannelTypes.includes(channel.type) && typeof channel.nsfw === "boolean" && typeof channel.messages?.cache === "object" && typeof channel.send === "function";
2038
+ return !!channel && isSnowflake(channel.id) && isSnowflake(channel.guildId) && typeof channel.name === "string" && import_discord2.Constants.TextBasedChannelTypes.includes(channel.type) && typeof channel.nsfw === "boolean" && "messages" in channel && typeof channel.send === "function";
2038
2039
  }
2039
2040
  __name(isTextChannelInstance, "isTextChannelInstance");
2040
2041
  function isMessageInstance(message) {
@@ -2089,52 +2090,25 @@ function isRecord(obj) {
2089
2090
  }
2090
2091
  __name(isRecord, "isRecord");
2091
2092
 
2092
- // src/plugin/http.ts
2093
- var import_http = __toESM(require("http"));
2094
- var HTTPPlugin = class extends ExtractorPlugin {
2093
+ // src/plugin/DirectLink.ts
2094
+ var import_undici = require("undici");
2095
+ var DirectLinkPlugin = class extends ExtractorPlugin {
2095
2096
  async validate(url) {
2096
- return validateAudioURL(import_http.default, "http:", url);
2097
- }
2098
- async resolve(url, options = {}) {
2099
- return resolveHttpSong(url, { ...options, source: "http" });
2100
- }
2101
- };
2102
- __name(HTTPPlugin, "HTTPPlugin");
2103
-
2104
- // src/plugin/https.ts
2105
- var import_https = __toESM(require("https"));
2106
- var import_url2 = require("url");
2107
- var getResponseHeaders = /* @__PURE__ */ __name(async (httpModule, url) => new Promise((resolve, reject) => {
2108
- httpModule.get(url).on("response", (res) => {
2109
- resolve(res.headers);
2110
- }).on("error", reject);
2111
- }), "getResponseHeaders");
2112
- var validateAudioURL = /* @__PURE__ */ __name(async (httpModule, protocol, url) => {
2113
- if (new import_url2.URL(url).protocol.toLowerCase() !== protocol) {
2097
+ const headers = await (0, import_undici.request)(url, { method: "HEAD" }).then((res) => res.headers);
2098
+ const type = headers["content-type"];
2099
+ if (type?.startsWith("audio"))
2100
+ return true;
2114
2101
  return false;
2115
2102
  }
2116
- const headers = await getResponseHeaders(httpModule, url), type = headers["content-type"];
2117
- if (type?.startsWith("audio")) {
2118
- return true;
2119
- }
2120
- return false;
2121
- }, "validateAudioURL");
2122
- var resolveHttpSong = /* @__PURE__ */ __name(async (url, options) => {
2123
- url = url.replace(/\/+$/, "");
2124
- return new Song({
2125
- name: url.substring(url.lastIndexOf("/") + 1).replace(/((\?|#).*)?$/, "") || url,
2126
- url
2127
- }, options);
2128
- }, "resolveHttpSong");
2129
- var HTTPSPlugin = class extends ExtractorPlugin {
2130
- async validate(url) {
2131
- return validateAudioURL(import_https.default, "https:", url);
2132
- }
2133
2103
  async resolve(url, options = {}) {
2134
- return resolveHttpSong(url, { ...options, source: "https" });
2104
+ url = url.replace(/\/+$/, "");
2105
+ return new Song({
2106
+ name: url.substring(url.lastIndexOf("/") + 1).replace(/((\?|#).*)?$/, "") || url,
2107
+ url
2108
+ }, options);
2135
2109
  }
2136
2110
  };
2137
- __name(HTTPSPlugin, "HTTPSPlugin");
2111
+ __name(DirectLinkPlugin, "DirectLinkPlugin");
2138
2112
 
2139
2113
  // src/DisTube.ts
2140
2114
  var import_ytsr = __toESM(require("@distube/ytsr"));
@@ -2161,7 +2135,7 @@ var DisTube = class extends import_tiny_typed_emitter2.TypedEmitter {
2161
2135
  this.handler = new DisTubeHandler(this);
2162
2136
  this.queues = new QueueManager(this);
2163
2137
  this.filters = { ...defaultFilters, ...this.options.customFilters };
2164
- this.options.plugins.push(new HTTPPlugin(), new HTTPSPlugin());
2138
+ this.options.plugins.push(new DirectLinkPlugin());
2165
2139
  this.options.plugins.map((p) => p.init(this));
2166
2140
  this.extractorPlugins = this.options.plugins.filter((p) => p.type === "extractor");
2167
2141
  this.customPlugins = this.options.plugins.filter((p) => p.type === "custom");
@@ -2385,6 +2359,7 @@ __name(DisTube, "DisTube");
2385
2359
  0 && (module.exports = {
2386
2360
  BaseManager,
2387
2361
  CustomPlugin,
2362
+ DirectLinkPlugin,
2388
2363
  DisTube,
2389
2364
  DisTubeBase,
2390
2365
  DisTubeError,
@@ -2395,8 +2370,6 @@ __name(DisTube, "DisTube");
2395
2370
  ExtractorPlugin,
2396
2371
  FilterManager,
2397
2372
  GuildIdManager,
2398
- HTTPPlugin,
2399
- HTTPSPlugin,
2400
2373
  Options,
2401
2374
  Playlist,
2402
2375
  Plugin,
@@ -2416,7 +2389,6 @@ __name(DisTube, "DisTube");
2416
2389
  defaultFilters,
2417
2390
  defaultOptions,
2418
2391
  formatDuration,
2419
- getResponseHeaders,
2420
2392
  isClientInstance,
2421
2393
  isGuildInstance,
2422
2394
  isMemberInstance,
@@ -2430,9 +2402,7 @@ __name(DisTube, "DisTube");
2430
2402
  isVoiceChannelEmpty,
2431
2403
  parseNumber,
2432
2404
  resolveGuildId,
2433
- resolveHttpSong,
2434
2405
  toSecond,
2435
- validateAudioURL,
2436
2406
  version
2437
2407
  });
2438
2408
  //# sourceMappingURL=index.js.map