diff --git a/src/calibre/srv/metadata.py b/src/calibre/srv/metadata.py index e3355d7c76..010acd54bb 100644 --- a/src/calibre/srv/metadata.py +++ b/src/calibre/srv/metadata.py @@ -24,7 +24,7 @@ from calibre.library.field_metadata import category_icon_map from polyglot.builtins import iteritems, itervalues, range, filter, unicode_type from polyglot.urllib import quote -IGNORED_FIELDS = frozenset('cover ondevice path marked au_map size'.split()) +IGNORED_FIELDS = frozenset('cover ondevice path marked au_map'.split()) def encode_datetime(dateval): diff --git a/src/pyj/book_list/custom_list.pyj b/src/pyj/book_list/custom_list.pyj index 1b44260911..504b1a38ce 100644 --- a/src/pyj/book_list/custom_list.pyj +++ b/src/pyj/book_list/custom_list.pyj @@ -135,6 +135,20 @@ def render_field(field, mi, book_id): # {{{ val = 1 return fmt_sidx(val, use_roman=interface_data.use_roman_numerals_for_series_number) + def process_size(field, fm, name, val): + val = val or 0 + mb = 1024 * 1024 + + def fmt(val, suffix): + ans = f'{val:.1f}' + if ans.endsWith('.0'): + ans = ans[:-2] + return ans + suffix + + if val < mb: + return fmt(val / 1024, 'KB') + return fmt(val / mb, 'MB') + name = fm.name or field datatype = fm.datatype if field is 'comments' or datatype is 'comments': @@ -160,6 +174,8 @@ def render_field(field, mi, book_id): # {{{ func = process_series elif field.endswith('_index'): func = process_series_index + elif field is 'size': + func = process_size ans = None if func: ans = func(field, fm, name, val)