Encode jukebox audio with native ffmpeg, normalise loudness, read metadata

- Play every track through an ffmpeg process that normalises loudness
  (EBU R128) and outputs Ogg Opus, handed to Discord as is: no more Opus
  encoding in JavaScript with opusscript. Measured at over 40x real time,
  about 2% of a core while playing. Closing the stream kills ffmpeg.
- Encoding at upload instead was ruled out: over two minutes for an 85-minute
  mix, during which the upload would hang.
- Read duration, title and artist with ffprobe at upload; default the title
  to "Artist - Title" or the file name without extension.
- Fill the duration of existing library entries at startup.
- Expose the position of the current track in queue snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-29 12:10:49 +01:00
parent d200040691
commit 98f4d29ac7
9 changed files with 309 additions and 22 deletions

View file

@ -87,7 +87,13 @@ function writeLibrary(entries) {
function registerUploadedFile(
file,
{ permanent, uploader = "unknown", title = file.originalname }
{
permanent,
uploader = "unknown",
title = file.originalname,
duration = null,
artist = null,
}
) {
ensureStorageLayout();
const createdAt = new Date().toISOString();
@ -120,6 +126,8 @@ function registerUploadedFile(
path: finalPath,
size: file.size,
mimetype: file.mimetype,
duration,
artist,
uploader,
createdAt,
};
@ -135,6 +143,8 @@ function registerUploadedFile(
storedName,
size: file.size,
mimetype: file.mimetype,
duration,
artist,
permanent,
uploader,
libraryTrackId: permanentEntry ? permanentEntry.id : null,
@ -164,6 +174,8 @@ function createQueueTrackFromLibrary(libraryTrack, requestedBy = "library") {
storedName: libraryTrack.storedName,
size: libraryTrack.size,
mimetype: libraryTrack.mimetype,
duration: libraryTrack.duration ?? null,
artist: libraryTrack.artist ?? null,
permanent: true,
uploader: requestedBy,
libraryTrackId: libraryTrack.id,
@ -211,6 +223,24 @@ function discardUploadedFile(file) {
deleteFileSafe(file?.path);
}
// Modifie des champs d'entrées de la bibliothèque : updates est une Map id → champs.
// Relit le fichier juste avant d'écrire, pour ne pas écraser un ajout fait entre-temps.
function updatePermanentTracks(updates) {
const library = getPermanentLibrary();
const updated = [];
for (const entry of library) {
const fields = updates.get(entry.id);
if (fields) {
Object.assign(entry, fields);
updated.push(entry);
}
}
if (updated.length > 0) {
writeLibrary(library);
}
return updated;
}
function deletePermanentTrack(id) {
const library = getPermanentLibrary();
const index = library.findIndex((entry) => entry.id === id);
@ -252,6 +282,7 @@ export {
cleanupTemporaryFiles,
discardUploadedFile,
deletePermanentTrack,
updatePermanentTracks,
handleTrackCompletion,
deleteTrackFile,
};