From a58da3f5d3f503f035e014d627450ba494f052d1 Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Sun, 1 Nov 2026 18:14:03 -0700 Subject: [PATCH] fix(music): stop reading a kb/s bitrate as a hi-res sample rate A lossy label such as "256 kb/s AAC" or "MP3 320 kb/s" no longer gets the per-track Hi-Res badge. --- tests/core/test_music_renderer.py | 22 ++++++++++++++++++++++ unshackle/core/music/renderer.py | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/core/test_music_renderer.py diff --git a/tests/core/test_music_renderer.py b/tests/core/test_music_renderer.py new file mode 100644 index 00000000..5ca17abf --- /dev/null +++ b/tests/core/test_music_renderer.py @@ -0,0 +1,22 @@ +import pytest + +from unshackle.core.music.renderer import MusicRenderer + + +@pytest.mark.parametrize( + ("label", "hires"), + [ + ("FLAC 24-bit/96kHz", True), + ("24-bit / 96 kHz", True), + ("FLAC 16-bit/88.2kHz", True), + ("96k", True), + ("FLAC 16-bit/44.1kHz", False), + ("Lossless", False), + ("256 kb/s AAC", False), + ("MP3 320 kb/s", False), + ("320kbps", False), + ("AAC 96 kbit/s", False), + ], +) +def test_is_hires_quality_reads_sample_rate_not_bitrate(label: str, hires: bool) -> None: + assert MusicRenderer.is_hires_quality(label) is hires diff --git a/unshackle/core/music/renderer.py b/unshackle/core/music/renderer.py index c40ed176..a0349da5 100644 --- a/unshackle/core/music/renderer.py +++ b/unshackle/core/music/renderer.py @@ -285,6 +285,7 @@ class MusicRenderer: @staticmethod def is_hires_quality(value: str) -> bool: + """Return True for a label above 16-bit or 48 kHz; a "k" before "b" is a bitrate ("256 kb/s"), not a rate.""" lowered = value.lower() bit_depth = None sample_rate = None @@ -293,7 +294,7 @@ class MusicRenderer: if bit_match: bit_depth = int(bit_match.group("bits")) - sample_match = re.search(r"(?P\d+(?:\.\d+)?)\s*k(?:hz)?", lowered) + sample_match = re.search(r"(?P\d+(?:\.\d+)?)\s*k(?!b)(?:hz)?", lowered) if sample_match: sample_rate = float(sample_match.group("rate"))