Skip to content

Commit

Permalink
Use a common function for both tracknumber() and discnumber()
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed Jan 7, 2025
1 parent 1efaaad commit 8cd6ab5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions picard/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,22 @@ def can_link_fingerprint(self):
def load(self, priority=False, refresh=False):
pass

@property
def tracknumber(self):
"""The track number as an int."""
def _track_or_disc_number(self, field):
"""Extract tracknumber or discnumber as int, defaults to 0."""
try:
return int(self.metadata.get('tracknumber', '0').split('/')[0])
return int(self.metadata.get(field, '0').split('/')[0])
except ValueError:
return 0

@property
def tracknumber(self):
"""The track number as an int."""
return self._track_or_disc_number('tracknumber')

@property
def discnumber(self):
"""The disc number as an int."""
try:
return int(self.metadata.get('discnumber', '0').split('/')[0])
except ValueError:
return 0
return self._track_or_disc_number('discnumber')

@property
def errors(self):
Expand Down

0 comments on commit 8cd6ab5

Please sign in to comment.