mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-02 17:18:36 +02:00
perf(metadata): avoid SAF copies during quality probes
This commit is contained in:
@@ -3,6 +3,39 @@ import 'package:spotiflac_android/utils/string_utils.dart';
|
||||
|
||||
/// Audio format/quality helpers shared by the download queue and history
|
||||
/// providers.
|
||||
Map<String, dynamic> normalizeScannedAudioMetadata(
|
||||
Map<String, dynamic> metadata,
|
||||
) {
|
||||
dynamic firstValue(String snakeCase, String camelCase) {
|
||||
final snakeValue = metadata[snakeCase];
|
||||
return snakeValue ?? metadata[camelCase];
|
||||
}
|
||||
|
||||
final normalized = <String, dynamic>{...metadata};
|
||||
final metadataFromFilename = metadata['metadataFromFilename'] == true;
|
||||
|
||||
// readAudioMetadata uses the LibraryScanResult contract. Automatic metadata
|
||||
// probes use the same snake_case keys as readFileMetadata so callers can use
|
||||
// the cheaper SAF file-descriptor path without knowing which backend result
|
||||
// shape was returned.
|
||||
if (!metadataFromFilename) {
|
||||
normalized['title'] = firstValue('title', 'trackName');
|
||||
normalized['artist'] = firstValue('artist', 'artistName');
|
||||
normalized['album'] = firstValue('album', 'albumName');
|
||||
}
|
||||
normalized['album_artist'] = firstValue('album_artist', 'albumArtist');
|
||||
normalized['date'] = firstValue('date', 'releaseDate');
|
||||
normalized['track_number'] = firstValue('track_number', 'trackNumber');
|
||||
normalized['total_tracks'] = firstValue('total_tracks', 'totalTracks');
|
||||
normalized['disc_number'] = firstValue('disc_number', 'discNumber');
|
||||
normalized['total_discs'] = firstValue('total_discs', 'totalDiscs');
|
||||
normalized['bit_depth'] = firstValue('bit_depth', 'bitDepth');
|
||||
normalized['sample_rate'] = firstValue('sample_rate', 'sampleRate');
|
||||
normalized['audio_codec'] =
|
||||
firstValue('audio_codec', 'audioCodec') ?? metadata['format'];
|
||||
return normalized;
|
||||
}
|
||||
|
||||
int? readPositiveBitrateKbps(dynamic value) {
|
||||
final parsed = readPositiveInt(value);
|
||||
if (parsed == null) return null;
|
||||
|
||||
Reference in New Issue
Block a user