commit 04971eaf33ca8504a601ff96fda6e83c6180d39b
parent 3f655faddf6a1c6c7b0ad4d1f876195191c4509a
Author: gearsix <gearsix@tuta.io>
Date:   Thu,  1 Dec 2022 20:30:38 +0000
Track numbers in a track title are now trimmed; named all regex's
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sya.py b/sya.py
@@ -9,6 +9,8 @@ import sys
 
 Version = 'v1.0.1'
 
+UnsafeFilenameChars = re.compile('[/\\?%*:|\"<>\x7F\x00-\x1F]')
+TrackNum = re.compile('(?:\d+.? ?-? ?)')
 Timestamp = re.compile('(?:[\t ]+?)?[\[\(]+?((\d+[:.])+(\d+))[\]\)]?(?:[\t ]+)?')
 
 class TracklistItem:
@@ -75,8 +77,9 @@ def parse_tracks(tracklist):
         if timestamp == None:
             print('line {}, missing timestamp: "{}"'.format(lcount, line))
         
-        title = ' '.join(sline).strip(' ')
-        title = re.sub(r"[/\\?%*:|\"<>\x7F\x00-\x1F]", '', title)
+        line = ' '.join(sline)
+        line = re.sub(TrackNum, '', line)
+        title = re.sub(UnsafeFilenameChars, '', line)
         
         tracks.append(TracklistItem(timestamp, title))
     return tracks