Start migrating the isbndb plugin

This commit is contained in:
Kovid Goyal 2011-04-05 12:36:12 -06:00
parent 547454c705
commit d9cea95a71
3 changed files with 46 additions and 1 deletions

View File

@ -17,7 +17,7 @@ from calibre.utils.config import JSONConfig
from calibre.utils.titlecase import titlecase from calibre.utils.titlecase import titlecase
from calibre.ebooks.metadata import check_isbn from calibre.ebooks.metadata import check_isbn
msprefs = JSONConfig('metadata_sources.json') msprefs = JSONConfig('metadata_sources/global.json')
msprefs.defaults['txt_comments'] = False msprefs.defaults['txt_comments'] = False
msprefs.defaults['ignore_fields'] = [] msprefs.defaults['ignore_fields'] = []
msprefs.defaults['max_tags'] = 20 msprefs.defaults['max_tags'] = 20

View File

@ -272,6 +272,7 @@ def identify(log, abort, title=None, authors=None, identifiers={}, timeout=30):
if k not in ('title', 'authors', 'identifiers'): if k not in ('title', 'authors', 'identifiers'):
sort_kwargs.pop(k) sort_kwargs.pop(k)
longest, lp = -1, ''
for plugin, presults in results.iteritems(): for plugin, presults in results.iteritems():
presults.sort(key=plugin.identify_results_keygen(**sort_kwargs)) presults.sort(key=plugin.identify_results_keygen(**sort_kwargs))
plog = logs[plugin].getvalue().strip() plog = logs[plugin].getvalue().strip()
@ -281,8 +282,11 @@ def identify(log, abort, title=None, authors=None, identifiers={}, timeout=30):
time_spent = getattr(plugin, 'dl_time_spent', None) time_spent = getattr(plugin, 'dl_time_spent', None)
if time_spent is None: if time_spent is None:
log('Downloading was aborted') log('Downloading was aborted')
longest, lp = -1, plugin.name
else: else:
log('Downloading from', plugin.name, 'took', time_spent) log('Downloading from', plugin.name, 'took', time_spent)
if time_spent > longest:
longest, lp = time_spent, plugin.name
for r in presults: for r in presults:
log('\n\n---') log('\n\n---')
log(unicode(r)) log(unicode(r))
@ -297,6 +301,7 @@ def identify(log, abort, title=None, authors=None, identifiers={}, timeout=30):
result.identify_plugin = plugin result.identify_plugin = plugin
log('The identify phase took %.2f seconds'%(time.time() - start_time)) log('The identify phase took %.2f seconds'%(time.time() - start_time))
log('The longest time (%f) was taken by:'%longest, lp)
log('Merging results from different sources and finding earliest', log('Merging results from different sources and finding earliest',
'publication dates') 'publication dates')
start_time = time.time() start_time = time.time()

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from calibre.ebooks.metadata.sources.base import Source
class ISBNDB(Source):
name = 'ISBNDB'
description = _('Downloads metadata from isbndb.com')
capabilities = frozenset(['identify'])
touched_fields = frozenset(['title', 'authors',
'identifier:isbn', 'comments', 'publisher'])
supports_gzip_transfer_encoding = True
def __init__(self, *args, **kwargs):
Source.__init__(self, *args, **kwargs)
prefs = self.prefs
prefs.defaults['key_migrated'] = False
prefs.defaults['isbndb_key'] = None
if not prefs['key_migrated']:
prefs['key_migrated'] = True
try:
from calibre.customize.ui import config
key = config['plugin_customization']['IsbnDB']
prefs['isbndb_key'] = key
except:
pass
self.isbndb_key = prefs['isbndb_key']