mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Correctly call input/output format and metadata download plugins
This commit is contained in:
parent
ed2d33a584
commit
5196de8f4b
@ -206,7 +206,6 @@ class MetadataReaderPlugin(Plugin):
|
|||||||
type = _('Metadata reader')
|
type = _('Metadata reader')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
print 11111, args, kwargs
|
|
||||||
Plugin.__init__(self, *args, **kwargs)
|
Plugin.__init__(self, *args, **kwargs)
|
||||||
self.quick = False
|
self.quick = False
|
||||||
|
|
||||||
|
@ -731,7 +731,8 @@ OptionRecommendation(name='timestamp',
|
|||||||
zf = ZipFile(os.path.join(self.opts.debug_pipeline,
|
zf = ZipFile(os.path.join(self.opts.debug_pipeline,
|
||||||
'periodical.downloaded_recipe'), 'w')
|
'periodical.downloaded_recipe'), 'w')
|
||||||
zf.add_dir(out_dir)
|
zf.add_dir(out_dir)
|
||||||
self.input_plugin.save_download(zf)
|
with self.input_plugin:
|
||||||
|
self.input_plugin.save_download(zf)
|
||||||
zf.close()
|
zf.close()
|
||||||
|
|
||||||
self.log.info('Input debug saved to:', out_dir)
|
self.log.info('Input debug saved to:', out_dir)
|
||||||
@ -780,28 +781,29 @@ OptionRecommendation(name='timestamp',
|
|||||||
self.ui_reporter(0.01, _('Converting input to HTML...'))
|
self.ui_reporter(0.01, _('Converting input to HTML...'))
|
||||||
ir = CompositeProgressReporter(0.01, 0.34, self.ui_reporter)
|
ir = CompositeProgressReporter(0.01, 0.34, self.ui_reporter)
|
||||||
self.input_plugin.report_progress = ir
|
self.input_plugin.report_progress = ir
|
||||||
self.oeb = self.input_plugin(stream, self.opts,
|
with self.input_plugin:
|
||||||
self.input_fmt, self.log,
|
self.oeb = self.input_plugin(stream, self.opts,
|
||||||
accelerators, tdir)
|
self.input_fmt, self.log,
|
||||||
if self.opts.debug_pipeline is not None:
|
accelerators, tdir)
|
||||||
self.dump_input(self.oeb, tdir)
|
if self.opts.debug_pipeline is not None:
|
||||||
if self.abort_after_input_dump:
|
self.dump_input(self.oeb, tdir)
|
||||||
return
|
if self.abort_after_input_dump:
|
||||||
if self.input_fmt in ('recipe', 'downloaded_recipe'):
|
return
|
||||||
self.opts_to_mi(self.user_metadata)
|
if self.input_fmt in ('recipe', 'downloaded_recipe'):
|
||||||
if not hasattr(self.oeb, 'manifest'):
|
self.opts_to_mi(self.user_metadata)
|
||||||
self.oeb = create_oebbook(self.log, self.oeb, self.opts,
|
if not hasattr(self.oeb, 'manifest'):
|
||||||
self.input_plugin)
|
self.oeb = create_oebbook(self.log, self.oeb, self.opts,
|
||||||
self.input_plugin.postprocess_book(self.oeb, self.opts, self.log)
|
self.input_plugin)
|
||||||
self.opts.is_image_collection = self.input_plugin.is_image_collection
|
self.input_plugin.postprocess_book(self.oeb, self.opts, self.log)
|
||||||
pr = CompositeProgressReporter(0.34, 0.67, self.ui_reporter)
|
self.opts.is_image_collection = self.input_plugin.is_image_collection
|
||||||
self.flush()
|
pr = CompositeProgressReporter(0.34, 0.67, self.ui_reporter)
|
||||||
if self.opts.debug_pipeline is not None:
|
self.flush()
|
||||||
out_dir = os.path.join(self.opts.debug_pipeline, 'parsed')
|
if self.opts.debug_pipeline is not None:
|
||||||
self.dump_oeb(self.oeb, out_dir)
|
out_dir = os.path.join(self.opts.debug_pipeline, 'parsed')
|
||||||
self.log('Parsed HTML written to:', out_dir)
|
self.dump_oeb(self.oeb, out_dir)
|
||||||
self.input_plugin.specialize(self.oeb, self.opts, self.log,
|
self.log('Parsed HTML written to:', out_dir)
|
||||||
self.output_fmt)
|
self.input_plugin.specialize(self.oeb, self.opts, self.log,
|
||||||
|
self.output_fmt)
|
||||||
|
|
||||||
pr(0., _('Running transforms on ebook...'))
|
pr(0., _('Running transforms on ebook...'))
|
||||||
|
|
||||||
@ -891,7 +893,8 @@ OptionRecommendation(name='timestamp',
|
|||||||
our = CompositeProgressReporter(0.67, 1., self.ui_reporter)
|
our = CompositeProgressReporter(0.67, 1., self.ui_reporter)
|
||||||
self.output_plugin.report_progress = our
|
self.output_plugin.report_progress = our
|
||||||
our(0., _('Creating')+' %s'%self.output_plugin.name)
|
our(0., _('Creating')+' %s'%self.output_plugin.name)
|
||||||
self.output_plugin.convert(self.oeb, self.output, self.input_plugin,
|
with self.output_plugin:
|
||||||
|
self.output_plugin.convert(self.oeb, self.output, self.input_plugin,
|
||||||
self.opts, self.log)
|
self.opts, self.log)
|
||||||
self.ui_reporter(1.)
|
self.ui_reporter(1.)
|
||||||
run_plugins_on_postprocess(self.output, self.output_fmt)
|
run_plugins_on_postprocess(self.output, self.output_fmt)
|
||||||
|
@ -215,6 +215,28 @@ def merge_results(one, two):
|
|||||||
else:
|
else:
|
||||||
one[idx].smart_update(x)
|
one[idx].smart_update(x)
|
||||||
|
|
||||||
|
class MetadataSources(object):
|
||||||
|
|
||||||
|
def __init__(self, sources):
|
||||||
|
self.sources = sources
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
for s in self.sources:
|
||||||
|
s.__enter__()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *args):
|
||||||
|
for s in self.sources:
|
||||||
|
s.__exit__()
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
for s in self.sources:
|
||||||
|
s(*args, **kwargs)
|
||||||
|
|
||||||
|
def join(self):
|
||||||
|
for s in self.sources:
|
||||||
|
s.join()
|
||||||
|
|
||||||
def search(title=None, author=None, publisher=None, isbn=None, isbndb_key=None,
|
def search(title=None, author=None, publisher=None, isbn=None, isbndb_key=None,
|
||||||
verbose=0):
|
verbose=0):
|
||||||
assert not(title is None and author is None and publisher is None and \
|
assert not(title is None and author is None and publisher is None and \
|
||||||
@ -224,11 +246,10 @@ def search(title=None, author=None, publisher=None, isbn=None, isbndb_key=None,
|
|||||||
if isbn is not None:
|
if isbn is not None:
|
||||||
isbn = re.sub(r'[^a-zA-Z0-9]', '', isbn).upper()
|
isbn = re.sub(r'[^a-zA-Z0-9]', '', isbn).upper()
|
||||||
fetchers = list(metadata_sources(isbndb_key=isbndb_key))
|
fetchers = list(metadata_sources(isbndb_key=isbndb_key))
|
||||||
|
with MetadataSources(fetchers) as manager:
|
||||||
|
manager(title, author, publisher, isbn, verbose)
|
||||||
|
manager.join()
|
||||||
|
|
||||||
for fetcher in fetchers:
|
|
||||||
fetcher(title, author, publisher, isbn, verbose)
|
|
||||||
for fetcher in fetchers:
|
|
||||||
fetcher.join()
|
|
||||||
results = list(fetchers[0].results)
|
results = list(fetchers[0].results)
|
||||||
for fetcher in fetchers[1:]:
|
for fetcher in fetchers[1:]:
|
||||||
merge_results(results, fetcher.results)
|
merge_results(results, fetcher.results)
|
||||||
@ -243,10 +264,9 @@ def search(title=None, author=None, publisher=None, isbn=None, isbndb_key=None,
|
|||||||
def get_social_metadata(mi, verbose=0):
|
def get_social_metadata(mi, verbose=0):
|
||||||
from calibre.customize.ui import metadata_sources
|
from calibre.customize.ui import metadata_sources
|
||||||
fetchers = list(metadata_sources(metadata_type='social'))
|
fetchers = list(metadata_sources(metadata_type='social'))
|
||||||
for fetcher in fetchers:
|
with MetadataSources(fetchers) as manager:
|
||||||
fetcher(mi.title, mi.authors, mi.publisher, mi.isbn, verbose)
|
manager(mi.title, mi.authors, mi.publisher, mi.isbn, verbose)
|
||||||
for fetcher in fetchers:
|
manager.join()
|
||||||
fetcher.join()
|
|
||||||
ratings, tags, comments = [], set([]), set([])
|
ratings, tags, comments = [], set([]), set([])
|
||||||
for fetcher in fetchers:
|
for fetcher in fetchers:
|
||||||
if fetcher.results:
|
if fetcher.results:
|
||||||
|
@ -173,7 +173,8 @@ class EbookIterator(object):
|
|||||||
plumber.opts.no_process = True
|
plumber.opts.no_process = True
|
||||||
|
|
||||||
plumber.input_plugin.for_viewer = True
|
plumber.input_plugin.for_viewer = True
|
||||||
self.pathtoopf = plumber.input_plugin(open(plumber.input, 'rb'),
|
with plumber.input_plugin:
|
||||||
|
self.pathtoopf = plumber.input_plugin(open(plumber.input, 'rb'),
|
||||||
plumber.opts, plumber.input_fmt, self.log,
|
plumber.opts, plumber.input_fmt, self.log,
|
||||||
{}, self.base)
|
{}, self.base)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user