diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 263ff5671..bc19c1620 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -317,7 +317,11 @@ def sanitize_for_path(value, pathmod, key=None): if sep: value = value.replace(sep, u'_') elif key in ('track', 'tracktotal', 'disc', 'disctotal'): - # pad with zeros + # Pad indices with zeros. + value = u'%02i' % value + elif key == 'year': + value = u'%04i' % value + elif key in ('month', 'day'): value = u'%02i' % value elif key == 'bitrate': # Bitrate gets formatted as kbps. diff --git a/docs/changelog.rst b/docs/changelog.rst index 47c997550..b07307bf0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,6 +24,8 @@ This release focuses on making beets' path formatting vastly more powerful. files (when tag-writing is enabled). * Add a message when skipping directories during an incremental import. * Ignore FUSE's shadow files when importing. +* Date values in path formats (``$year``, ``$month``, and ``$day``) are now + appropriately zero-padded. * Removed the ``--path-format`` global flag for ``beet``. * Removed the ``lastid`` plugin, which was deprecated in the previous version. diff --git a/test/test_db.py b/test/test_db.py index 68eaf9175..e40ad5283 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -165,15 +165,23 @@ class DestinationTest(unittest.TestCase): def test_destination_pads_some_indices(self): self.lib.directory = 'base' self.lib.path_formats = {'default': '$track $tracktotal ' \ - '$disc $disctotal $bpm $year'} + '$disc $disctotal $bpm'} self.i.track = 1 self.i.tracktotal = 2 self.i.disc = 3 self.i.disctotal = 4 self.i.bpm = 5 - self.i.year = 6 self.assertEqual(self.lib.destination(self.i), - np('base/01 02 03 04 5 6')) + np('base/01 02 03 04 5')) + + def test_destination_pads_date_values(self): + self.lib.directory = 'base' + self.lib.path_formats = {'default': '$year-$month-$day'} + self.i.year = 1 + self.i.month = 2 + self.i.day = 3 + self.assertEqual(self.lib.destination(self.i), + np('base/0001-02-03')) def test_destination_escapes_slashes(self): self.i.album = 'one/two'