-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
standardise_performers.py
76 lines (68 loc) · 2.87 KB
/
standardise_performers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
PLUGIN_NAME = 'Standardise Performers'
PLUGIN_AUTHOR = 'Sophist'
PLUGIN_DESCRIPTION = '''Splits multi-instrument performer tags into single
instruments and combines names so e.g. (from 10cc by 10cc track 1):
<pre>
Performer [acoustic guitar, bass, dobro, electric guitar and tambourine]: Graham Gouldman
Performer [acoustic guitar, electric guitar, grand piano and synthesizer]: Lol Creme
Performer [electric guitar, moog and slide guitar]: Eric Stewart
</pre>
becomes:
<pre>
Performer [acoustic guitar]: Graham Gouldman; Lol Creme
Performer [bass]: Graham Gouldman
Performer [dobro]: Graham Gouldman
Performer [electric guitar]: Eric Stewart; Graham Gouldman; Lol Creme
Performer [grand piano]: Lol Creme
Performer [moog]: Eric Stewart
Performer [slide guitar]: Eric Stewart
Performer [synthesizer]: Lol Creme
Performer [tambourine]: Graham Gouldman
</pre>
Update: This version now sorts the performer tags in order to maintain a consistent value and avoid tags appearing to change even though the base data is equivalent.
'''
PLUGIN_VERSION = '1.0'
PLUGIN_API_VERSIONS = ["2.0"]
PLUGIN_LICENSE = "GPL-2.0"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.html"
import re
from picard import log
from picard.metadata import register_track_metadata_processor
standardise_performers_split = re.compile(r", | and ").split
def standardise_performers(album, metadata, *args):
for key, values in list(metadata.rawitems()):
if not key.startswith('performer:') \
and not key.startswith('~performersort:'):
continue
mainkey, subkey = key.split(':', 1)
if not subkey:
continue
instruments = standardise_performers_split(subkey)
if len(instruments) == 1:
continue
log.debug("%s: Splitting Performer [%s] into separate performers",
PLUGIN_NAME,
subkey,
)
prefixes = []
words = instruments[0].split()
for word in words[:]:
if not word in ['guest', 'solo', 'additional', 'minor']:
break
prefixes.append(word)
words.remove(word)
instruments[0] = " ".join(words)
prefix = " ".join(prefixes) + " " if prefixes else ""
for instrument in instruments:
newkey = '%s:%s%s' % (mainkey, prefix, instrument)
for value in values:
metadata.add_unique(newkey, value)
del metadata[key]
# Sort performer metdata to avoid changes in processing sequence creating false changes in metadata
for key, values in list(metadata.rawitems()):
if key.startswith('performer:') or key.startswith('~performersort:'):
metadata[key] = sorted(values)
from picard.plugin import PluginPriority
register_track_metadata_processor(standardise_performers,
priority=PluginPriority.HIGH)