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.
This commit is contained in:
parent
e5c679a1ee
commit
4361531513
@ -15,6 +15,45 @@ export interface AudioMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AudioMetadataService {
|
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
|
* Extract metadata from audio file buffer
|
||||||
*/
|
*/
|
||||||
@ -32,7 +71,7 @@ export class AudioMetadataService {
|
|||||||
bitrate: metadata.format.bitrate,
|
bitrate: metadata.format.bitrate,
|
||||||
sampleRate: metadata.format.sampleRate,
|
sampleRate: metadata.format.sampleRate,
|
||||||
channels: metadata.format.numberOfChannels,
|
channels: metadata.format.numberOfChannels,
|
||||||
format: metadata.format.container,
|
format: this.mapFormatToDisplayName(metadata.format.container, fileName),
|
||||||
size: fileBuffer.length,
|
size: fileBuffer.length,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -41,7 +80,7 @@ export class AudioMetadataService {
|
|||||||
// Return basic metadata if extraction fails
|
// Return basic metadata if extraction fails
|
||||||
return {
|
return {
|
||||||
title: fileName.replace(/\.[^/.]+$/, ''), // Remove file extension
|
title: fileName.replace(/\.[^/.]+$/, ''), // Remove file extension
|
||||||
format: fileName.split('.').pop()?.toLowerCase(),
|
format: this.mapFormatToDisplayName(fileName.split('.').pop()?.toLowerCase() || '', fileName),
|
||||||
size: fileBuffer.length,
|
size: fileBuffer.length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user