Introduce %M, %N template variables

- %M: total number of discs in the chosen release
- %N: number of current disc

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
This commit is contained in:
JoeLametta
2021-05-15 16:40:29 +00:00
parent 76b8004b8f
commit 1edd3657ba
5 changed files with 20 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)))

View File

@@ -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']

View File

@@ -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