Skip to content

Commit

Permalink
Try parsing track number from the filename (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Sep 14, 2024
1 parent 495b794 commit 8451943
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions music_assistant/server/helpers/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ def track(self) -> int | None:
"""Return track tag if present."""
if tag := self.tags.get("track"):
return try_parse_int(tag.split("/")[0], None)
# fallback to parsing from filename (if present)
# this can be in the form of 01 - title.mp3
# or 01-title.mp3
# or 01.title.mp3
# or 01 title.mp3
# or 1. title.mp3
for splitpos in (4, 3, 2, 1):
firstpart = self.filename[:splitpos]
if firstpart.isnumeric():
return try_parse_int(firstpart, None)
return None

@property
Expand Down

0 comments on commit 8451943

Please sign in to comment.