commit d2d115933cb2431ad0ac9ec37f9fb0a6f2d0cc1f
parent eb8778f263793b5c104f8a49509227ec5e58a6d5
Author: gearsix <gearsix@tuta.io>
Date: Fri, 29 Mar 2024 13:14:06 +0000
small improvements to sya.py#parse_tracks
- Added (brief) documentation
- empty lines get skipped
- timestamps are prepended with 0 if missing (xx:xx:xx, not x:xx:xx)
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/sya.py b/src/sya.py
@@ -64,10 +64,19 @@ def load_tracklist(path):
return url, tracklist
def parse_tracks(tracklist):
+ '''
+ This function parses each line of tracklist and
+ matches it against the `Timestamp` regex.
+ There is a heuristic check against timestamps on
+ the right and left of lines (some track names may
+ have timestamp-looking elements).
+ '''
tracks = []
weightR = 0 # num. timestamps on right-side
weightL = 0 # num. timestamps on left-side
for lcount, line in enumerate(tracklist):
+ if len(line.strip(' ')) == 0:
+ continue
sline = line.split(' ')
timestamp = None
@@ -84,6 +93,8 @@ def parse_tracks(tracklist):
sline.remove(l)
if timestamp == None:
print('line {}, missing timestamp: "{}"'.format(lcount, line))
+ elif timestamp[0] != '0' and timestamp[1] == ':':
+ timestamp = '0' + timestamp
line = ' '.join(sline)
line = re.sub(TrackNum, '', line)