mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
filter workss
This commit is contained in:
1 parent
85f11fe34b
commit
0bdc37fa73
2 files changed
+76
-17
No files matched your search
+8
-8
@@ -320,7 +320,7 @@ export async function run(msg) {
|
|||||||
: `🔇 No filter active.\n\n${reason}`
|
: `🔇 No filter active.\n\n${reason}`
|
||||||
)
|
)
|
||||||
.setFooter({ text: "Session ended" })
|
.setFooter({ text: "Session ended" })
|
||||||
;
|
;
|
||||||
|
|
||||||
await menuMsg.edit({ embeds: [closedEmbed] }).catch(() => {});
|
await menuMsg.edit({ embeds: [closedEmbed] }).catch(() => {});
|
||||||
};
|
};
|
||||||
@@ -387,7 +387,7 @@ export async function run(msg) {
|
|||||||
const errEmbed = new EmbedBuilder()
|
const errEmbed = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
.setDescription("❌ Nothing is playing right now.")
|
.setDescription("❌ Nothing is playing right now.")
|
||||||
;
|
;
|
||||||
await menuMsg.edit({ embeds: [errEmbed] }).catch(() => {});
|
await menuMsg.edit({ embeds: [errEmbed] }).catch(() => {});
|
||||||
await Utils.sleep(2000);
|
await Utils.sleep(2000);
|
||||||
await menuMsg.edit({
|
await menuMsg.edit({
|
||||||
@@ -429,7 +429,7 @@ export async function run(msg) {
|
|||||||
`❌ Failed to apply **${filter.label}**: \`${reason}\`\n\n` +
|
`❌ Failed to apply **${filter.label}**: \`${reason}\`\n\n` +
|
||||||
`Make sure your NodeLink node has filters enabled.`
|
`Make sure your NodeLink node has filters enabled.`
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
await menuMsg.edit({ embeds: [errEmbed] }).catch(() => {});
|
await menuMsg.edit({ embeds: [errEmbed] }).catch(() => {});
|
||||||
await Utils.sleep(3000);
|
await Utils.sleep(3000);
|
||||||
await menuMsg.edit({
|
await menuMsg.edit({
|
||||||
@@ -448,10 +448,10 @@ export async function run(msg) {
|
|||||||
? `${filter.label} saved. It will apply on the next playable track.`
|
? `${filter.label} saved. It will apply on the next playable track.`
|
||||||
: `${filter.label} removed. The next playable track will use the updated filters.`)
|
: `${filter.label} removed. The next playable track will use the updated filters.`)
|
||||||
: filter.key === "off"
|
: filter.key === "off"
|
||||||
? "🔇 Filters cleared — original audio restored."
|
? "🔇 Filters cleared — original audio restored."
|
||||||
: activeKeys.includes(filter.key)
|
: activeKeys.includes(filter.key)
|
||||||
? `${filter.emoji} **${filter.label}** applied!`
|
? `${filter.emoji} **${filter.label}** applied!`
|
||||||
: `${filter.emoji} **${filter.label}** removed.`;
|
: `${filter.emoji} **${filter.label}** removed.`;
|
||||||
|
|
||||||
const confirmEmbed = new EmbedBuilder()
|
const confirmEmbed = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
@@ -460,7 +460,7 @@ export async function run(msg) {
|
|||||||
`*${filter.desc}*\n\n` +
|
`*${filter.desc}*\n\n` +
|
||||||
`💡 React again to toggle, or ${CANCEL_EMOJI} to close.`
|
`💡 React again to toggle, or ${CANCEL_EMOJI} to close.`
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
await menuMsg.edit({ embeds: [confirmEmbed] }).catch(() => {});
|
await menuMsg.edit({ embeds: [confirmEmbed] }).catch(() => {});
|
||||||
await Utils.sleep(2500);
|
await Utils.sleep(2500);
|
||||||
|
|||||||
+68
-9
@@ -883,7 +883,7 @@ export default class Player extends EventEmitter {
|
|||||||
// Audio Streaming (revoice.js)
|
// Audio Streaming (revoice.js)
|
||||||
// ═══════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
async _streamViaRevoice(url, options = {}) {
|
async _streamViaRevoice(url, inputOptions = []) {
|
||||||
if (this._streamingStopped) return;
|
if (this._streamingStopped) return;
|
||||||
|
|
||||||
this._streamingStopped = false;
|
this._streamingStopped = false;
|
||||||
@@ -951,7 +951,7 @@ export default class Player extends EventEmitter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const playResult = this._mediaPlayer.playStream(audioStream, options);
|
const playResult = this._mediaPlayer.playStream(audioStream, inputOptions);
|
||||||
if (playResult && typeof playResult.catch === "function") {
|
if (playResult && typeof playResult.catch === "function") {
|
||||||
playResult.catch((e) => {
|
playResult.catch((e) => {
|
||||||
if (isIgnorableMediaStateError(e) || this._streamingStopped || this._skipping || this.leaving) {
|
if (isIgnorableMediaStateError(e) || this._streamingStopped || this._skipping || this.leaving) {
|
||||||
@@ -1030,8 +1030,10 @@ export default class Player extends EventEmitter {
|
|||||||
|
|
||||||
if (url.includes("/v4/loadstream")) {
|
if (url.includes("/v4/loadstream")) {
|
||||||
logger.player(`[Player] NodeLink loadStream PCM active`);
|
logger.player(`[Player] NodeLink loadStream PCM active`);
|
||||||
|
// Raw PCM from NodeLink — tell FFmpeg the input format
|
||||||
|
const pcmInputOpts = ["-f", "s16le", "-ar", "48000", "-ac", "2"];
|
||||||
try {
|
try {
|
||||||
return await this._streamViaRevoice(url, { rawPcm: true });
|
return await this._streamViaRevoice(url, pcmInputOpts);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = err?.message ?? String(err ?? "");
|
const msg = err?.message ?? String(err ?? "");
|
||||||
if (msg.includes("HTTP ")) {
|
if (msg.includes("HTTP ")) {
|
||||||
@@ -1474,6 +1476,19 @@ export default class Player extends EventEmitter {
|
|||||||
this.activeFilter = meta ?? null;
|
this.activeFilter = meta ?? null;
|
||||||
this.activeFilterPayload = meta ? filterPayload : null;
|
this.activeFilterPayload = meta ? filterPayload : null;
|
||||||
this.emit("filter", this.activeFilter);
|
this.emit("filter", this.activeFilter);
|
||||||
|
|
||||||
|
// Restart the current stream so the loadstream URL picks up the new filters.
|
||||||
|
// The PATCH only updates NodeLink's player state — it does NOT modify the
|
||||||
|
// currently-streaming PCM pipe. Without restarting, the audio won't change.
|
||||||
|
if (current?.encoded && this.connection && !this.leaving && !this._streamingStopped) {
|
||||||
|
const elapsed = this.startedPlaying ? (Date.now() - this.startedPlaying) : 0;
|
||||||
|
const positionMs = Math.max(0, elapsed);
|
||||||
|
logger.player(`[Player] Filter applied — restarting stream from ${positionMs}ms`);
|
||||||
|
this._replayWithFilters(positionMs).catch((e) => {
|
||||||
|
logger.warn("[Player] Filter replay failed (non-fatal):", e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errMsg = e.message ?? "";
|
const errMsg = e.message ?? "";
|
||||||
@@ -1489,6 +1504,50 @@ export default class Player extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart playback of the current track from a given position with the
|
||||||
|
* currently active filters baked into the loadstream URL.
|
||||||
|
*/
|
||||||
|
async _replayWithFilters(positionMs = 0) {
|
||||||
|
const current = this.queue.getCurrent();
|
||||||
|
if (!current?.encoded || !this.connection || this.leaving) return;
|
||||||
|
|
||||||
|
// Stop the current stream (kills FFmpeg + passthrough)
|
||||||
|
this._streamingStopped = true;
|
||||||
|
await this._stopMediaPlayer().catch(() => {});
|
||||||
|
this._streamingStopped = false;
|
||||||
|
|
||||||
|
// Small delay to let the old pipe fully drain
|
||||||
|
await Utils.sleep(100);
|
||||||
|
|
||||||
|
// _stopMediaPlayer sets _mediaPlayer to null — must recreate before streaming
|
||||||
|
const hasPlayer = await this._ensureMediaPlayer();
|
||||||
|
if (!hasPlayer) {
|
||||||
|
logger.warn("[Player] _replayWithFilters: could not recreate MediaPlayer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore volume on the fresh player
|
||||||
|
if (this.preferredVolume !== 1) {
|
||||||
|
this._mediaPlayer.setVolume(this.preferredVolume);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a fresh loadstream URL — include filters so NodeLink applies them server-side
|
||||||
|
const nlBase = `http://${this._nl.host}:${this._nl.port}`;
|
||||||
|
let streamUrl = `${nlBase}/v4/loadstream?encodedTrack=${encodeURIComponent(current.encoded)}&position=${positionMs}&volume=100`;
|
||||||
|
|
||||||
|
// Append active filter payload to the URL so NodeLink processes them
|
||||||
|
if (this.activeFilterPayload) {
|
||||||
|
streamUrl += `&filters=${encodeURIComponent(JSON.stringify(this.activeFilterPayload))}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this._streamUrl(streamUrl);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn("[Player] _replayWithFilters stream error:", e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
// Queue Management
|
// Queue Management
|
||||||
// ═══════════════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
@@ -2018,12 +2077,12 @@ export default class Player extends EventEmitter {
|
|||||||
} else if (songData.encoded) {
|
} else if (songData.encoded) {
|
||||||
const nlBase = `http://${this._nl.host}:${this._nl.port}`;
|
const nlBase = `http://${this._nl.host}:${this._nl.port}`;
|
||||||
const positionMs = 0;
|
const positionMs = 0;
|
||||||
const filters = this.activeFilterPayload ?? {};
|
streamUrl = `${nlBase}/v4/loadstream?encodedTrack=${encodeURIComponent(songData.encoded)}&position=${positionMs}&volume=100`;
|
||||||
const filtersParam =
|
|
||||||
Object.keys(filters).length > 0
|
// Append active filters so NodeLink applies them server-side
|
||||||
? `&filters=${encodeURIComponent(JSON.stringify(filters))}`
|
if (this.activeFilterPayload) {
|
||||||
: "";
|
streamUrl += `&filters=${encodeURIComponent(JSON.stringify(this.activeFilterPayload))}`;
|
||||||
streamUrl = `${nlBase}/v4/loadstream?encodedTrack=${encodeURIComponent(songData.encoded)}&position=${positionMs}&volume=100${filtersParam}`;
|
}
|
||||||
} else if (songData.url && Utils.isValidUrl(songData.url)) {
|
} else if (songData.url && Utils.isValidUrl(songData.url)) {
|
||||||
streamUrl = songData.url;
|
streamUrl = songData.url;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user