diff --git a/beets/library.py b/beets/library.py index dc37b809d..bdba6cb37 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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]] diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 6f67aad4b..f2b807825 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -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 diff --git a/docs/changelog.rst b/docs/changelog.rst index 66b9547bd..37e043b3e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 diff --git a/docs/reference/pathformat.rst b/docs/reference/pathformat.rst index 77a482086..471c982ad 100644 --- a/docs/reference/pathformat.rst +++ b/docs/reference/pathformat.rst @@ -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: diff --git a/test/rsrc/test.blb b/test/rsrc/test.blb index cd53d014e..f71d6ec2c 100644 Binary files a/test/rsrc/test.blb and b/test/rsrc/test.blb differ diff --git a/test/test_db.py b/test/test_db.py index 8a1b29ab9..2500d9f02 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -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'