From 1edd3657ba0303aef512e61c701ff67a16f6eaaf Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Sat, 15 May 2021 16:40:29 +0000 Subject: [PATCH] Introduce %M, %N template variables - %M: total number of discs in the chosen release - %N: number of current disc Signed-off-by: JoeLametta --- man/whipper-cd-rip.rst | 2 ++ whipper/command/cd.py | 2 ++ whipper/common/common.py | 4 ++-- whipper/common/mbngs.py | 13 ++++++++++--- whipper/common/program.py | 4 ++++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/man/whipper-cd-rip.rst b/man/whipper-cd-rip.rst index b4706db..01319e2 100644 --- a/man/whipper-cd-rip.rst +++ b/man/whipper-cd-rip.rst @@ -100,6 +100,8 @@ Template schemes | - %d: release title (with disambiguation) | - %D: disc title (without disambiguation) | - %I: MusicBrainz Disc ID +| - %M: total number of discs in the chosen release +| - %N: number of current disc | - %T: medium title | - %y: release year | - %r: release type, lowercase diff --git a/whipper/command/cd.py b/whipper/command/cd.py index f6bc2d6..68b6d42 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -60,6 +60,8 @@ disc and track template are: - %d: release title (with disambiguation) - %D: disc title (without disambiguation) - %I: MusicBrainz Disc ID + - %M: total number of discs in the chosen release + - %N: number of current disc - %T: medium title - %y: release year - %r: release type, lowercase diff --git a/whipper/common/common.py b/whipper/common/common.py index 21a5f3c..bdbb9ac 100644 --- a/whipper/common/common.py +++ b/whipper/common/common.py @@ -277,9 +277,9 @@ def getRelativePath(targetPath, collectionPath): def validate_template(template, kind): """Raise exception if disc/track template includes invalid variables.""" if kind == 'disc': - matches = re.findall(r'%[^ABCDIRSTXcdrxy]', template) + matches = re.findall(r'%[^ABCDIMNRSTXcdrxy]', template) elif kind == 'track': - matches = re.findall(r'%[^ABCDIRSTXacdnrstxy]', template) + matches = re.findall(r'%[^ABCDIMNRSTXacdnrstxy]', template) if '%' in template and matches: raise ValueError(kind + ' template string contains invalid ' 'variable(s): {}'.format(', '.join(matches))) diff --git a/whipper/common/mbngs.py b/whipper/common/mbngs.py index 0a35f82..c6a2aaa 100644 --- a/whipper/common/mbngs.py +++ b/whipper/common/mbngs.py @@ -77,6 +77,10 @@ class DiscMetadata: :vartype tracks: list of :any:`TrackMetadata` :cvar countries: MusicBrainz release countries :vartype countries: list or None + :cvar discNumber: number of current disc + :vartype discNumber: int or None + :cvar discTotal: total number of discs in the chosen release + :vartype discTotal: int or None :cvar catalogNumber: release catalog number :vartype catalogNumber: str or None :cvar barcode: release barcode @@ -102,6 +106,8 @@ class DiscMetadata: catalogNumber = None barcode = None countries = None + discNumber = None + discTotal = None mediumTitle = None def __init__(self): @@ -298,10 +304,11 @@ def _getMetadata(release, discid=None, country=None): if 'disambiguation' in release: discMD.releaseDisambCmt = release['disambiguation'] releaseTitle += " (%s)" % release['disambiguation'] - count = len(release['medium-list']) - if count > 1: + discMD.discNumber = int(medium['position']) + discMD.discTotal = len(release['medium-list']) + if discMD.discTotal > 1: releaseTitle += ' (Disc %d of %d)' % ( - int(medium['position']), count) + discMD.discNumber, discMD.discTotal) if 'title' in medium: discMD.mediumTitle = medium['title'] releaseTitle += ": %s" % medium['title'] diff --git a/whipper/common/program.py b/whipper/common/program.py index 3015162..3cc49e6 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -182,6 +182,8 @@ class Program: * ``%d``: release title (with disambiguation) * ``%D``: disc title (without disambiguation) * ``%I``: MusicBrainz Disc ID + * ``%M``: total number of discs in the chosen release + * ``%N``: number of current disc * ``%T``: medium title * ``%y``: release year * ``%r``: release type, lowercase @@ -219,6 +221,8 @@ class Program: v['B'] = metadata.barcode v['C'] = metadata.catalogNumber v['c'] = metadata.releaseDisambCmt + v['M'] = metadata.discTotal + v['N'] = metadata.discNumber v['T'] = metadata.mediumTitle if metadata.releaseType: v['R'] = metadata.releaseType