Use new cover downloaders when fetching cover for single book

This commit is contained in:
Kovid Goyal 2010-08-01 11:34:46 -06:00
parent 8039d980f2
commit 73b8a5a09e

View File

@ -24,8 +24,9 @@ from calibre.gui2.widgets import ProgressIndicator
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
from calibre.ebooks.metadata import string_to_authors, \ from calibre.ebooks.metadata import string_to_authors, \
authors_to_string, check_isbn authors_to_string, check_isbn
from calibre.ebooks.metadata.library_thing import cover_from_isbn from calibre.ebooks.metadata.covers import download_cover
from calibre.ebooks.metadata.meta import get_metadata from calibre.ebooks.metadata.meta import get_metadata
from calibre.ebooks.metadata import MetaInformation
from calibre.utils.config import prefs, tweaks from calibre.utils.config import prefs, tweaks
from calibre.utils.date import qt_to_dt, local_tz, utcfromtimestamp from calibre.utils.date import qt_to_dt, local_tz, utcfromtimestamp
from calibre.customize.ui import run_plugins_on_import, get_isbndb_key from calibre.customize.ui import run_plugins_on_import, get_isbndb_key
@ -48,12 +49,13 @@ class CoverFetcher(QThread):
def run(self): def run(self):
try: try:
au = self.author if self.author else None
mi = MetaInformation(self.title, [au])
if not self.isbn: if not self.isbn:
from calibre.ebooks.metadata.fetch import search from calibre.ebooks.metadata.fetch import search
if not self.title: if not self.title:
self.needs_isbn = True self.needs_isbn = True
return return
au = self.author if self.author else None
key = get_isbndb_key() key = get_isbndb_key()
if not key: if not key:
key = None key = None
@ -66,8 +68,10 @@ class CoverFetcher(QThread):
return return
self.isbn = results[0] self.isbn = results[0]
self.cover_data = cover_from_isbn(self.isbn, timeout=self.timeout, mi.isbn = self.isbn
username=self.username, password=self.password)[0]
self.cover_data, self.errors = download_cover(mi,
timeout=self.timeout)
except Exception, e: except Exception, e:
self.exception = e self.exception = e
self.traceback = traceback.format_exc() self.traceback = traceback.format_exc()
@ -576,6 +580,13 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
error_dialog(self, _('Cannot fetch cover'), error_dialog(self, _('Cannot fetch cover'),
_('<b>Could not fetch cover.</b><br/>')+unicode(err)).exec_() _('<b>Could not fetch cover.</b><br/>')+unicode(err)).exec_()
return return
if self.cover_fetcher.errors and self.cover_fetcher.cover_data is None:
details = u'\n\n'.join([e[-1] + ': ' + e[1] for e in self.cover_fetcher.errors])
error_dialog(self, _('Cannot fetch cover'),
_('<b>Could not fetch cover.</b><br/>') +
_('For the error message from each cover source, '
'click Show details below.'), det_msg=details, show=True)
return
pix = QPixmap() pix = QPixmap()
pix.loadFromData(self.cover_fetcher.cover_data) pix.loadFromData(self.cover_fetcher.cover_data)