diff --git a/beetsplug/types.py b/beetsplug/types.py index 68aea35c7..e351c8add 100644 --- a/beetsplug/types.py +++ b/beetsplug/types.py @@ -22,6 +22,13 @@ class TypesPlugin(BeetsPlugin): @property def item_types(self): + return self._types() + + @property + def album_types(self): + return self._types() + + def _types(self): if not self.config.exists(): return {} diff --git a/docs/plugins/types.rst b/docs/plugins/types.rst index 978654e8d..b6503f353 100644 --- a/docs/plugins/types.rst +++ b/docs/plugins/types.rst @@ -15,3 +15,12 @@ Here's an example:: types: rating: int + +Now you can assign numeric ratings to tracks and albums and use :ref:`range +queries ` to filter them.:: + + beet modify "My favorite track" rating=5 + beet ls rating:4..5 + + beet modify --album "My favorite album" rating=5 + beet modify --album rating:4..5 diff --git a/test/test_types_plugin.py b/test/test_types_plugin.py index 5e34db9e2..d175525be 100644 --- a/test/test_types_plugin.py +++ b/test/test_types_plugin.py @@ -47,6 +47,22 @@ class TypesPluginTest(unittest.TestCase, TestHelper): out = self.list('myint:1..3') self.assertIn('aaa', out) + def test_album_integer_modify_and_query(self): + self.config['types'] = {'myint': 'int'} + album = self.add_album(albumartist='aaa') + + # Do not match unset values + out = self.list_album('myint:1..3') + self.assertEqual('', out) + + self.modify('-a', 'myint=2') + album.load() + self.assertEqual(album['myint'], 2) + + # Match in range + out = self.list_album('myint:1..3') + self.assertIn('aaa', out) + def test_float_modify_and_query(self): self.config['types'] = {'myfloat': 'float'} item = self.add_item(artist='aaa') @@ -121,6 +137,9 @@ class TypesPluginTest(unittest.TestCase, TestHelper): def list(self, query, fmt='$artist - $album - $title'): return self.run_with_output('ls', '-f', fmt, query).strip() + def list_album(self, query, fmt='$albumartist - $album - $title'): + return self.run_with_output('ls', '-a', '-f', fmt, query).strip() + def mktime(*args): return time.mktime(datetime(*args).timetuple())