add new audio properties to library/DB

$samplerate now expands to "##kHz" in path formats.
This commit is contained in:
Adrian Sampson 2012-01-27 16:04:51 -08:00
parent 9987ab47fd
commit fe33926038
6 changed files with 20 additions and 4 deletions

View file

@ -68,6 +68,9 @@ ITEM_FIELDS = [
('length', 'real', False, True),
('bitrate', 'int', False, True),
('format', 'text', False, True),
('samplerate', 'int', False, True),
('bitdepth', 'int', False, True),
('channels', 'int', False, True),
('mtime', 'int', False, False),
]
ITEM_KEYS_WRITABLE = [f[0] for f in ITEM_FIELDS if f[3] and f[2]]

View file

@ -328,7 +328,10 @@ def sanitize_for_path(value, pathmod, key=None):
value = u'%02i' % value
elif key == 'bitrate':
# Bitrate gets formatted as kbps.
value = u'%ikbps' % (value / 1000)
value = u'%ikbps' % ((value or 0) / 1000)
elif key == 'samplerate':
# Sample rate formatted as kHz.
value = u'%ikHz' % ((value or 0) / 1000)
else:
value = unicode(value)
return value

View file

@ -6,6 +6,9 @@ Changelog
* The :doc:`/plugins/lyrics`, originally by `Peter Brunner`_, is revamped and
included with beets, making it easy to fetch **song lyrics**.
* Items now expose their audio sample rate, number of channels, and bits per
sample (bitdepth). See :doc:`/reference/pathformat` for a list of all
available audio properties. Thanks to Andrew Dunn.
* The autotagger now tolerates tracks on multi-disc albums that are numbered
per-disc. For example, if track 24 on a release is the first track on the
second disc, then it is not penalized for having its track number set to 1

View file

@ -139,9 +139,12 @@ Ordinary metadata:
Audio information:
* length
* bitrate
* format
* length (in seconds)
* bitrate (in kilobits per second, with units: e.g., "192kbps")
* format (e.g., "MP3" or "FLAC")
* channels
* bitdepth (only available for some formats)
* samplerate (in kilohertz, with units: e.g., "48kHz")
MusicBrainz IDs:

Binary file not shown.

View file

@ -348,6 +348,10 @@ class DestinationTest(unittest.TestCase):
val = util.sanitize_for_path(12345, posixpath, 'bitrate')
self.assertEqual(val, u'12kbps')
def test_component_sanitize_uses_khz_samplerate(self):
val = util.sanitize_for_path(12345, posixpath, 'samplerate')
self.assertEqual(val, u'12kHz')
def test_artist_falls_back_to_albumartist(self):
self.i.artist = ''
self.i.albumartist = 'something'