mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also load metadata when loading manifest
This commit is contained in:
parent
d62024d1b1
commit
da04475ff1
@ -107,7 +107,7 @@ def prepare_convert(temp_path, key, st):
|
|||||||
def do_convert(path, temp_path, key, instance):
|
def do_convert(path, temp_path, key, instance):
|
||||||
tdir = os.path.join(temp_path, instance['path'])
|
tdir = os.path.join(temp_path, instance['path'])
|
||||||
fork_job('calibre.srv.render_book', 'render', args=(
|
fork_job('calibre.srv.render_book', 'render', args=(
|
||||||
path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key}
|
path, tdir, {'size': instance['file_size'], 'mtime': instance['file_mtime'], 'hash': key}, True,
|
||||||
), timeout=3000, no_output=True
|
), timeout=3000, no_output=True
|
||||||
)
|
)
|
||||||
size = 0
|
size = 0
|
||||||
|
@ -89,6 +89,11 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler):
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
rq.fail(rq.RequestFailed)
|
rq.fail(rq.RequestFailed)
|
||||||
|
elif name == 'manifest':
|
||||||
|
manifest, mime_type = get_data('calibre-book-manifest.json')
|
||||||
|
metadata = get_data('calibre-book-metadata.json')[0]
|
||||||
|
data = b'[' + manifest + b',' + metadata + b']'
|
||||||
|
self.send_reply(rq, mime_type, data)
|
||||||
|
|
||||||
def send_reply(self, rq, mime_type, data):
|
def send_reply(self, rq, mime_type, data):
|
||||||
if sip.isdeleted(rq):
|
if sip.isdeleted(rq):
|
||||||
|
@ -522,8 +522,17 @@ def html_as_dict(root):
|
|||||||
return {'ns_map':ns_map, 'tag_map':tags, 'tree':tree}
|
return {'ns_map':ns_map, 'tag_map':tags, 'tree':tree}
|
||||||
|
|
||||||
|
|
||||||
def render(pathtoebook, output_dir, book_hash=None):
|
def render(pathtoebook, output_dir, book_hash=None, serialize_metadata=False):
|
||||||
Container(pathtoebook, output_dir, book_hash=book_hash)
|
Container(pathtoebook, output_dir, book_hash=book_hash)
|
||||||
|
if serialize_metadata:
|
||||||
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
|
from calibre.ebooks.metadata.book.serialize import metadata_as_dict
|
||||||
|
with lopen(pathtoebook, 'rb') as f:
|
||||||
|
mi = get_metadata(f, os.path.splitext(pathtoebook)[1][1:].lower())
|
||||||
|
d = metadata_as_dict(mi)
|
||||||
|
d.pop('cover_data', None)
|
||||||
|
with lopen(os.path.join(output_dir, 'calibre-book-metadata.json'), 'wb') as f:
|
||||||
|
f.write(json.dumps(d))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -45,8 +45,9 @@ def manifest_received(key, end_type, xhr, ev):
|
|||||||
nonlocal book
|
nonlocal book
|
||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
book = new_book(key, {})
|
book = new_book(key, {})
|
||||||
book.manifest = JSON.parse(xhr.responseText)
|
data = JSON.parse(xhr.responseText)
|
||||||
book.metadata = book.manifest.metadata
|
book.manifest = data[0]
|
||||||
|
book.metadata = book.manifest.metadata = data[1]
|
||||||
book.stored_files = {}
|
book.stored_files = {}
|
||||||
book.is_complete = True
|
book.is_complete = True
|
||||||
v'delete book.manifest["metadata"]'
|
v'delete book.manifest["metadata"]'
|
||||||
@ -96,7 +97,7 @@ def start_book_load(key, prefs):
|
|||||||
if view is None:
|
if view is None:
|
||||||
create_session_data(prefs)
|
create_session_data(prefs)
|
||||||
view = View(document.getElementById('view'))
|
view = View(document.getElementById('view'))
|
||||||
ajax('book/calibre-book-manifest.json', manifest_received.bind(None, key), ok_code=0).send()
|
ajax('manifest', manifest_received.bind(None, key), ok_code=0).send()
|
||||||
|
|
||||||
|
|
||||||
def onerror(msg, script_url, line_number, column_number, error_object):
|
def onerror(msg, script_url, line_number, column_number, error_object):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user