diff --git a/src/calibre/srv/metadata.py b/src/calibre/srv/metadata.py index 23eb18e9d8..569071cdfe 100644 --- a/src/calibre/srv/metadata.py +++ b/src/calibre/srv/metadata.py @@ -66,7 +66,15 @@ def add_field(field, db, book_id, ans, field_metadata): def book_as_json(db, book_id): db = db.new_api with db.safe_read_lock: - ans = {'formats':db._formats(book_id)} + fmts = db._formats(book_id, verify_formats=False) + ans = [] + fm = {} + for fmt in fmts: + m = db.format_metadata(book_id, fmt) + if m and m.get('size', 0) > 0: + ans.append(fmt) + fm[fmt] = m['size'] + ans = {'formats': ans, 'format_sizes': fm} if not ans['formats'] and not db.has_id(book_id): return None fm = db.field_metadata diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 915465df0e..a6876b6160 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -7,13 +7,13 @@ from elementmaker import E from gettext import gettext as _ from ajax import ajax, encode_query_component +from book_list.globals import get_session_data from book_list.item_list import create_item, create_item_list from book_list.library_data import ( book_metadata, cover_url, current_library_id, current_virtual_library, download_url, library_data, load_status, set_book_metadata ) from book_list.router import back, home, open_book -from book_list.globals import get_session_data from book_list.theme import get_color, get_font_size from book_list.top_bar import add_button, create_top_bar, set_title from book_list.ui import query_as_href, set_panel_handler, show_panel @@ -23,8 +23,8 @@ from dom import add_extra_css, build_rule, clear, svgicon from modals import create_custom_dialog, error_dialog from session import get_interface_data from utils import ( - conditional_timeout, debounce, fmt_sidx, parse_url_params, safe_set_inner_html, - sandboxed_html + conditional_timeout, debounce, fmt_sidx, human_readable, parse_url_params, + safe_set_inner_html, sandboxed_html ) from widgets import create_button, create_spinner @@ -74,7 +74,7 @@ def href_for_search(name, val): def on_fmt_click(ev): fmt = ev.currentTarget.dataset.format book_id = int(ev.currentTarget.dataset.bookId) - title = this + title, sz = this create_custom_dialog(title, def(parent, close_modal): @@ -87,7 +87,8 @@ def on_fmt_click(ev): E.div(class_='button-box', create_button(_('Read'), 'book', action.bind(None, read_format)), '\xa0', - create_button(_('Download'), 'cloud-download', action.bind(None, download_format)), + create_button(_('Download'), 'cloud-download', action.bind(None, download_format), + tooltip=_('File size: {}').format(human_readable(sz))), ) )) ) @@ -194,7 +195,8 @@ def render_metadata(mi, table, book_id): # {{{ td.appendChild(E.a( fmt, class_='simple-link', href='javascript:void(0)', title=_('Read or download this book in the {} format').format(fmt), - onclick=on_fmt_click.bind(mi.title), data_format=fmt, data_book_id='' + book_id)) + onclick=on_fmt_click.bind(v'[mi.title, mi.format_sizes[fmt] || 0]'), + data_format=fmt, data_book_id='' + book_id)) if fmt is not val[-1]: td.appendChild(document.createTextNode(', ')) @@ -424,7 +426,8 @@ def render_book(container_id, book_id): read_button = create_button(_('Read'), 'book', read_book.bind(None, book_id), _('Read this book')) fmt = preferred_format(book_id) download_button = create_button(_('Download'), 'cloud-download', download_url(book_id, fmt), - _('Download this book in the {} format').format(fmt), download_filename=f'{metadata.title}.{fmt.toLowerCase()}') + _('Download this book in the {0} format ({1})').format(fmt, human_readable(metadata.format_sizes[fmt] or 0)), + download_filename=f'{metadata.title}.{fmt.toLowerCase()}') row = E.div(read_button, '\xa0\xa0\xa0', download_button, style='margin-bottom: 1ex') if not metadata.formats or not metadata.formats.length: row.style.display = 'none'