mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'fetch-metadata-by-plugin' of https://github.com/na--/calibre
This commit is contained in:
commit
dac9782a45
@ -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)
|
||||||
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user