From 71d3be238bfc7182a86c30a468c3d0efade34b35 Mon Sep 17 00:00:00 2001 From: David Logie Date: Wed, 8 Jul 2015 13:19:07 +0100 Subject: [PATCH] zero: optionally update tags in the database. --- beetsplug/zero.py | 3 +++ docs/changelog.rst | 2 ++ docs/plugins/zero.rst | 6 ++++-- test/test_zero.py | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/beetsplug/zero.py b/beetsplug/zero.py index 48ca930ca..abccde36f 100644 --- a/beetsplug/zero.py +++ b/beetsplug/zero.py @@ -41,6 +41,7 @@ class ZeroPlugin(BeetsPlugin): self.config.add({ 'fields': [], + 'update_database': False, }) self.patterns = {} @@ -99,3 +100,5 @@ class ZeroPlugin(BeetsPlugin): if match: self._log.debug(u'{0}: {1} -> None', field, value) tags[field] = None + if self.config['update_database']: + item[field] = None diff --git a/docs/changelog.rst b/docs/changelog.rst index 196795698..13c8b7931 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,8 @@ New features: :bug:`1104` :bug:`1493` * :doc:`/plugins/plexupdate`: A new ``token`` configuration option lets you specify a key for Plex Home setups. Thanks to :user:`edcarroll`. :bug:`1494` +* :doc:`/plugins/zero`: A new ``update_database`` configuration option + allows the database to be updated along with files' tags. :bug:`1516` Fixes: diff --git a/docs/plugins/zero.rst b/docs/plugins/zero.rst index c53a7b148..2682ee6ca 100644 --- a/docs/plugins/zero.rst +++ b/docs/plugins/zero.rst @@ -3,8 +3,7 @@ Zero Plugin The ``zero`` plugin allows you to null fields in files' metadata tags. Fields can be nulled unconditionally or conditioned on a pattern match. For example, -the plugin can strip useless comments like "ripped by MyGreatRipper." This -plugin only affects files' tags ; the beets database is left unchanged. +the plugin can strip useless comments like "ripped by MyGreatRipper." To use the ``zero`` plugin, enable the plugin in your configuration (see :ref:`using-plugins`). @@ -21,6 +20,8 @@ fields to nullify and the conditions for nullifying them: embedded in the media file. * To conditionally filter a field, use ``field: [regexp, regexp]`` to specify regular expressions. +* By default this plugin only affects files' tags ; the beets database is left + unchanged. To update the tags in the database, set the ``update_database`` option. For example:: @@ -28,6 +29,7 @@ For example:: fields: month day genre comments comments: [EAC, LAME, from.+collection, 'ripped by'] genre: [rnb, 'power metal'] + update_database: true If a custom pattern is not defined for a given field, the field will be nulled unconditionally. diff --git a/test/test_zero.py b/test/test_zero.py index 7274cc943..b92034dfb 100644 --- a/test/test_zero.py +++ b/test/test_zero.py @@ -88,6 +88,24 @@ class ZeroPluginTest(unittest.TestCase, TestHelper): self.assertEqual(item['year'], 2000) self.assertIsNone(mediafile.year) + def test_change_database(self): + item = self.add_item_fixture(year=2000) + item.write() + mediafile = MediaFile(item.path) + self.assertEqual(2000, mediafile.year) + + config['zero'] = { + 'fields': ['year'], + 'update_database': True, + } + self.load_plugins('zero') + + item.write() + mediafile = MediaFile(item.path) + self.assertEqual(item['year'], 0) + self.assertIsNone(mediafile.year) + + def test_album_art(self): path = self.create_mediafile_fixture(images=['jpg']) item = Item.from_path(path)