mirror of
https://github.com/beetbox/beets.git
synced 2026-02-21 14:56:02 +01:00
Move MusicalKey type out of dbcore module
This is library-specific.
This commit is contained in:
parent
394e4e45eb
commit
23d884b6e8
2 changed files with 29 additions and 31 deletions
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
"""Representation of type information for DBCore model fields.
|
||||
"""
|
||||
import re
|
||||
|
||||
from . import query
|
||||
from beets.util import str2bool
|
||||
|
||||
|
|
@ -174,31 +172,3 @@ class Boolean(Type):
|
|||
|
||||
def parse(self, string):
|
||||
return str2bool(string)
|
||||
|
||||
|
||||
class MusicalKey(String):
|
||||
"""String representing the musical key of a song.
|
||||
|
||||
The standard format is C, Cm, C#, C#m, etc.
|
||||
"""
|
||||
|
||||
ENHARMONIC = {
|
||||
r'db': 'c#',
|
||||
r'eb': 'd#',
|
||||
r'gb': 'f#',
|
||||
r'ab': 'g#',
|
||||
r'bb': 'a#',
|
||||
}
|
||||
|
||||
def parse(self, key):
|
||||
key = key.lower()
|
||||
for flat, sharp in self.ENHARMONIC.items():
|
||||
key = re.sub(flat, sharp, key)
|
||||
key = re.sub(r'[\W\s]+minor', 'm', key)
|
||||
return key.capitalize()
|
||||
|
||||
def normalize(self, key):
|
||||
if key is None:
|
||||
return None
|
||||
else:
|
||||
return self.parse(key)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import logging
|
|||
import shlex
|
||||
import unicodedata
|
||||
import time
|
||||
import re
|
||||
from unidecode import unidecode
|
||||
from beets.mediafile import MediaFile, MutagenError
|
||||
from beets import plugins
|
||||
|
|
@ -107,6 +108,33 @@ class PathType(types.Type):
|
|||
return value
|
||||
|
||||
|
||||
class MusicalKey(types.String):
|
||||
"""String representing the musical key of a song.
|
||||
|
||||
The standard format is C, Cm, C#, C#m, etc.
|
||||
"""
|
||||
ENHARMONIC = {
|
||||
r'db': 'c#',
|
||||
r'eb': 'd#',
|
||||
r'gb': 'f#',
|
||||
r'ab': 'g#',
|
||||
r'bb': 'a#',
|
||||
}
|
||||
|
||||
def parse(self, key):
|
||||
key = key.lower()
|
||||
for flat, sharp in self.ENHARMONIC.items():
|
||||
key = re.sub(flat, sharp, key)
|
||||
key = re.sub(r'[\W\s]+minor', 'm', key)
|
||||
return key.capitalize()
|
||||
|
||||
def normalize(self, key):
|
||||
if key is None:
|
||||
return None
|
||||
else:
|
||||
return self.parse(key)
|
||||
|
||||
|
||||
# Special path format key.
|
||||
PF_KEY_DEFAULT = 'default'
|
||||
|
||||
|
|
@ -244,7 +272,7 @@ class Item(LibModel):
|
|||
'original_year': types.PaddedInt(4),
|
||||
'original_month': types.PaddedInt(2),
|
||||
'original_day': types.PaddedInt(2),
|
||||
'initial_key': types.MusicalKey(),
|
||||
'initial_key': MusicalKey(),
|
||||
|
||||
'length': types.Float(),
|
||||
'bitrate': types.ScaledInt(1000, u'kbps'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue