From 84519432f0fbf19dc5be4cb58ac0dc7e2a590f3c Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 14 Sep 2024 10:26:23 +0200 Subject: [PATCH] Try parsing track number from the filename (#1663) --- music_assistant/server/helpers/tags.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- 2.34.1