From 43615315137db12768fd7f7ade3b7fef7b33c0ed Mon Sep 17 00:00:00 2001 From: Geert Rademakes Date: Wed, 6 Aug 2025 15:15:28 +0200 Subject: [PATCH] fix: Map audio format names to user-friendly display names - Add mapFormatToDisplayName function to convert container formats to display names - Map 'MPEG' container format to 'MP3' for better user experience - Map other common formats: WAVE->WAV, FLAC->FLAC, AAC->AAC, etc. - Fallback to file extension if container format not recognized - Apply format mapping in both successful and error cases - Ensure consistent format display across the application Now MP3 files will display as 'MP3' instead of 'MPEG' in the UI. --- .../src/services/audioMetadataService.ts | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/services/audioMetadataService.ts b/packages/backend/src/services/audioMetadataService.ts index 55c3c5f..cf11694 100644 --- a/packages/backend/src/services/audioMetadataService.ts +++ b/packages/backend/src/services/audioMetadataService.ts @@ -15,6 +15,45 @@ export interface AudioMetadata { } export class AudioMetadataService { + /** + * Map container format to user-friendly format name + */ + private mapFormatToDisplayName(container: string, fileName: string): string { + // Map common container formats to display names + const formatMap: { [key: string]: string } = { + 'MPEG': 'MP3', + 'mp3': 'MP3', + 'WAVE': 'WAV', + 'wav': 'WAV', + 'FLAC': 'FLAC', + 'flac': 'FLAC', + 'AAC': 'AAC', + 'aac': 'AAC', + 'OGG': 'OGG', + 'ogg': 'OGG', + 'M4A': 'M4A', + 'm4a': 'M4A', + 'WMA': 'WMA', + 'wma': 'WMA', + 'OPUS': 'OPUS', + 'opus': 'OPUS', + }; + + // Try to map the container format + if (formatMap[container]) { + return formatMap[container]; + } + + // Fallback to file extension if container format is not recognized + const extension = fileName.split('.').pop()?.toLowerCase(); + if (extension && formatMap[extension]) { + return formatMap[extension]; + } + + // Return the original container format if no mapping found + return container.toUpperCase(); + } + /** * Extract metadata from audio file buffer */ @@ -32,7 +71,7 @@ export class AudioMetadataService { bitrate: metadata.format.bitrate, sampleRate: metadata.format.sampleRate, channels: metadata.format.numberOfChannels, - format: metadata.format.container, + format: this.mapFormatToDisplayName(metadata.format.container, fileName), size: fileBuffer.length, }; } catch (error) { @@ -41,7 +80,7 @@ export class AudioMetadataService { // Return basic metadata if extraction fails return { title: fileName.replace(/\.[^/.]+$/, ''), // Remove file extension - format: fileName.split('.').pop()?.toLowerCase(), + format: this.mapFormatToDisplayName(fileName.split('.').pop()?.toLowerCase() || '', fileName), size: fileBuffer.length, }; }