Skip to content

Commit

Permalink
Merge branch 'workandmovement-fixes' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Sep 29, 2021
2 parents 642698a + 53ff572 commit ed7ce62
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions plugins/workandmovement/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018-2019 Philipp Wolfer
# Copyright (C) 2018-2019, 2021 Philipp Wolfer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -20,8 +20,8 @@
PLUGIN_NAME = 'Work & Movement'
PLUGIN_AUTHOR = 'Philipp Wolfer'
PLUGIN_DESCRIPTION = 'Set work and movement based on work relationships'
PLUGIN_VERSION = '1.0.1'
PLUGIN_API_VERSIONS = ['2.1', '2.2']
PLUGIN_VERSION = '1.0.2'
PLUGIN_API_VERSIONS = ['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7']
PLUGIN_LICENSE = 'GPL-2.0-or-later'
PLUGIN_LICENSE_URL = 'https://www.gnu.org/licenses/gpl-2.0.html'

Expand All @@ -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 All @@ -170,7 +172,7 @@ def parse_work(work_rel):
if is_parent_work(rel):
if is_movement_like(rel):
work.is_movement = True
work.part_number = rel['ordering-key']
work.part_number = rel.get('ordering-key')
if 'work' in rel:
work.parent = parse_work(rel['work'])
work.parent.is_work = True
Expand Down

0 comments on commit ed7ce62

Please sign in to comment.