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:
parent
d200040691
commit
98f4d29ac7
9 changed files with 309 additions and 22 deletions
24
src/web/storage/libraryMetadata.js
Normal file
24
src/web/storage/libraryMetadata.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { probeAudioFile } from "../../media/validateAudioFile.js";
|
||||
import { getPermanentLibrary, updatePermanentTracks } from "./storageManager.js";
|
||||
|
||||
// Complète la durée et l'artiste des morceaux ajoutés avant que l'upload ne les relève.
|
||||
// Un fichier illisible est ignoré : il sera retenté au prochain démarrage.
|
||||
async function backfillLibraryMetadata({ probe = probeAudioFile } = {}) {
|
||||
const missing = getPermanentLibrary().filter((entry) => entry.duration == null);
|
||||
const updates = new Map();
|
||||
|
||||
for (const entry of missing) {
|
||||
try {
|
||||
const { duration, artist } = await probe(entry.path);
|
||||
if (duration != null) {
|
||||
updates.set(entry.id, { duration, artist: entry.artist ?? artist });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Unable to read metadata of library entry ${entry.id}`, error.cause ?? error);
|
||||
}
|
||||
}
|
||||
|
||||
return updatePermanentTracks(updates);
|
||||
}
|
||||
|
||||
export { backfillLibraryMetadata };
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue