Merge branch 'fetch-metadata-by-plugin' of https://github.com/na--/calibre

This commit is contained in:
Kovid Goyal 2017-04-23 18:33:01 +05:30
commit dac9782a45
2 changed files with 13 additions and 3 deletions

View File

@ -12,6 +12,7 @@ from io import BytesIO
from threading import Event from threading import Event
from calibre import prints from calibre import prints
from calibre.customize.ui import all_metadata_plugins
from calibre.utils.config import OptionParser from calibre.utils.config import OptionParser
from calibre.utils.img import save_cover_data_to from calibre.utils.img import save_cover_data_to
from calibre.ebooks.metadata import string_to_authors from calibre.ebooks.metadata import string_to_authors
@ -40,6 +41,11 @@ of title, authors or ISBN.
help=_('Specify a filename. The cover, if available, will be saved to it. Without this option, no cover will be downloaded.')) help=_('Specify a filename. The cover, if available, will be saved to it. Without this option, no cover will be downloaded.'))
parser.add_option('-d', '--timeout', default='30', parser.add_option('-d', '--timeout', default='30',
help=_('Timeout in seconds. Default is 30')) help=_('Timeout in seconds. Default is 30'))
parser.add_option('-p', '--allowed-plugin', action='append', default=[],
help=_('Specify the name of a metadata download plugin to use.'
' By default, all metadata plugins will be used.'
' Can be specified multiple times for multiple plugins.'
' All plugin names: {}').format(', '.join(p.name for p in all_metadata_plugins())))
return parser return parser
@ -61,8 +67,10 @@ def main(args=sys.argv):
if opts.isbn: if opts.isbn:
identifiers['isbn'] = opts.isbn identifiers['isbn'] = opts.isbn
allowed_plugins = frozenset(opts.allowed_plugin)
results = identify(log, abort, title=opts.title, authors=authors, results = identify(log, abort, title=opts.title, authors=authors,
identifiers=identifiers, timeout=int(opts.timeout)) identifiers=identifiers, timeout=int(opts.timeout),
allowed_plugins=allowed_plugins or None)
if not results: if not results:
print (log, file=sys.stderr) print (log, file=sys.stderr)

View File

@ -369,13 +369,15 @@ def merge_identify_results(result_map, log):
def identify(log, abort, # {{{ def identify(log, abort, # {{{
title=None, authors=None, identifiers={}, timeout=30): title=None, authors=None, identifiers={}, timeout=30, allowed_plugins=None):
if title == _('Unknown'): if title == _('Unknown'):
title = None title = None
if authors == [_('Unknown')]: if authors == [_('Unknown')]:
authors = None authors = None
start_time = time.time() start_time = time.time()
plugins = [p for p in metadata_plugins(['identify']) if p.is_configured()]
plugins = [p for p in metadata_plugins(['identify'])
if p.is_configured() and (allowed_plugins is None or p.name in allowed_plugins)]
kwargs = { kwargs = {
'title': title, 'title': title,