info: revert human_length changes

* Remove human length changes from the plugin and the tests, as they will
eventually be handled at a higher level.
This commit is contained in:
Diego Moreda 2015-11-25 16:06:19 +01:00
parent 67af8af7dd
commit 83279ebe5b
2 changed files with 5 additions and 50 deletions

View file

@ -90,17 +90,10 @@ def print_data(data, fmt=None, human_length=True):
If no format string `fmt` is passed, the entries on `data` are printed one
in each line, with the format 'field: value'. If `fmt` is not `None`, the
item is printed according to `fmt`, using the `Item.__format__` machinery.
If `raw_length` is `True`, the `length` field is displayed using its raw
value (float with the number of seconds and miliseconds). If not, a human
readable form is displayed instead (mm:ss).
"""
item = data.pop('item', None)
if fmt:
# use fmt specified by the user, prettifying length if needed
if human_length and '$length' in fmt:
item['humanlength'] = ui.human_seconds_short(item.length)
fmt = fmt.replace('$length', '$humanlength')
# use fmt specified by the user
ui.print_(format(item, fmt))
return
@ -110,10 +103,7 @@ def print_data(data, fmt=None, human_length=True):
if isinstance(value, list):
formatted[key] = u'; '.join(value)
if value is not None:
if human_length and key == 'length':
formatted[key] = ui.human_seconds_short(float(value))
else:
formatted[key] = value
formatted[key] = value
if len(formatted) == 0:
return
@ -143,9 +133,6 @@ class InfoPlugin(BeetsPlugin):
cmd.parser.add_option('-i', '--include-keys', default=[],
action='append', dest='included_keys',
help='comma separated list of keys to show')
cmd.parser.add_option('-r', '--raw-length', action='store_true',
default=False,
help='display length as seconds')
cmd.parser.add_format_option(target='item')
return [cmd]
@ -192,11 +179,11 @@ class InfoPlugin(BeetsPlugin):
else:
if not first:
ui.print_()
print_data(data, opts.format, not opts.raw_length)
print_data(data, opts.format)
first = False
if opts.summarize:
print_data(summary, human_length=not opts.raw_length)
print_data(summary)
def make_key_filter(include):

View file

@ -107,43 +107,11 @@ class InfoTest(unittest.TestCase, TestHelper):
self.assertNotIn(u'title:', out)
self.assertIn(u'album: xxxx', out)
def test_length_human_library(self):
item, = self.add_item_fixtures()
item.album = 'loool'
item.length = 123.4
item.write()
item.store()
out = self.run_with_output('--library')
self.assertIn(u'length: 2:03', out)
def test_length_raw_library(self):
item, = self.add_item_fixtures()
item.album = 'loool'
item.length = 123.4
item.write()
item.store()
out = self.run_with_output('--library', '--raw-length')
self.assertIn(u'length: 123.4', out)
def test_length_human_path(self):
path = self.create_mediafile_fixture()
out = self.run_with_output(path)
self.assertIn(u'length: 0:01', out)
self.remove_mediafile_fixtures()
def test_length_raw_path(self):
path = self.create_mediafile_fixture()
out = self.run_with_output(path, '--raw-length')
self.assertIn(u'length: 1.071', out)
self.remove_mediafile_fixtures()
def test_custom_format(self):
self.add_item_fixtures()
out = self.run_with_output('--library', '--format',
'$track. $title - $artist ($length)')
self.assertEqual(u'02. tïtle 0 - the artist (0:01)\n', out)
self.assertEqual(u'02. tïtle 0 - the artist (1.1)\n', out)
def suite():