Wire up the metadata source plugin live updates

Updates are kicked off when the user uses either the single or bulk
download metadata tools in the GUI.
This commit is contained in:
Kovid Goyal 2017-03-01 14:44:44 +05:30
parent 722106531f
commit 59fdacad91
4 changed files with 24 additions and 18 deletions

View File

@ -19,6 +19,7 @@ from calibre.ebooks.metadata.opf2 import metadata_to_opf
from calibre.ebooks.metadata.sources.base import create_log from calibre.ebooks.metadata.sources.base import create_log
from calibre.ebooks.metadata.sources.identify import identify from calibre.ebooks.metadata.sources.identify import identify
from calibre.ebooks.metadata.sources.covers import download_cover from calibre.ebooks.metadata.sources.covers import download_cover
from calibre.ebooks.metadata.sources.update import patch_plugins
def option_parser(): def option_parser():
@ -50,6 +51,7 @@ def main(args=sys.argv):
buf = BytesIO() buf = BytesIO()
log = create_log(buf) log = create_log(buf)
abort = Event() abort = Event()
patch_plugins()
authors = [] authors = []
if opts.authors: if opts.authors:
@ -92,6 +94,6 @@ def main(args=sys.argv):
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

View File

@ -1,27 +1,23 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import (unicode_literals, division, absolute_import, # License: GPLv3 Copyright: 2012, Kovid Goyal <kovid at kovidgoyal.net>
print_function) from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os import os
from threading import Event, Thread
from Queue import Queue, Empty
from io import BytesIO
from collections import Counter from collections import Counter
from io import BytesIO
from Queue import Empty, Queue
from threading import Event, Thread
from calibre.utils.date import as_utc
from calibre.ebooks.metadata.sources.identify import identify, msprefs
from calibre.ebooks.metadata.book.base import Metadata
from calibre.customize.ui import metadata_plugins from calibre.customize.ui import metadata_plugins
from calibre.ebooks.metadata.sources.covers import (download_cover, from calibre.ebooks.metadata.book.base import Metadata
run_download) from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf
from calibre.ebooks.metadata.sources.base import dump_caches, load_caches from calibre.ebooks.metadata.sources.base import dump_caches, load_caches
from calibre.ebooks.metadata.sources.covers import download_cover, run_download
from calibre.ebooks.metadata.sources.identify import identify, msprefs
from calibre.ebooks.metadata.sources.update import patch_plugins
from calibre.utils.date import as_utc
from calibre.utils.logging import GUILog from calibre.utils.logging import GUILog
from calibre.ebooks.metadata.opf2 import metadata_to_opf, OPF
def merge_result(oldmi, newmi, ensure_fields=None): def merge_result(oldmi, newmi, ensure_fields=None):
@ -56,6 +52,7 @@ def main(do_identify, covers, metadata, ensure_fields, tdir):
failed_covers = set() failed_covers = set()
all_failed = True all_failed = True
log = GUILog() log = GUILog()
patch_plugins()
for book_id, mi in metadata.iteritems(): for book_id, mi in metadata.iteritems():
mi = OPF(BytesIO(mi), basedir=tdir, mi = OPF(BytesIO(mi), basedir=tdir,
@ -102,6 +99,7 @@ def main(do_identify, covers, metadata, ensure_fields, tdir):
def single_identify(title, authors, identifiers): def single_identify(title, authors, identifiers):
log = GUILog() log = GUILog()
patch_plugins()
results = identify(log, Event(), title=title, authors=authors, results = identify(log, Event(), title=title, authors=authors,
identifiers=identifiers) identifiers=identifiers)
return [metadata_to_opf(r) for r in results], [r.has_cached_cover_url for return [metadata_to_opf(r) for r in results], [r.has_cached_cover_url for
@ -109,6 +107,7 @@ def single_identify(title, authors, identifiers):
def single_covers(title, authors, identifiers, caches, tdir): def single_covers(title, authors, identifiers, caches, tdir):
patch_plugins()
load_caches(caches) load_caches(caches)
log = GUILog() log = GUILog()
results = Queue() results = Queue()
@ -133,5 +132,3 @@ def single_covers(title, authors, identifiers, caches, tdir):
os.mkdir(os.path.join(tdir, name+'.done')) os.mkdir(os.path.join(tdir, name+'.done'))
return log.dump() return log.dump()

View File

@ -110,6 +110,8 @@ class EditMetadataAction(InterfaceAction):
db = self.gui.library_view.model().db db = self.gui.library_view.model().db
ids = [db.id(row.row()) for row in rows] ids = [db.id(row.row()) for row in rows]
from calibre.gui2.metadata.bulk_download import start_download from calibre.gui2.metadata.bulk_download import start_download
from calibre.ebooks.metadata.sources.update import update_sources
update_sources()
start_download(self.gui, ids, start_download(self.gui, ids,
Dispatcher(self.metadata_downloaded), Dispatcher(self.metadata_downloaded),
ensure_fields=ensure_fields) ensure_fields=ensure_fields)

View File

@ -476,6 +476,8 @@ class MetadataSingleDialogBase(QDialog):
fw.setFocus(Qt.OtherFocusReason) fw.setFocus(Qt.OtherFocusReason)
def fetch_metadata(self, *args): def fetch_metadata(self, *args):
from calibre.ebooks.metadata.sources.update import update_sources
update_sources()
d = FullFetch(self.cover.pixmap(), self) d = FullFetch(self.cover.pixmap(), self)
ret = d.start(title=self.title.current_val, authors=self.authors.current_val, ret = d.start(title=self.title.current_val, authors=self.authors.current_val,
identifiers=self.identifiers.current_val) identifiers=self.identifiers.current_val)
@ -516,6 +518,8 @@ class MetadataSingleDialogBase(QDialog):
gui=gui, never_shutdown=True) gui=gui, never_shutdown=True)
def download_cover(self, *args): def download_cover(self, *args):
from calibre.ebooks.metadata.sources.update import update_sources
update_sources()
from calibre.gui2.metadata.single_download import CoverFetch from calibre.gui2.metadata.single_download import CoverFetch
d = CoverFetch(self.cover.pixmap(), self) d = CoverFetch(self.cover.pixmap(), self)
ret = d.start(self.title.current_val, self.authors.current_val, ret = d.start(self.title.current_val, self.authors.current_val,
@ -1141,6 +1145,7 @@ def edit_metadata(db, row_list, current_row, parent=None, view_slot=None,
# possible workaround for bug reports of occasional ghost edit metadata dialog on windows # possible workaround for bug reports of occasional ghost edit metadata dialog on windows
d.deleteLater() d.deleteLater()
if __name__ == '__main__': if __name__ == '__main__':
from calibre.gui2 import Application as QApplication from calibre.gui2 import Application as QApplication
app = QApplication([]) app = QApplication([])