mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Types plugin: Field types for albums and documentation example
This commit is contained in:
parent
da1624def7
commit
464f8cdc04
3 changed files with 35 additions and 0 deletions
|
|
@ -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 {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <numericquery>` 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
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in a new issue