From fe339260381f772058ef8363438d5549fb2a3254 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 27 Jan 2012 16:04:51 -0800 Subject: [PATCH] add new audio properties to library/DB $samplerate now expands to "##kHz" in path formats. --- beets/library.py | 3 +++ beets/util/__init__.py | 5 ++++- docs/changelog.rst | 3 +++ docs/reference/pathformat.rst | 9 ++++++--- test/rsrc/test.blb | Bin 7168 -> 7168 bytes test/test_db.py | 4 ++++ 6 files changed, 20 insertions(+), 4 deletions(-) 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 cd53d014ef1a5c5d27b62e559adad597e4376e94..f71d6ec2cc0f58befdd2745ad3390c0e5b2546c8 100644 GIT binary patch delta 110 zcmZp$Xt0_sl%#7^f;^K_$ zshd?8&ogT1C?sbj=H;d46f0!rmFOrGC*~I9q!uNXq(b;fnI$Qy1tl4q-!lnH0sshF B9PR)B delta 69 zcmZp$Xt0