mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-02 17:18:36 +02:00
feat(library): highlight high-bitrate quality badges
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const highQualityBadgeBitrateThresholdKbps = 900;
|
||||
|
||||
/// Preserves the highlighted color used by legacy 24-bit Library badges while
|
||||
/// also supporting newer labels that display a measured bitrate instead.
|
||||
bool shouldHighlightAudioQualityBadge(String quality) {
|
||||
final normalized = quality.trim().toLowerCase();
|
||||
if (RegExp(r'\b24(?:\s*[- ]?\s*bit|/)').hasMatch(normalized)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final kbpsMatch = RegExp(
|
||||
r'\b(\d+(?:\.\d+)?)\s*k(?:bps)?\b',
|
||||
).firstMatch(normalized);
|
||||
final kbps = double.tryParse(kbpsMatch?.group(1) ?? '');
|
||||
if (kbps != null) {
|
||||
return kbps > highQualityBadgeBitrateThresholdKbps;
|
||||
}
|
||||
|
||||
final mbpsMatch = RegExp(
|
||||
r'\b(\d+(?:\.\d+)?)\s*mbps\b',
|
||||
).firstMatch(normalized);
|
||||
final mbps = double.tryParse(mbpsMatch?.group(1) ?? '');
|
||||
return mbps != null && mbps * 1000 > highQualityBadgeBitrateThresholdKbps;
|
||||
}
|
||||
Reference in New Issue
Block a user