From fb081107973995c66a41ff4a6345ee832950c3ed Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Wed, 30 Sep 2026 20:58:18 +0700 Subject: [PATCH] fix(download): verify ReplayGain tags independently of metadata embedding --- .../com/zarz/spotiflac/NativeDownloadFinalizer.kt | 3 ++- lib/providers/download_queue_provider_embedding.dart | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/kotlin/com/zarz/spotiflac/NativeDownloadFinalizer.kt b/android/app/src/main/kotlin/com/zarz/spotiflac/NativeDownloadFinalizer.kt index 6182e0b3..55b042e8 100644 --- a/android/app/src/main/kotlin/com/zarz/spotiflac/NativeDownloadFinalizer.kt +++ b/android/app/src/main/kotlin/com/zarz/spotiflac/NativeDownloadFinalizer.kt @@ -922,7 +922,8 @@ object NativeDownloadFinalizer { } val deleteScanPath = scanPath != state.filePath val scan = try { - scanReplayGain(scanPath, shouldCancel) ?: return null + scanReplayGain(scanPath, shouldCancel) + ?: throw IllegalStateException("ReplayGain analysis produced no valid measurement") } finally { if (deleteScanPath) File(scanPath).delete() } diff --git a/lib/providers/download_queue_provider_embedding.dart b/lib/providers/download_queue_provider_embedding.dart index 80739e3d..da45e31f 100644 --- a/lib/providers/download_queue_provider_embedding.dart +++ b/lib/providers/download_queue_provider_embedding.dart @@ -453,6 +453,10 @@ extension _DownloadQueueEmbedding on DownloadQueueNotifier { _log.d( 'Metadata embedding disabled, skipping $format metadata/cover embed', ); + if (settings.embedReplayGain) { + final rg = await ReplayGainService.scanAndApplyToFile(filePath); + if (rg != null) _storeTrackReplayGainForAlbum(track, filePath, rg); + } return null; } @@ -827,12 +831,10 @@ extension _DownloadQueueEmbedding on DownloadQueueNotifier { if (settings.embedReplayGain) { try { - final rgResult = await FFmpegService.scanReplayGain(filePath); + final rgResult = await ReplayGainService.scanAndApplyToFile( + filePath, + ); if (rgResult != null) { - await PlatformBridge.editFileMetadata(filePath, { - 'replaygain_track_gain': rgResult.trackGain, - 'replaygain_track_peak': rgResult.trackPeak, - }); _log.d( 'ReplayGain for $format: gain=${rgResult.trackGain}, peak=${rgResult.trackPeak}', );