mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 01:23:09 +01:00
Expose an Item's filesize as a field
- Update test-case for info to make sure the item's path is pointing to an actual file. See #1291
This commit is contained in:
parent
313c3807aa
commit
6ed0b2e0f3
3 changed files with 6 additions and 7 deletions
|
|
@ -420,6 +420,8 @@ class Item(LibModel):
|
|||
def _getters(cls):
|
||||
getters = plugins.item_field_getters()
|
||||
getters['singleton'] = lambda i: i.album_id is None
|
||||
# Filesize is given in bytes
|
||||
getters['filesize'] = lambda i: os.path.getsize(syspath(i.path))
|
||||
return getters
|
||||
|
||||
@classmethod
|
||||
|
|
@ -603,11 +605,6 @@ class Item(LibModel):
|
|||
"""
|
||||
return int(os.path.getmtime(syspath(self.path)))
|
||||
|
||||
def filesize(self):
|
||||
"""Returns the size, in bytes, of the file.
|
||||
"""
|
||||
return os.path.getsize(syspath(self.path))
|
||||
|
||||
# Model methods.
|
||||
|
||||
def remove(self, delete=False, with_album=True):
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ def summarize_items(items, singleton):
|
|||
|
||||
average_bitrate = sum([item.bitrate for item in items]) / len(items)
|
||||
total_duration = sum([item.length for item in items])
|
||||
total_filesize = sum([item.filesize() for item in items])
|
||||
total_filesize = sum([item.filesize for item in items])
|
||||
summary_parts.append('{0}kbps'.format(int(average_bitrate / 1000)))
|
||||
summary_parts.append(ui.human_seconds_short(total_duration))
|
||||
summary_parts.append(ui.human_bytes(total_filesize))
|
||||
|
|
|
|||
|
|
@ -94,7 +94,9 @@ class InfoTest(unittest.TestCase, TestHelper):
|
|||
self.assertIn(u'title: [various]', out)
|
||||
|
||||
def test_include_pattern(self):
|
||||
item = self.add_item(album='xxxx')
|
||||
item, = self.add_item_fixtures()
|
||||
item.album = 'xxxx'
|
||||
item.store()
|
||||
|
||||
out = self.run_with_output('--library', 'album:xxxx',
|
||||
'--include-keys', '*lbu*')
|
||||
|
|
|
|||
Loading…
Reference in a new issue