feat(music): support direct media playback from Fluxer attachments and uploaded files (#24)

- Add AttachmentUtils for detecting fluxerusercontent.com URLs and chat file attachments
- Support playing uploaded audio/video files directly via %play and %playnext
- Add Route 3d in-process ffmpeg decoding for container formats (.mp4, .mkv, .mov, etc.)
- Add native zero-re-encode passthrough for .opus, .webm, and .ogg attachments
- Add 📎 Fluxer Attachment source badges and embeds across all 6 locales
- Fixes #24
This commit is contained in:
NoLogicAlan committed 2026-10-29 03:08:20 +03:00
1 parent 91e7812c30
commit 7c5fb1e468
14 files changed
+300 -18

No files matched your search

+41 -3
View File
@@ -12,6 +12,11 @@ import { PROVIDER_CHOICES, parseInlineProvider } from "../src/music/providers.mj
import { playLastFmCategory } from "./lastfm.mjs";
import { parseLastFmUrl, isLastFmUrl } from "../src/services/lastfm/LastFmManager.mjs";
import { ERROR_COLOR } from "../src/utils/UI.mjs";
import {
getPlayableAttachment,
isFluxerAttachmentUrl,
extractMediaTitle,
} from "../src/utils/AttachmentUtils.mjs";
const LASTFM_PLAY_CATEGORIES = ["loved", "top", "recent", "albums"];
@@ -102,7 +107,7 @@ const KNOWN_SERVICE_HOSTS = /(?:youtu(?:be\.com|\.be)|youtube\.com|music\.youtub
const NATIVE_AUDIO_EXTENSIONS = /\.(?:opus|webm|ogg)(?:\?|$)/i;
/** Audio file extensions that indicate any direct audio URL (broader set). */
const AUDIO_EXTENSIONS = /\.(?:mp3|m4a|aac|ogg|opus|flac|wav|wma|webm|stream|m3u8|pls)(?:\?|$)/i;
const AUDIO_EXTENSIONS = /\.(?:mp3|m4a|aac|ogg|opus|flac|wav|wma|webm|mp4|mkv|mov|stream|m3u8|pls)(?:\?|$)/i;
/** Common stream/radio content-type paths or patterns. */
const STREAM_PATH_HINTS = /\/(?:stream|live|radio|audio|playlist|play|listen|mp3|aac|ogg)/i;
@@ -139,6 +144,7 @@ function isDirectAudioUrl(str) {
try {
const url = new URL(trimmed);
if (KNOWN_SERVICE_HOSTS.test(url.hostname)) return false;
if (isFluxerAttachmentUrl(trimmed)) return true;
if (AUDIO_EXTENSIONS.test(url.pathname)) return true;
if (STREAM_PATH_HINTS.test(url.pathname) && !url.pathname.includes(".html") && !url.pathname.includes(".php")) {
return true;
@@ -185,7 +191,7 @@ export const command = new CommandBuilder()
.addTextOption(option =>
option.setName("query")
.setDescription("A search query, music genre (for example `pop`), URL, or provider-prefixed query like `sp: song name`.", "options.play.query")
.setRequired(true)
.setRequired(false)
)
.addChoiceOption(o =>
o.setName("provider")
@@ -229,7 +235,39 @@ function forwardPlayMessage(d, statusMsg, message) {
* @returns {Promise<void>}
*/
export async function run(message, data) {
const rawQuery = data.get("query").value;
const attachment = getPlayableAttachment(message);
const rawQuery = data.get("query")?.value?.trim() || "";
/* Handle case where neither a query nor an attachment was supplied */
if (!rawQuery && !attachment) {
const noQueryEmbed = new EmbedBuilder()
.setColor(ERROR_COLOR)
.setAuthor({ name: this.t(message, "responses.play.noQueryTitle") })
.setDescription(this.t(message, "responses.play.noQueryDesc"))
.setFooter({ text: this.t(message, "responses.play.noQueryFooter") });
return message.reply({ embeds: [noQueryEmbed] });
}
/* Handle direct Fluxer user attachment or fluxerusercontent.com URL */
const isAttachment = Boolean(attachment) || isFluxerAttachmentUrl(rawQuery);
if (isAttachment) {
const mediaUrl = attachment ? attachment.url : rawQuery;
const cleanTitle = attachment ? extractMediaTitle(attachment.filename) : extractMediaTitle(rawQuery);
const p = await this.getPlayer(message, true, true, true);
if (!p) return;
const statusEmbed = new EmbedBuilder()
.setColor(getGlobalColor())
.setAuthor({ name: this.t(message, "responses.play.streamPipelineAuthor") })
.setDescription(this.t(message, "responses.play.loadingAttachmentStream"));
let statusMsg = null;
try { statusMsg = await message.reply({ embeds: [statusEmbed] }); } catch(e) { logger.warn("[Play] Error:", e?.message); }
const messages = p.playExternal(mediaUrl, cleanTitle, "Fluxer Attachment", false, "attachment");
messages.on("message", d => forwardPlayMessage(d, statusMsg, message));
return;
}
const flagProvider = data.get("provider")?.value;
const { provider: inlineProvider, query } = parseInlineProvider(rawQuery);
const provider = inlineProvider ?? flagProvider ?? "ytm";
+49 -2
View File
@@ -8,6 +8,12 @@ import { CommandBuilder } from "../src/commands/index.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../src/ui/index.mjs";
import { PROVIDER_CHOICES, parseInlineProvider } from "../src/music/providers.mjs";
import { ERROR_COLOR } from "../src/utils/UI.mjs";
import {
getPlayableAttachment,
isFluxerAttachmentUrl,
extractMediaTitle,
} from "../src/utils/AttachmentUtils.mjs";
/**
@@ -27,7 +33,7 @@ export const command = new CommandBuilder()
.addTextOption(option =>
option.setName("query")
.setDescription("A search query, URL, or provider-prefixed query like `sp: song name`.", "options.playnext.query")
.setRequired(true)
.setRequired(false)
)
.addChoiceOption(o =>
o.setName("provider")
@@ -50,7 +56,48 @@ export async function run(message, data) {
const p = await this.getPlayer(message, true, true, true);
if (!p) return;
const rawQuery = data.get("query").value;
const attachment = getPlayableAttachment(message);
const rawQuery = data.get("query")?.value?.trim() || "";
/* Handle case where neither a query nor an attachment was supplied */
if (!rawQuery && !attachment) {
const noQueryEmbed = new EmbedBuilder()
.setColor(ERROR_COLOR)
.setAuthor({ name: this.t(message, "responses.play.noQueryTitle") })
.setDescription(this.t(message, "responses.play.noQueryDesc"))
.setFooter({ text: this.t(message, "responses.play.noQueryFooter") });
return message.reply({ embeds: [noQueryEmbed] });
}
/* Handle direct Fluxer user attachment or fluxerusercontent.com URL */
const isAttachment = Boolean(attachment) || isFluxerAttachmentUrl(rawQuery);
if (isAttachment) {
const mediaUrl = attachment ? attachment.url : rawQuery;
const cleanTitle = attachment ? extractMediaTitle(attachment.filename) : extractMediaTitle(rawQuery);
const statusEmbed = new EmbedBuilder()
.setColor(getGlobalColor())
.setAuthor({ name: this.t(message, "responses.playnext.playingNext") })
.setDescription(this.t(message, "responses.play.loadingAttachmentStream"));
let statusMsg = null;
try { statusMsg = await message.reply({ embeds: [statusEmbed] }); } catch (_) {}
const messages = p.playExternal(mediaUrl, cleanTitle, "Fluxer Attachment", true, "attachment");
messages.on("message", d => {
let embed;
if (d instanceof EmbedBuilder) {
embed = d;
} else if (d?.embeds?.[0]) {
embed = d.embeds[0];
} else {
embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(String(d));
}
embed.setAuthor({ name: this.t(message, "responses.playnext.playingNext") });
if (statusMsg) statusMsg.edit({ embeds: [embed] }).catch(() => {});
});
return;
}
const flagProvider = data.get("provider")?.value;
const { provider: inlineProvider, query } = parseInlineProvider(rawQuery);
const provider = inlineProvider ?? flagProvider ?? "ytm";