distube 4.1.0 → 4.1.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.d.ts +14 -14
- package/dist/index.js +33 -37
- package/dist/index.js.map +1 -1
- package/package.json +21 -21
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as ytdl from '@distube/ytdl-core';
|
|
2
|
+
import ytdl__default, { Cookie } from '@distube/ytdl-core';
|
|
2
3
|
import * as discord_js from 'discord.js';
|
|
3
4
|
import { GuildTextBasedChannel, Message, Snowflake, VoiceBasedChannel, VoiceState, Guild, GuildMember, Interaction, Client, Collection, ClientOptions } from 'discord.js';
|
|
4
5
|
import ytpl from '@distube/ytpl';
|
|
@@ -113,7 +114,7 @@ type DisTubeOptions = {
|
|
|
113
114
|
searchCooldown?: number;
|
|
114
115
|
youtubeCookie?: Cookie[] | string;
|
|
115
116
|
customFilters?: Filters;
|
|
116
|
-
ytdlOptions?:
|
|
117
|
+
ytdlOptions?: ytdl__default.downloadOptions;
|
|
117
118
|
nsfw?: boolean;
|
|
118
119
|
emitAddSongWhenCreatingQueue?: boolean;
|
|
119
120
|
emitAddListWhenCreatingQueue?: boolean;
|
|
@@ -569,7 +570,7 @@ declare class SearchResultPlaylist extends ISearchResult {
|
|
|
569
570
|
declare class Song<T = unknown> {
|
|
570
571
|
#private;
|
|
571
572
|
source: string;
|
|
572
|
-
formats?:
|
|
573
|
+
formats?: ytdl__default.videoFormat[];
|
|
573
574
|
id?: string;
|
|
574
575
|
name?: string;
|
|
575
576
|
isLive: boolean;
|
|
@@ -597,12 +598,12 @@ declare class Song<T = unknown> {
|
|
|
597
598
|
* @param {string} [options.source="youtube"] Song source
|
|
598
599
|
* @param {T} [options.metadata] Song metadata
|
|
599
600
|
*/
|
|
600
|
-
constructor(info:
|
|
601
|
+
constructor(info: ytdl__default.videoInfo | SearchResult | OtherSongInfo | ytdl__default.relatedVideo | RelatedSong | ytpl.result["items"][number], options?: {
|
|
601
602
|
member?: GuildMember;
|
|
602
603
|
source?: string;
|
|
603
604
|
metadata?: T;
|
|
604
605
|
});
|
|
605
|
-
_patchYouTube(i:
|
|
606
|
+
_patchYouTube(i: ytdl__default.videoInfo | SearchResult): void;
|
|
606
607
|
/**
|
|
607
608
|
* Patch data from other source
|
|
608
609
|
* @param {OtherSongInfo} info Video info
|
|
@@ -767,10 +768,9 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
|
|
|
767
768
|
interface StreamOptions {
|
|
768
769
|
seek?: number;
|
|
769
770
|
ffmpegArgs?: string[];
|
|
770
|
-
isLive?: boolean;
|
|
771
771
|
type?: StreamType;
|
|
772
772
|
}
|
|
773
|
-
declare const chooseBestVideoFormat: (
|
|
773
|
+
declare const chooseBestVideoFormat: ({ duration, formats, isLive }: Song) => ytdl.videoFormat | undefined;
|
|
774
774
|
/**
|
|
775
775
|
* Create a stream to play with {@link DisTubeVoice}
|
|
776
776
|
* @private
|
|
@@ -778,12 +778,12 @@ declare const chooseBestVideoFormat: (formats: ytdl.videoFormat[], isLive?: bool
|
|
|
778
778
|
declare class DisTubeStream {
|
|
779
779
|
/**
|
|
780
780
|
* Create a stream from ytdl video formats
|
|
781
|
-
* @param {
|
|
781
|
+
* @param {Song} song A YouTube Song
|
|
782
782
|
* @param {StreamOptions} options options
|
|
783
783
|
* @returns {DisTubeStream}
|
|
784
784
|
* @private
|
|
785
785
|
*/
|
|
786
|
-
static YouTube(
|
|
786
|
+
static YouTube(song: Song, options?: StreamOptions): DisTubeStream;
|
|
787
787
|
/**
|
|
788
788
|
* Create a stream from a stream url
|
|
789
789
|
* @param {string} url stream url
|
|
@@ -812,20 +812,20 @@ declare class DisTubeStream {
|
|
|
812
812
|
declare class DisTubeHandler extends DisTubeBase {
|
|
813
813
|
#private;
|
|
814
814
|
constructor(distube: DisTube);
|
|
815
|
-
get ytdlOptions():
|
|
815
|
+
get ytdlOptions(): ytdl__default.getInfoOptions;
|
|
816
816
|
get ytCookie(): string;
|
|
817
817
|
/**
|
|
818
818
|
* @param {string} url url
|
|
819
819
|
* @param {boolean} [basic=false] getBasicInfo?
|
|
820
820
|
* @returns {Promise<ytdl.videoInfo>}
|
|
821
821
|
*/
|
|
822
|
-
getYouTubeInfo(url: string, basic?: boolean): Promise<
|
|
822
|
+
getYouTubeInfo(url: string, basic?: boolean): Promise<ytdl__default.videoInfo>;
|
|
823
823
|
resolve<T = unknown>(song: Song<T>, options?: Omit<ResolveOptions, "metadata">): Promise<Song<T>>;
|
|
824
824
|
resolve<T = unknown>(song: Playlist<T>, options?: Omit<ResolveOptions, "metadata">): Promise<Playlist<T>>;
|
|
825
825
|
resolve<T = unknown>(song: string | SearchResult, options?: ResolveOptions<T>): Promise<Song<T> | Playlist<T>>;
|
|
826
|
-
resolve<T = unknown>(song:
|
|
826
|
+
resolve<T = unknown>(song: ytdl__default.videoInfo | OtherSongInfo | ytdl__default.relatedVideo, options?: ResolveOptions<T>): Promise<Song<T>>;
|
|
827
827
|
resolve<T = unknown>(song: Playlist, options: ResolveOptions<T>): Promise<Playlist<T>>;
|
|
828
|
-
resolve(song: string |
|
|
828
|
+
resolve(song: string | ytdl__default.videoInfo | Song | Playlist | SearchResult | OtherSongInfo | ytdl__default.relatedVideo, options?: ResolveOptions): Promise<Song | Playlist>;
|
|
829
829
|
resolvePlaylist<T = unknown>(playlist: Playlist<T> | Song<T>[] | string, options?: Omit<ResolvePlaylistOptions, "metadata">): Promise<Playlist<T>>;
|
|
830
830
|
resolvePlaylist<T = undefined>(playlist: Playlist | Song[] | string, options: ResolvePlaylistOptions<T>): Promise<Playlist<T>>;
|
|
831
831
|
resolvePlaylist(playlist: Playlist | Song[] | string, options?: ResolvePlaylistOptions): Promise<Playlist>;
|
|
@@ -887,7 +887,7 @@ declare class Options {
|
|
|
887
887
|
searchCooldown: number;
|
|
888
888
|
youtubeCookie?: Cookie[] | string;
|
|
889
889
|
customFilters?: Filters;
|
|
890
|
-
ytdlOptions:
|
|
890
|
+
ytdlOptions: ytdl__default.getInfoOptions;
|
|
891
891
|
nsfw: boolean;
|
|
892
892
|
emitAddSongWhenCreatingQueue: boolean;
|
|
893
893
|
emitAddListWhenCreatingQueue: boolean;
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,7 @@ var require_package = __commonJS({
|
|
|
63
63
|
"package.json"(exports, module2) {
|
|
64
64
|
module2.exports = {
|
|
65
65
|
name: "distube",
|
|
66
|
-
version: "4.1.
|
|
66
|
+
version: "4.1.1",
|
|
67
67
|
description: "A Discord.js module to simplify your music commands and play songs with audio filters on Discord without any API key.",
|
|
68
68
|
main: "./dist/index.js",
|
|
69
69
|
types: "./dist/index.d.ts",
|
|
@@ -124,43 +124,43 @@ var require_package = __commonJS({
|
|
|
124
124
|
],
|
|
125
125
|
homepage: "https://distube.js.org/",
|
|
126
126
|
dependencies: {
|
|
127
|
-
"@distube/ytdl-core": "^4.
|
|
128
|
-
"@distube/ytpl": "^1.1
|
|
129
|
-
"@distube/ytsr": "^1.
|
|
127
|
+
"@distube/ytdl-core": "^4.13.2",
|
|
128
|
+
"@distube/ytpl": "^1.2.1",
|
|
129
|
+
"@distube/ytsr": "^1.2.0",
|
|
130
130
|
"prism-media": "npm:@distube/prism-media@latest",
|
|
131
131
|
"tiny-typed-emitter": "^2.1.0",
|
|
132
132
|
"tough-cookie": "^4.1.3",
|
|
133
133
|
tslib: "^2.6.2",
|
|
134
|
-
undici: "^5.
|
|
134
|
+
undici: "^5.27.2"
|
|
135
135
|
},
|
|
136
136
|
devDependencies: {
|
|
137
|
-
"@babel/core": "^7.
|
|
137
|
+
"@babel/core": "^7.23.2",
|
|
138
138
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
139
139
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
140
140
|
"@babel/plugin-transform-private-methods": "^7.22.5",
|
|
141
|
-
"@babel/preset-env": "^7.
|
|
142
|
-
"@babel/preset-typescript": "^7.
|
|
143
|
-
"@commitlint/cli": "^
|
|
144
|
-
"@commitlint/config-conventional": "^
|
|
141
|
+
"@babel/preset-env": "^7.23.2",
|
|
142
|
+
"@babel/preset-typescript": "^7.23.2",
|
|
143
|
+
"@commitlint/cli": "^18.2.0",
|
|
144
|
+
"@commitlint/config-conventional": "^18.1.0",
|
|
145
145
|
"@discordjs/voice": "^0.16.0",
|
|
146
146
|
"@distubejs/docgen": "distubejs/docgen",
|
|
147
|
-
"@types/jest": "^29.5.
|
|
148
|
-
"@types/node": "^20.
|
|
149
|
-
"@types/tough-cookie": "^4.0.
|
|
150
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
151
|
-
"@typescript-eslint/parser": "^6.
|
|
152
|
-
"babel-jest": "^29.
|
|
147
|
+
"@types/jest": "^29.5.8",
|
|
148
|
+
"@types/node": "^20.9.0",
|
|
149
|
+
"@types/tough-cookie": "^4.0.5",
|
|
150
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
151
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
152
|
+
"babel-jest": "^29.7.0",
|
|
153
153
|
"discord.js": "^14.13.0",
|
|
154
|
-
eslint: "^8.
|
|
154
|
+
eslint: "^8.53.0",
|
|
155
155
|
"eslint-config-distube": "^1.6.4",
|
|
156
156
|
"eslint-config-prettier": "^9.0.0",
|
|
157
|
-
"eslint-plugin-deprecation": "^
|
|
158
|
-
"eslint-plugin-jsdoc": "^46.
|
|
157
|
+
"eslint-plugin-deprecation": "^2.0.0",
|
|
158
|
+
"eslint-plugin-jsdoc": "^46.8.2",
|
|
159
159
|
husky: "^8.0.3",
|
|
160
|
-
jest: "^29.
|
|
160
|
+
jest: "^29.7.0",
|
|
161
161
|
"jsdoc-babel": "^0.5.0",
|
|
162
162
|
"nano-staged": "^0.8.0",
|
|
163
|
-
"npm-check-updates": "^16.
|
|
163
|
+
"npm-check-updates": "^16.14.6",
|
|
164
164
|
pinst: "^3.0.0",
|
|
165
165
|
prettier: "^3.0.3",
|
|
166
166
|
tsup: "^7.2.0",
|
|
@@ -1116,13 +1116,7 @@ var DisTubeVoice = _DisTubeVoice;
|
|
|
1116
1116
|
// src/core/DisTubeStream.ts
|
|
1117
1117
|
var import_prism_media = require("prism-media");
|
|
1118
1118
|
var import_voice2 = require("@discordjs/voice");
|
|
1119
|
-
var chooseBestVideoFormat = /* @__PURE__ */ __name((formats, isLive
|
|
1120
|
-
let filter = /* @__PURE__ */ __name((format) => format.hasAudio, "filter");
|
|
1121
|
-
if (isLive)
|
|
1122
|
-
filter = /* @__PURE__ */ __name((format) => format.hasAudio && format.isHLS, "filter");
|
|
1123
|
-
formats = formats.filter(filter).sort((a, b) => Number(b.audioBitrate) - Number(a.audioBitrate) || Number(a.bitrate) - Number(b.bitrate));
|
|
1124
|
-
return formats.find((format) => !format.hasVideo) || formats.sort((a, b) => Number(a.bitrate) - Number(b.bitrate))[0];
|
|
1125
|
-
}, "chooseBestVideoFormat");
|
|
1119
|
+
var chooseBestVideoFormat = /* @__PURE__ */ __name(({ duration, formats, isLive }) => formats && formats.filter((f) => f.hasAudio && (duration < 10 * 60 || f.hasVideo) && (!isLive || f.isHLS)).sort((a, b) => Number(b.audioBitrate) - Number(a.audioBitrate) || Number(a.bitrate) - Number(b.bitrate))[0], "chooseBestVideoFormat");
|
|
1126
1120
|
var _DisTubeStream = class _DisTubeStream {
|
|
1127
1121
|
/**
|
|
1128
1122
|
* Create a DisTubeStream to play with {@link DisTubeVoice}
|
|
@@ -1168,18 +1162,20 @@ var _DisTubeStream = class _DisTubeStream {
|
|
|
1168
1162
|
}
|
|
1169
1163
|
/**
|
|
1170
1164
|
* Create a stream from ytdl video formats
|
|
1171
|
-
* @param {
|
|
1165
|
+
* @param {Song} song A YouTube Song
|
|
1172
1166
|
* @param {StreamOptions} options options
|
|
1173
1167
|
* @returns {DisTubeStream}
|
|
1174
1168
|
* @private
|
|
1175
1169
|
*/
|
|
1176
|
-
static YouTube(
|
|
1177
|
-
if (
|
|
1170
|
+
static YouTube(song, options = {}) {
|
|
1171
|
+
if (song.source !== "youtube")
|
|
1172
|
+
throw new DisTubeError("INVALID_TYPE", "youtube", song.source, "Song#source");
|
|
1173
|
+
if (!song.formats?.length)
|
|
1178
1174
|
throw new DisTubeError("UNAVAILABLE_VIDEO");
|
|
1179
1175
|
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
1180
1176
|
throw new DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
1181
1177
|
}
|
|
1182
|
-
const bestFormat = chooseBestVideoFormat(
|
|
1178
|
+
const bestFormat = chooseBestVideoFormat(song);
|
|
1183
1179
|
if (!bestFormat)
|
|
1184
1180
|
throw new DisTubeError("UNPLAYABLE_FORMATS");
|
|
1185
1181
|
return new _DisTubeStream(bestFormat.url, options);
|
|
@@ -1517,9 +1513,9 @@ var _DisTubeHandler = class _DisTubeHandler extends DisTubeBase {
|
|
|
1517
1513
|
* @param {Song} song A Song
|
|
1518
1514
|
*/
|
|
1519
1515
|
async attachStreamInfo(song) {
|
|
1520
|
-
const { url, source, formats, streamURL
|
|
1516
|
+
const { url, source, formats, streamURL } = song;
|
|
1521
1517
|
if (source === "youtube") {
|
|
1522
|
-
if (!formats || !chooseBestVideoFormat(
|
|
1518
|
+
if (!formats || !chooseBestVideoFormat(song)) {
|
|
1523
1519
|
song._patchYouTube(await this.handler.getYouTubeInfo(url));
|
|
1524
1520
|
}
|
|
1525
1521
|
} else if (!streamURL) {
|
|
@@ -1946,15 +1942,15 @@ var _QueueManager = class _QueueManager extends GuildIdManager {
|
|
|
1946
1942
|
* @returns {DisTubeStream}
|
|
1947
1943
|
*/
|
|
1948
1944
|
createStream(queue) {
|
|
1949
|
-
const
|
|
1945
|
+
const song = queue.songs[0];
|
|
1946
|
+
const { duration, source, streamURL } = song;
|
|
1950
1947
|
const streamOptions = {
|
|
1951
1948
|
ffmpegArgs: queue.filters.ffmpegArgs,
|
|
1952
1949
|
seek: duration ? queue.beginTime : void 0,
|
|
1953
|
-
isLive,
|
|
1954
1950
|
type: this.options.streamType
|
|
1955
1951
|
};
|
|
1956
1952
|
if (source === "youtube")
|
|
1957
|
-
return DisTubeStream.YouTube(
|
|
1953
|
+
return DisTubeStream.YouTube(song, streamOptions);
|
|
1958
1954
|
return DisTubeStream.DirectLink(streamURL, streamOptions);
|
|
1959
1955
|
}
|
|
1960
1956
|
/**
|