From f236d72a19f91c5c1aa76831ad06d27f57ab653e Mon Sep 17 00:00:00 2001 From: zarzet Date: Fri, 26 Jun 2026 19:06:04 +0700 Subject: [PATCH] fix(download): detect actual output format from audio codec on fallback When a fallback provider returns a non-FLAC container (e.g. YouTube Opus) and neither an explicit extension field nor a recognizable path suffix is available (such as SAF content URIs), infer the output extension from the backend-probed audio codec. Prevents Opus/MP3/AAC downloads from being mislabeled and embedded as FLAC, which left metadata empty. --- lib/providers/download_queue_provider.dart | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/providers/download_queue_provider.dart b/lib/providers/download_queue_provider.dart index 7a684e2e..05e234b4 100644 --- a/lib/providers/download_queue_provider.dart +++ b/lib/providers/download_queue_provider.dart @@ -3331,6 +3331,29 @@ class DownloadQueueNotifier extends Notifier { if (lower.endsWith(ext)) return ext; } } + + // Generic safety net: when neither an explicit extension field nor a + // recognizable path suffix is available (e.g. SAF content URIs that drop + // the suffix), fall back to the actual audio codec reported by the backend + // probe. This keeps any extension that returns a non-FLAC container (Opus, + // MP3, AAC) from being mislabeled as FLAC. + final codec = _normalizeAudioFormatValue( + result['audio_codec']?.toString() ?? + result['actual_audio_codec']?.toString() ?? + result['format']?.toString(), + ); + switch (codec) { + case 'opus': + return '.opus'; + case 'mp3': + return '.mp3'; + case 'aac': + case 'alac': + case 'm4a': + return '.m4a'; + case 'flac': + return '.flac'; + } return null; }