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 8, 2025
1 parent 1efaaad commit f7dff4e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions picard/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ def load(self, priority=False, refresh=False):
@property
def tracknumber(self):
"""The track number as an int."""
try:
return int(self.metadata.get('tracknumber', '0').split('/')[0])
except ValueError:
return 0
return self._track_or_disc_number('tracknumber')

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

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

Expand Down

0 comments on commit f7dff4e

Please sign in to comment.