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, }; }