From: Marcel van der Veldt Date: Sat, 14 Sep 2024 08:26:23 +0000 (+0200) Subject: Try parsing track number from the filename (#1663) X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=84519432f0fbf19dc5be4cb58ac0dc7e2a590f3c;p=music-assistant-server.git Try parsing track number from the filename (#1663) --- diff --git a/music_assistant/server/helpers/tags.py b/music_assistant/server/helpers/tags.py index f0014b17..c60ea526 100644 --- a/music_assistant/server/helpers/tags.py +++ b/music_assistant/server/helpers/tags.py @@ -180,6 +180,16 @@ class AudioTags: """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