Bulk metadata download works again. More testing of corner cases needed

This commit is contained in:
Kovid Goyal 2011-04-12 18:06:18 -06:00
parent 2ddf478929
commit f3beb13b62
4 changed files with 30 additions and 9 deletions

View File

@ -145,7 +145,7 @@ def download_cover(log,
Synchronous cover download. Returns the "best" cover as per user Synchronous cover download. Returns the "best" cover as per user
prefs/cover resolution. prefs/cover resolution.
Return cover is a tuple: (plugin, width, height, fmt, data) Returned cover is a tuple: (plugin, width, height, fmt, data)
Returns None if no cover is found. Returns None if no cover is found.
''' '''

View File

@ -94,7 +94,7 @@ class EditMetadataAction(InterfaceAction):
def bulk_metadata_downloaded(self, job): def bulk_metadata_downloaded(self, job):
if job.failed: if job.failed:
self.job_exception(job, dialog_title=_('Failed to download metadata')) self.gui.job_exception(job, dialog_title=_('Failed to download metadata'))
return return
from calibre.gui2.metadata.bulk_download2 import proceed from calibre.gui2.metadata.bulk_download2 import proceed
proceed(self.gui, job) proceed(self.gui, job)

View File

@ -54,6 +54,8 @@ def start_download(gui, ids, callback, identify, covers):
_('Download metadata for %d books')%len(ids), _('Download metadata for %d books')%len(ids),
download, (ids, gui.current_db, identify, covers), {}, callback) download, (ids, gui.current_db, identify, covers), {}, callback)
gui.job_manager.run_threaded_job(job) gui.job_manager.run_threaded_job(job)
gui.status_bar.show_message(_('Metadata download started'), 3000)
class ViewLog(QDialog): # {{{ class ViewLog(QDialog): # {{{
@ -110,11 +112,12 @@ class ApplyDialog(QDialog):
self.bb.accepted.connect(self.accept) self.bb.accepted.connect(self.accept)
l.addWidget(self.bb) l.addWidget(self.bb)
self.db = gui.current_db self.gui = gui
self.id_map = list(id_map.iteritems()) self.id_map = list(id_map.iteritems())
self.current_idx = 0 self.current_idx = 0
self.failures = [] self.failures = []
self.ids = []
self.canceled = False self.canceled = False
QTimer.singleShot(20, self.do_one) QTimer.singleShot(20, self.do_one)
@ -124,11 +127,13 @@ class ApplyDialog(QDialog):
if self.canceled: if self.canceled:
return return
i, mi = self.id_map[self.current_idx] i, mi = self.id_map[self.current_idx]
db = self.gui.current_db
try: try:
set_title = not mi.is_null('title') set_title = not mi.is_null('title')
set_authors = not mi.is_null('authors') set_authors = not mi.is_null('authors')
self.db.set_metadata(i, mi, commit=False, set_title=set_title, db.set_metadata(i, mi, commit=False, set_title=set_title,
set_authors=set_authors) set_authors=set_authors)
self.ids.append(i)
except: except:
import traceback import traceback
self.failures.append((i, traceback.format_exc())) self.failures.append((i, traceback.format_exc()))
@ -156,9 +161,10 @@ class ApplyDialog(QDialog):
return return
if self.failures: if self.failures:
msg = [] msg = []
db = self.gui.current_db
for i, tb in self.failures: for i, tb in self.failures:
title = self.db.title(i, index_is_id=True) title = db.title(i, index_is_id=True)
authors = self.db.authors(i, index_is_id=True) authors = db.authors(i, index_is_id=True)
if authors: if authors:
authors = [x.replace('|', ',') for x in authors.split(',')] authors = [x.replace('|', ',') for x in authors.split(',')]
title += ' - ' + authors_to_string(authors) title += ' - ' + authors_to_string(authors)
@ -169,6 +175,12 @@ class ApplyDialog(QDialog):
' in your library. Click "Show Details" to see ' ' in your library. Click "Show Details" to see '
'details.'), det_msg='\n\n'.join(msg), show=True) 'details.'), det_msg='\n\n'.join(msg), show=True)
self.accept() self.accept()
if self.ids:
cr = self.gui.library_view.currentIndex().row()
self.gui.library_view.model().refresh_ids(
self.ids, cr)
if self.gui.cover_flow:
self.gui.cover_flow.dataChanged()
_amd = None _amd = None
def apply_metadata(job, gui, q, result): def apply_metadata(job, gui, q, result):
@ -209,6 +221,7 @@ def apply_metadata(job, gui, q, result):
_amd = ApplyDialog(id_map, gui) _amd = ApplyDialog(id_map, gui)
def proceed(gui, job): def proceed(gui, job):
gui.status_bar.show_message(_('Metadata download completed'), 3000)
id_map, failed_ids = job.result id_map, failed_ids = job.result
fmsg = det_msg = '' fmsg = det_msg = ''
if failed_ids: if failed_ids:
@ -242,6 +255,10 @@ def merge_result(oldmi, newmi):
if (not newmi.is_null(f) and getattr(newmi, f) == getattr(oldmi, f)): if (not newmi.is_null(f) and getattr(newmi, f) == getattr(oldmi, f)):
setattr(newmi, f, getattr(dummy, f)) setattr(newmi, f, getattr(dummy, f))
newmi.last_modified = oldmi.last_modified
return newmi
def download(ids, db, do_identify, covers, def download(ids, db, do_identify, covers,
log=None, abort=None, notifications=None): log=None, abort=None, notifications=None):
ids = list(ids) ids = list(ids)
@ -271,9 +288,9 @@ def download(ids, db, do_identify, covers,
if covers: if covers:
cdata = download_cover(log, title=title, authors=authors, cdata = download_cover(log, title=title, authors=authors,
identifiers=identifiers) identifiers=identifiers)
if cdata: if cdata is not None:
with PersistentTemporaryFile('.jpg', 'downloaded-cover-') as f: with PersistentTemporaryFile('.jpg', 'downloaded-cover-') as f:
f.write(cdata) f.write(cdata[-1])
mi.cover = f.name mi.cover = f.name
ans[i] = mi ans[i] = mi
count += 1 count += 1

View File

@ -189,7 +189,11 @@ class ThreadedJobServer(Thread):
def run(self): def run(self):
while self.keep_going: while self.keep_going:
self.run_once() try:
self.run_once()
except:
import traceback
traceback.print_exc()
time.sleep(0.1) time.sleep(0.1)
def run_once(self): def run_once(self):