todo
This commit is contained in:
parent
f72c91849c
commit
36567e346f
9 changed files with 214 additions and 7 deletions
|
@ -29,7 +29,8 @@
|
||||||
"homepage": "https://github.com/Androz2091/discord-player#readme",
|
"homepage": "https://github.com/Androz2091/discord-player#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord-ytdl-core": "^5.0.2",
|
"discord-ytdl-core": "^5.0.2",
|
||||||
"youtube-sr": "^4.0.3"
|
"youtube-sr": "^4.0.3",
|
||||||
|
"ytdl-core": "^4.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/opus": "^0.5.0",
|
"@discordjs/opus": "^0.5.0",
|
||||||
|
|
47
src/AudioFilters.ts
Normal file
47
src/AudioFilters.ts
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
export default {
|
||||||
|
bassboost: "bass=g=20",
|
||||||
|
"8D": "apulsator=hz=0.09",
|
||||||
|
vaporwave: "aresample=48000,asetrate=48000*0.8",
|
||||||
|
nightcore: "aresample=48000,asetrate=48000*1.25",
|
||||||
|
phaser: "aphaser=in_gain=0.4",
|
||||||
|
tremolo: "tremolo",
|
||||||
|
vibrato: "vibrato=f=6.5",
|
||||||
|
reverse: "areverse",
|
||||||
|
treble: "treble=g=5",
|
||||||
|
normalizer: "dynaudnorm=g=101",
|
||||||
|
surrounding: "surround",
|
||||||
|
pulsator: "apulsator=hz=1",
|
||||||
|
subboost: "asubboost",
|
||||||
|
karaoke: "stereotools=mlev=0.03",
|
||||||
|
flanger: "flanger",
|
||||||
|
gate: "agate",
|
||||||
|
haas: "haas",
|
||||||
|
mcompand: "mcompand",
|
||||||
|
mono: "pan=mono|c0=.5*c0+.5*c1",
|
||||||
|
mstlr: "stereotools=mode=ms>lr",
|
||||||
|
mstrr: "stereotools=mode=ms>rr",
|
||||||
|
compressor: "compand=points=-80/-105|-62/-80|-15.4/-15.4|0/-12|20/-7.6",
|
||||||
|
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",
|
||||||
|
softlimiter: "compand=attacks=0:points=-80/-80|-12.4/-12.4|-6/-8|0/-6.8|20/-2.8",
|
||||||
|
chorus: "chorus=0.7:0.9:55:0.4:0.25:2",
|
||||||
|
chorus2d: "chorus=0.6:0.9:50|60:0.4|0.32:0.25|0.4:2|1.3",
|
||||||
|
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",
|
||||||
|
fadein: "afade=t=in:ss=0:d=10",
|
||||||
|
|
||||||
|
*[Symbol.iterator](): IterableIterator<{ name: string, value: string }> {
|
||||||
|
for (const [k, v] of Object.entries(this)) {
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
yield { name: k, value: v };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get names() {
|
||||||
|
return Object.keys(this);
|
||||||
|
},
|
||||||
|
get length() {
|
||||||
|
return Object.keys(this).length;
|
||||||
|
},
|
||||||
|
toString() {
|
||||||
|
return `"${Object.values(this).join(",")}"`
|
||||||
|
}
|
||||||
|
};
|
30
src/Player.ts
Normal file
30
src/Player.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
import { Client } from "discord.js";
|
||||||
|
import { PlayerOptions } from "./types/Player";
|
||||||
|
import Util from "./Util";
|
||||||
|
|
||||||
|
export default class Player extends EventEmitter {
|
||||||
|
public client!: Client;
|
||||||
|
public options: PlayerOptions;
|
||||||
|
|
||||||
|
constructor(client: Client, options?: PlayerOptions) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The discord client that instantiated this player
|
||||||
|
*/
|
||||||
|
Object.defineProperty(this, "client", {
|
||||||
|
value: client,
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player options
|
||||||
|
*/
|
||||||
|
this.options = Object.assign({}, Util.DefaultPlayerOptions, options ?? {});
|
||||||
|
|
||||||
|
// check FFmpeg
|
||||||
|
void Util.alertFFmpeg();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
13
src/Structures/Queue.ts
Normal file
13
src/Structures/Queue.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import Player from "../Player";
|
||||||
|
|
||||||
|
export default class Queue {
|
||||||
|
public player!: Player;
|
||||||
|
|
||||||
|
constructor(player: Player) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player that instantiated this Queue
|
||||||
|
*/
|
||||||
|
Object.defineProperty(this, "player", { value: player, enumerable: false });
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,38 @@
|
||||||
export default class Track {}
|
import Player from "../Player";
|
||||||
|
import { User } from "discord.js";
|
||||||
|
|
||||||
|
export default class Track {
|
||||||
|
public player!: Player;
|
||||||
|
public title!: string;
|
||||||
|
public description!: string;
|
||||||
|
public author!: string;
|
||||||
|
public url!: string;
|
||||||
|
public thumbnail!: string;
|
||||||
|
public duration!: string;
|
||||||
|
public views!: number;
|
||||||
|
public requestedBy!: User;
|
||||||
|
public fromPlaylist!: boolean;
|
||||||
|
|
||||||
|
constructor(player: Player, data: any) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player that instantiated this Track
|
||||||
|
*/
|
||||||
|
Object.defineProperty(this, "player", { value: player, enumerable: false });
|
||||||
|
|
||||||
|
void this._patch(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _patch(data: any) {
|
||||||
|
this.title = data.title ?? "";
|
||||||
|
this.description = data.description ?? "";
|
||||||
|
this.author = data.author ?? "";
|
||||||
|
this.url = data.url ?? "";
|
||||||
|
this.thumbnail = typeof data.thumbnail === "object" ? data.thumbnail.url : data.thumbnail;
|
||||||
|
this.duration = data.duration ?? "";
|
||||||
|
this.views = data.views ?? 0;
|
||||||
|
this.requestedBy = data.requestedBy;
|
||||||
|
this.fromPlaylist = Boolean(data.fromPlaylist);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
38
src/Util.ts
Normal file
38
src/Util.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { PlayerOptions } from "./types/Player";
|
||||||
|
import { FFmpeg } from "prism-media";
|
||||||
|
|
||||||
|
export default class Util {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
throw new Error(`The ${this.constructor.name} class is static and cannot be instantiated!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get DefaultPlayerOptions() {
|
||||||
|
return {
|
||||||
|
leaveOnEnd: true,
|
||||||
|
leaveOnStop: true,
|
||||||
|
leaveOnEmpty: true,
|
||||||
|
leaveOnEmptyCooldown: 0,
|
||||||
|
autoSelfDeaf: true,
|
||||||
|
enableLive: false,
|
||||||
|
ytdlDownloadOptions: {}
|
||||||
|
} as PlayerOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
static checkFFmpeg(force?: boolean) {
|
||||||
|
try {
|
||||||
|
FFmpeg.getInfo(Boolean(force));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static alertFFmpeg() {
|
||||||
|
const hasFFmpeg = Util.checkFFmpeg();
|
||||||
|
|
||||||
|
if (!hasFFmpeg) console.warn("[Discord Player] FFmpeg/Avconv not found! Install via \"npm install ffmpeg-static\" or download from https://ffmpeg.org/download.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
src/index.ts
12
src/index.ts
|
@ -1,5 +1,7 @@
|
||||||
import { version } from "../package.json"
|
export * as AudioFilters from "./AudioFilters";
|
||||||
|
export * as Player from "./Player";
|
||||||
export {
|
export * as Util from "./Util";
|
||||||
version
|
export * as Track from "./Structures/Track";
|
||||||
}
|
export * as Queue from "./Structures/Queue";
|
||||||
|
export * from "./types/Player";
|
||||||
|
export { version } from "../package.json";
|
12
src/types/Player.ts
Normal file
12
src/types/Player.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { downloadOptions } from "ytdl-core";
|
||||||
|
|
||||||
|
export interface PlayerOptions {
|
||||||
|
leaveOnEnd?: boolean;
|
||||||
|
leaveOnEndCooldown?: number;
|
||||||
|
leaveOnStop?: boolean;
|
||||||
|
leaveOnEmpty?: boolean;
|
||||||
|
leaveOnEmptyCooldown?: number;
|
||||||
|
autoSelfDeaf?: boolean;
|
||||||
|
enableLive?: boolean;
|
||||||
|
ytdlDownloadOptions?: downloadOptions;
|
||||||
|
}
|
27
yarn.lock
27
yarn.lock
|
@ -281,6 +281,14 @@ lru-cache@^6.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
yallist "^4.0.0"
|
yallist "^4.0.0"
|
||||||
|
|
||||||
|
m3u8stream@^0.8.3:
|
||||||
|
version "0.8.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/m3u8stream/-/m3u8stream-0.8.3.tgz#c4624e92b4240eb356d040c4a5e155586cf58108"
|
||||||
|
integrity sha512-0nAcdrF8YJKUkb6PzWdvGftTPyCVWgoiot1AkNVbPKTeIGsWs6DrOjifrJ0Zi8WQfQmD2SuVCjkYIOip12igng==
|
||||||
|
dependencies:
|
||||||
|
miniget "^4.0.0"
|
||||||
|
sax "^1.2.4"
|
||||||
|
|
||||||
make-dir@^3.1.0:
|
make-dir@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
|
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
|
||||||
|
@ -300,6 +308,11 @@ mime-types@^2.1.12:
|
||||||
dependencies:
|
dependencies:
|
||||||
mime-db "1.47.0"
|
mime-db "1.47.0"
|
||||||
|
|
||||||
|
miniget@^4.0.0:
|
||||||
|
version "4.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/miniget/-/miniget-4.2.0.tgz#0004e95536b192d95a7d09f4435d67b9285481d0"
|
||||||
|
integrity sha512-IzTOaNgBw/qEpzkPTE7X2cUVXQfSKbG8w52Emi93zb+Zya2ZFrbmavpixzebuDJD9Ku4ecbaFlC7Y1cEESzQtQ==
|
||||||
|
|
||||||
minimatch@^3.0.4:
|
minimatch@^3.0.4:
|
||||||
version "3.0.4"
|
version "3.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
||||||
|
@ -416,6 +429,11 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1:
|
||||||
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
|
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
|
||||||
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
|
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
|
||||||
|
|
||||||
|
sax@^1.1.3, sax@^1.2.4:
|
||||||
|
version "1.2.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
|
||||||
|
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
|
||||||
|
|
||||||
semver@^6.0.0:
|
semver@^6.0.0:
|
||||||
version "6.3.0"
|
version "6.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
||||||
|
@ -535,3 +553,12 @@ youtube-sr@^4.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
node-fetch "^2.6.1"
|
node-fetch "^2.6.1"
|
||||||
simple-youtube-api "^5.2.1"
|
simple-youtube-api "^5.2.1"
|
||||||
|
|
||||||
|
ytdl-core@^4.5.0:
|
||||||
|
version "4.5.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.5.0.tgz#f07733387c548e5c3a5614c93ef55bde666eeaf4"
|
||||||
|
integrity sha512-e8r6skrakWNixsVlNPBMoRM1HrdW1swE97If9nenDUjF65uogYk4DvxIuqlmqRfBWKe+6aIZwqedNxUU9XLYJA==
|
||||||
|
dependencies:
|
||||||
|
m3u8stream "^0.8.3"
|
||||||
|
miniget "^4.0.0"
|
||||||
|
sax "^1.1.3"
|
||||||
|
|
Loading…
Reference in a new issue