discord-player
Advanced tools
Comparing version 5.0.0-dev.0 to 5.0.0-dev.1
@@ -17,3 +17,3 @@ /// <reference types="node" /> | ||
repeatMode: QueueRepeatMode; | ||
_streamTime: number; | ||
private _streamTime; | ||
_cooldownsTimeout: Collection<string, NodeJS.Timeout>; | ||
@@ -36,3 +36,6 @@ private _activeFilters; | ||
get streamTime(): number; | ||
setFilters(filters: QueueFilters): Promise<void>; | ||
getFiltersEnabled(): string[]; | ||
getFiltersDisabled(): string[]; | ||
setFilters(filters?: QueueFilters): Promise<void>; | ||
seek(position: number): Promise<boolean>; | ||
back(): Promise<void>; | ||
@@ -43,2 +46,3 @@ play(src?: Track, options?: PlayOptions): Promise<void>; | ||
guild: `${bigint}`; | ||
voiceChannel: `${bigint}`; | ||
options: PlayerOptions; | ||
@@ -45,0 +49,0 @@ tracks: import("../types/types").TrackJSON[]; |
@@ -17,2 +17,3 @@ "use strict"; | ||
const discord_js_1 = require("discord.js"); | ||
const Track_1 = __importDefault(require("./Track")); | ||
const types_1 = require("../types/types"); | ||
@@ -33,3 +34,3 @@ const discord_ytdl_core_1 = __importDefault(require("discord-ytdl-core")); | ||
this._cooldownsTimeout = new discord_js_1.Collection(); | ||
this._activeFilters = {}; | ||
this._activeFilters = []; | ||
this.player = player; | ||
@@ -49,3 +50,3 @@ this.guild = guild; | ||
fetchBeforeQueued: false, | ||
initialVolume: 50 | ||
initialVolume: 100 | ||
}, options); | ||
@@ -117,3 +118,3 @@ } | ||
setRepeatMode(mode) { | ||
if (![types_1.QueueRepeatMode.OFF, types_1.QueueRepeatMode.QUEUE, types_1.QueueRepeatMode.TRACK].includes(mode)) | ||
if (![types_1.QueueRepeatMode.OFF, types_1.QueueRepeatMode.QUEUE, types_1.QueueRepeatMode.TRACK, types_1.QueueRepeatMode.AUTOPLAY].includes(mode)) | ||
throw new Error(`Unknown repeat mode "${mode}"!`); | ||
@@ -136,8 +137,27 @@ if (mode === this.repeatMode) | ||
return 0; | ||
return this._streamTime + this.connection.streamTime; | ||
const playbackTime = this._streamTime + this.connection.streamTime; | ||
const NC = this._activeFilters.includes("nightcore") ? 1.25 : null; | ||
const VW = this._activeFilters.includes("vaporwave") ? 0.8 : null; | ||
if (NC && VW) | ||
return playbackTime * (NC + VW); | ||
return NC ? playbackTime * NC : VW ? playbackTime * VW : playbackTime; | ||
} | ||
getFiltersEnabled() { | ||
return AudioFilters_1.default.names.filter((x) => this._activeFilters.includes(x)); | ||
} | ||
getFiltersDisabled() { | ||
return AudioFilters_1.default.names.filter((x) => !this._activeFilters.includes(x)); | ||
} | ||
setFilters(filters) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!Object.keys(filters).length) | ||
return; | ||
if (!filters || !Object.keys(filters).length) { | ||
const streamTime = this.streamTime; | ||
this._activeFilters = []; | ||
return yield this.play(this.current, { | ||
immediate: true, | ||
filtersUpdate: true, | ||
seek: streamTime, | ||
encoderArgs: [] | ||
}); | ||
} | ||
const _filters = []; | ||
@@ -148,6 +168,11 @@ for (const filter in filters) { | ||
} | ||
if (this._activeFilters.join("") === _filters.join("")) | ||
return; | ||
const newFilters = AudioFilters_1.default.create(_filters); | ||
const streamTime = this.streamTime; | ||
this._activeFilters = _filters; | ||
return yield this.play(this.current, { | ||
immediate: true, | ||
filtersUpdate: true, | ||
seek: this.streamTime, | ||
seek: streamTime, | ||
encoderArgs: ["-af", newFilters] | ||
@@ -157,2 +182,18 @@ }); | ||
} | ||
seek(position) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.playing || !this.current) | ||
return false; | ||
if (position < 1) | ||
position = 0; | ||
if (position >= this.current.durationMS) | ||
return this.skip(); | ||
yield this.play(this.current, { | ||
immediate: true, | ||
filtersUpdate: true, | ||
seek: position | ||
}); | ||
return true; | ||
}); | ||
} | ||
back() { | ||
@@ -164,3 +205,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
play(src, options = {}) { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -188,3 +229,3 @@ if (!this.connection || !this.connection.voiceConnection) | ||
return void this.play(this.tracks.shift(), { immediate: true }); | ||
stream = discord_ytdl_core_1.default(link, Object.assign(Object.assign({}, this.options.ytdlOptions), { opusEncoded: false, fmt: "s16le", encoderArgs: (_a = options.encoderArgs) !== null && _a !== void 0 ? _a : [], seek: options.seek })).on("error", (err) => this.player.emit("error", this, err)); | ||
stream = discord_ytdl_core_1.default(link, Object.assign(Object.assign({}, this.options.ytdlOptions), { opusEncoded: false, fmt: "s16le", encoderArgs: ((_a = options.encoderArgs) !== null && _a !== void 0 ? _a : this._activeFilters.length) ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [], seek: options.seek ? options.seek / 1000 : 0 })).on("error", (err) => (err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err))); | ||
} | ||
@@ -196,6 +237,6 @@ else { | ||
fmt: "s16le", | ||
encoderArgs: (_b = options.encoderArgs) !== null && _b !== void 0 ? _b : [], | ||
seek: options.seek | ||
encoderArgs: ((_b = options.encoderArgs) !== null && _b !== void 0 ? _b : this._activeFilters.length) ? ["-af", AudioFilters_1.default.create(this._activeFilters)] : [], | ||
seek: options.seek ? options.seek / 1000 : 0 | ||
}) | ||
.on("error", (err) => this.player.emit("error", this, err)); | ||
.on("error", (err) => (err.message.toLowerCase().includes("premature close") ? null : this.player.emit("error", this, err))); | ||
} | ||
@@ -209,3 +250,3 @@ const resource = this.connection.createStream(stream, { | ||
const dispatcher = yield this.connection.playStream(resource); | ||
dispatcher.setVolume(options.encoderArgs && ((_c = options.encoderArgs[1]) === null || _c === void 0 ? void 0 : _c.includes("bass=g")) ? this.options.initialVolume + 35 : this.options.initialVolume); | ||
dispatcher.setVolume(this.options.initialVolume); | ||
dispatcher.once("start", () => { | ||
@@ -216,3 +257,4 @@ this.playing = true; | ||
}); | ||
dispatcher.once("finish", () => { | ||
dispatcher.once("finish", () => __awaiter(this, void 0, void 0, function* () { | ||
var _c; | ||
this.playing = false; | ||
@@ -228,10 +270,41 @@ if (options.filtersUpdate) | ||
else { | ||
if (this.repeatMode === types_1.QueueRepeatMode.TRACK) | ||
return void this.play(Util_1.Util.last(this.previousTracks), { immediate: true }); | ||
if (this.repeatMode === types_1.QueueRepeatMode.QUEUE) | ||
this.tracks.push(Util_1.Util.last(this.previousTracks)); | ||
const nextTrack = this.tracks.shift(); | ||
this.play(nextTrack, { immediate: true }); | ||
if (this.repeatMode !== types_1.QueueRepeatMode.AUTOPLAY) { | ||
if (this.repeatMode === types_1.QueueRepeatMode.TRACK) | ||
return void this.play(Util_1.Util.last(this.previousTracks), { immediate: true }); | ||
if (this.repeatMode === types_1.QueueRepeatMode.QUEUE) | ||
this.tracks.push(Util_1.Util.last(this.previousTracks)); | ||
const nextTrack = this.tracks.shift(); | ||
this.play(nextTrack, { immediate: true }); | ||
return; | ||
} | ||
else { | ||
if (![track.source, (_c = track.raw) === null || _c === void 0 ? void 0 : _c.source].includes("youtube")) { | ||
if (this.options.leaveOnEnd) | ||
this.destroy(); | ||
return void this.player.emit("queueEnd", this); | ||
} | ||
const info = yield discord_ytdl_core_1.default | ||
.getInfo(track.url) | ||
.then((x) => x.related_videos[0]) | ||
.catch(() => { }); | ||
if (!info) { | ||
if (this.options.leaveOnEnd) | ||
this.destroy(); | ||
return void this.player.emit("queueEnd", this); | ||
} | ||
const nextTrack = new Track_1.default(this.player, { | ||
title: info.title, | ||
url: `https://www.youtube.com/watch?v=${info.id}`, | ||
duration: info.length_seconds ? Util_1.Util.buildTimeCode(Util_1.Util.parseMS(info.length_seconds * 1000)) : "0:00", | ||
description: "", | ||
thumbnail: Util_1.Util.last(info.thumbnails).url, | ||
views: parseInt(info.view_count.replace(/[^0-9]/g, "")), | ||
author: typeof info.author === "string" ? info.author : info.author.name, | ||
requestedBy: track.requestedBy, | ||
source: "youtube" | ||
}); | ||
this.play(nextTrack, { immediate: true }); | ||
} | ||
} | ||
}); | ||
})); | ||
}); | ||
@@ -243,4 +316,6 @@ } | ||
toJSON() { | ||
var _a, _b; | ||
return { | ||
guild: this.guild.id, | ||
voiceChannel: (_b = (_a = this.connection) === null || _a === void 0 ? void 0 : _a.channel) === null || _b === void 0 ? void 0 : _b.id, | ||
options: this.options, | ||
@@ -247,0 +322,0 @@ tracks: this.tracks.map((m) => m.toJSON()) |
@@ -21,2 +21,3 @@ /// <reference types="node" /> | ||
normalizer?: boolean; | ||
normalizer2?: boolean; | ||
surrounding?: boolean; | ||
@@ -40,2 +41,4 @@ pulsator?: boolean; | ||
fadein?: boolean; | ||
dim?: string; | ||
earrape?: string; | ||
}; | ||
@@ -154,3 +157,4 @@ export declare type TrackSource = "soundcloud" | "youtube" | "spotify" | "arbitrary"; | ||
TRACK = 1, | ||
QUEUE = 2 | ||
QUEUE = 2, | ||
AUTOPLAY = 3 | ||
} | ||
@@ -157,0 +161,0 @@ export interface PlaylistInitData { |
@@ -27,2 +27,3 @@ "use strict"; | ||
QueueRepeatMode[QueueRepeatMode["QUEUE"] = 2] = "QUEUE"; | ||
QueueRepeatMode[QueueRepeatMode["AUTOPLAY"] = 3] = "AUTOPLAY"; | ||
})(QueueRepeatMode = exports.QueueRepeatMode || (exports.QueueRepeatMode = {})); |
@@ -13,2 +13,3 @@ import { FiltersName } from "../types/types"; | ||
normalizer: string; | ||
normalizer2: string; | ||
surrounding: string; | ||
@@ -32,2 +33,4 @@ pulsator: string; | ||
fadein: string; | ||
dim: string; | ||
earrape: string; | ||
[Symbol.iterator](): IterableIterator<{ | ||
@@ -34,0 +37,0 @@ name: FiltersName; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const FilterList = { | ||
bassboost: "bass=g=20", | ||
bassboost: "bass=g=20:f=110:w=0.3", | ||
"8D": "apulsator=hz=0.09", | ||
@@ -16,2 +16,3 @@ vaporwave: "aresample=48000,asetrate=48000*0.8", | ||
normalizer: "dynaudnorm=g=101", | ||
normalizer2: "acompressor", | ||
surrounding: "surround", | ||
@@ -35,2 +36,4 @@ pulsator: "apulsator=hz=1", | ||
fadein: "afade=t=in:ss=0:d=10", | ||
dim: `afftfilt="'real=re * (1-clip((b/nb)*b,0,1))':imag='im * (1-clip((b/nb)*b,0,1))'"`, | ||
earrape: "channelsplit,sidechaingate=level_in=64", | ||
*[Symbol.iterator]() { | ||
@@ -49,3 +52,3 @@ for (const [k, v] of Object.entries(this)) { | ||
toString() { | ||
return this.names.map(m => this[m]).join(","); | ||
return this.names.map((m) => this[m]).join(","); | ||
}, | ||
@@ -52,0 +55,0 @@ create(filter) { |
@@ -130,3 +130,3 @@ "use strict"; | ||
return 0; | ||
return Math.floor(this.audioResource.playbackDuration / 1000); | ||
return this.audioResource.playbackDuration; | ||
} | ||
@@ -133,0 +133,0 @@ get paused() { |
{ | ||
"name": "discord-player", | ||
"version": "5.0.0-dev.0", | ||
"version": "5.0.0-dev.1", | ||
"description": "Complete framework to facilitate music commands using discord.js", | ||
@@ -54,3 +54,3 @@ "main": "lib/index.js", | ||
"@discordjs/voice": "^0.5.0", | ||
"discord-ytdl-core": "^5.0.3", | ||
"discord-ytdl-core": "^5.0.4", | ||
"libsodium-wrappers": "^0.7.9", | ||
@@ -57,0 +57,0 @@ "soundcloud-scraper": "^5.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
87970
1743
0
Updateddiscord-ytdl-core@^5.0.4