From 244ffd71e2ea6be44d9b029964c9ad80f14097db Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 14 Oct 2012 20:27:13 -0700 Subject: [PATCH] fix "beet modify" for date fields (GC-449) This is fixed by allowing MediaFiles to convert strings to integers on assignment. An eventual complete fix will perform these type conversions in the Item interface. --- beets/mediafile.py | 2 +- beets/util/__init__.py | 2 +- docs/changelog.rst | 2 ++ docs/reference/cli.rst | 2 ++ test/test_mediafile.py | 9 +++++++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/beets/mediafile.py b/beets/mediafile.py index 48b212b83..b5e0acce2 100644 --- a/beets/mediafile.py +++ b/beets/mediafile.py @@ -255,7 +255,7 @@ class Packed(object): field_lengths = [4, 2, 2] # YYYY-MM-DD elems = [] for i, item in enumerate(new_items): - elems.append( ('%0' + str(field_lengths[i]) + 'i') % item ) + elems.append('{0:0{1}}'.format(int(item), field_lengths[i])) self.items = '-'.join(elems) elif self.packstyle == packing.TUPLE: self.items = new_items diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 9be05ee18..9c8b7f35e 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -529,7 +529,7 @@ def cpu_count(): """Return the number of hardware thread contexts (cores or SMT threads) in the system. """ - # Adapted from observing the soundconverter project: + # Adapted from the soundconverter project: # https://github.com/kassoulet/soundconverter if sys.platform == 'win32': try: diff --git a/docs/changelog.rst b/docs/changelog.rst index b3929941b..05cf1938c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -51,6 +51,8 @@ Changelog modify files' tags even when they successfully change the database. * Fix a VFS bug leading to a crash in the :doc:`/plugins/bpd` when files had non-ASCII extensions. +* Fix for changing date fields (like "year") with the :ref:`modify-cmd` + command. * Add a human-readable error message when writing files' tags fails. * Changed plugin loading so that modules can be imported without unintentionally loading the plugins they contain. diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index 0b92f7cc8..64b760199 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -164,6 +164,8 @@ You'll be shown a list of the files that will be removed and asked to confirm. By default, this just removes entries from the library database; it doesn't touch the files on disk. To actually delete the files, use ``beet remove -d``. +.. _modify-cmd: + modify `````` :: diff --git a/test/test_mediafile.py b/test/test_mediafile.py index 3c1fc1104..5ac8b0d02 100644 --- a/test/test_mediafile.py +++ b/test/test_mediafile.py @@ -196,6 +196,15 @@ class MissingAudioDataTest(unittest.TestCase): del self.mf.mgfile.info.bitrate # Not available directly. self.assertEqual(self.mf.bitrate, 0) +class TypeTest(unittest.TestCase): + def setUp(self): + path = os.path.join(_common.RSRC, 'full.mp3') + self.mf = beets.mediafile.MediaFile(path) + + def test_year_integer_in_string(self): + self.mf.year = '2009' + self.assertEqual(self.mf.year, 2009) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)