From 9b936c7f0d1989d579af95379789c8f564ef7622 Mon Sep 17 00:00:00 2001 From: George <41969151+geo-martino@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:51:05 -0400 Subject: [PATCH] skip int and float conversion on bad tag values (#110) * skip int and float conversion on bad tag values * Update release history --- docs/info/release-history.rst | 7 +++++++ musify/libraries/local/track/_tags/reader.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/info/release-history.rst b/docs/info/release-history.rst index 0cfe9613..18fed4a5 100644 --- a/docs/info/release-history.rst +++ b/docs/info/release-history.rst @@ -32,6 +32,13 @@ The format is based on `Keep a Changelog `_, and this project adheres to `Semantic Versioning `_ +1.1.7 +===== + +Fixed +----- +* Handle bad values for bpm and compilation in :py:class:`.TagReader` by returning ``None``. + 1.1.6 ===== diff --git a/musify/libraries/local/track/_tags/reader.py b/musify/libraries/local/track/_tags/reader.py index b069b547..5db48076 100644 --- a/musify/libraries/local/track/_tags/reader.py +++ b/musify/libraries/local/track/_tags/reader.py @@ -131,7 +131,10 @@ def read_date(self) -> tuple[int | None, int | None, int | None] | None: def read_bpm(self) -> float | None: """Extract BPM tags from file""" values = self.read_tag(self.tag_map.bpm) - return float(values[0]) if values is not None else None + try: + return float(values[0]) if values is not None else None + except ValueError: + return None def read_key(self) -> str | None: """Extract key tags from file""" @@ -159,7 +162,10 @@ def read_disc_total(self) -> int | None: def read_compilation(self) -> bool | None: """Extract compilation tags from file""" values = self.read_tag(self.tag_map.compilation) - return bool(int(values[0])) if values is not None else None + try: + return bool(int(values[0])) if values is not None else None + except ValueError: + return None def read_comments(self) -> list[str] | None: """Extract comment tags from file"""