def run_import_plugins(formats): from calibre.ebooks.metadata.worker import run_import_plugins import_ctx['group_id'] += 1 ans = run_import_plugins(formats, import_ctx['group_id'], import_ctx['tdir']) fm = import_ctx['format_map'] for old_path, new_path in zip(formats, ans): fm[new_path] = old_path return ans
def run_import_plugins(formats): from calibre.ebooks.metadata.worker import run_import_plugins import_ctx['group_id'] += 1 ans = run_import_plugins(formats, import_ctx['group_id'], import_ctx['tdir']) fm = import_ctx['format_map'] for old_path, new_path in zip(formats, ans): fm[new_path] = old_path return ans
def forked_read_metadata(original_path, tdir): from calibre.ebooks.metadata.opf2 import metadata_to_opf from calibre.ebooks.metadata.worker import run_import_plugins path = run_import_plugins((original_path, ), os.getpid(), tdir)[0] if path != original_path: with lopen(os.path.join(tdir, 'file_changed_by_plugins'), 'w') as f: f.write(os.path.abspath(path)) with lopen(path, 'rb') as f: fmt = os.path.splitext(path)[1][1:].lower() f.seek(0, 2) sz = f.tell() with lopen(os.path.join(tdir, 'size.txt'), 'wb') as s: s.write(str(sz).encode('ascii')) f.seek(0) mi = get_metadata(f, fmt) if mi.cover_data and mi.cover_data[1]: with lopen(os.path.join(tdir, 'cover.jpg'), 'wb') as f: f.write(mi.cover_data[1]) mi.cover_data = (None, None) mi.cover = 'cover.jpg' opf = metadata_to_opf(mi, default_lang='und') with lopen(os.path.join(tdir, 'metadata.opf'), 'wb') as f: f.write(opf)