Skip to content

Commit

Permalink
workandmovement: Strip separating chars like comma from start of move…
Browse files Browse the repository at this point in the history
…ment title
  • Loading branch information
phw committed Sep 29, 2021
1 parent d3c6b95 commit 53ff572
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugins/workandmovement/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
from picard.metadata import register_track_metadata_processor


_re_work_title = re.compile(r'(?P<work>.*):\s+(?P<movementnumber>[IVXLCDM]+)\.\s+(?P<movement>.*)')
_re_part_number = re.compile(r'(?P<number>[0-9IVXLCDM]+)\.?\s+')
_re_work_title = re.compile(r'(?P<work>.*):\s+(?P<movementnumber>[IVXLCDM]+)\.\s[\s,:;./]*(?P<movement>.*)')
_re_part_number = re.compile(r'(?P<number>[0-9IVXLCDM]+)\.?\s[\s,:;./]*')
_re_separators = re.compile(r'^[\s,:;./-]+')


class Work:
Expand Down Expand Up @@ -147,14 +148,15 @@ def normalize_movement_title(work):
if work.parent:
work_title = work.parent.title
if movement_title.startswith(work_title):
movement_title = movement_title[len(work_title):].lstrip(':').strip()
movement_title = movement_title[len(work_title):]
movement_title = _re_separators.sub('', movement_title)
match = _re_part_number.match(movement_title)
if match:
# Only remove the number if it matches the part_number
try:
number = number_to_int(match.group('number'))
if number == work.part_number:
movement_title = _re_part_number.sub("", movement_title)
movement_title = _re_part_number.sub('', movement_title)
except ValueError as e:
log.warning(e)
return movement_title
Expand Down

0 comments on commit 53ff572

Please sign in to comment.