Skip to content

Commit

Permalink
skip int and float conversion on bad tag values (#110)
Browse files Browse the repository at this point in the history
* skip int and float conversion on bad tag values

* Update release history
  • Loading branch information
geo-martino authored Sep 20, 2024
1 parent e6b2da0 commit 9b936c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/info/release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_


1.1.7
=====

Fixed
-----
* Handle bad values for bpm and compilation in :py:class:`.TagReader` by returning ``None``.

1.1.6
=====

Expand Down
10 changes: 8 additions & 2 deletions musify/libraries/local/track/_tags/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 9b936c7

Please sign in to comment.