mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
722106531f
commit
59fdacad91
@ -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.identify import identify
|
||||
from calibre.ebooks.metadata.sources.covers import download_cover
|
||||
from calibre.ebooks.metadata.sources.update import patch_plugins
|
||||
|
||||
|
||||
def option_parser():
|
||||
@ -50,6 +51,7 @@ def main(args=sys.argv):
|
||||
buf = BytesIO()
|
||||
log = create_log(buf)
|
||||
abort = Event()
|
||||
patch_plugins()
|
||||
|
||||
authors = []
|
||||
if opts.authors:
|
||||
@ -92,6 +94,6 @@ def main(args=sys.argv):
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
||||
|
@ -1,27 +1,23 @@
|
||||
#!/usr/bin/env python2
|
||||
# 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__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
# License: GPLv3 Copyright: 2012, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
from threading import Event, Thread
|
||||
from Queue import Queue, Empty
|
||||
from io import BytesIO
|
||||
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.ebooks.metadata.sources.covers import (download_cover,
|
||||
run_download)
|
||||
from calibre.ebooks.metadata.book.base import Metadata
|
||||
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.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.ebooks.metadata.opf2 import metadata_to_opf, OPF
|
||||
|
||||
|
||||
def merge_result(oldmi, newmi, ensure_fields=None):
|
||||
@ -56,6 +52,7 @@ def main(do_identify, covers, metadata, ensure_fields, tdir):
|
||||
failed_covers = set()
|
||||
all_failed = True
|
||||
log = GUILog()
|
||||
patch_plugins()
|
||||
|
||||
for book_id, mi in metadata.iteritems():
|
||||
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):
|
||||
log = GUILog()
|
||||
patch_plugins()
|
||||
results = identify(log, Event(), title=title, authors=authors,
|
||||
identifiers=identifiers)
|
||||
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):
|
||||
patch_plugins()
|
||||
load_caches(caches)
|
||||
log = GUILog()
|
||||
results = Queue()
|
||||
@ -133,5 +132,3 @@ def single_covers(title, authors, identifiers, caches, tdir):
|
||||
os.mkdir(os.path.join(tdir, name+'.done'))
|
||||
|
||||
return log.dump()
|
||||
|
||||
|
||||
|
@ -110,6 +110,8 @@ class EditMetadataAction(InterfaceAction):
|
||||
db = self.gui.library_view.model().db
|
||||
ids = [db.id(row.row()) for row in rows]
|
||||
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,
|
||||
Dispatcher(self.metadata_downloaded),
|
||||
ensure_fields=ensure_fields)
|
||||
|
@ -476,6 +476,8 @@ class MetadataSingleDialogBase(QDialog):
|
||||
fw.setFocus(Qt.OtherFocusReason)
|
||||
|
||||
def fetch_metadata(self, *args):
|
||||
from calibre.ebooks.metadata.sources.update import update_sources
|
||||
update_sources()
|
||||
d = FullFetch(self.cover.pixmap(), self)
|
||||
ret = d.start(title=self.title.current_val, authors=self.authors.current_val,
|
||||
identifiers=self.identifiers.current_val)
|
||||
@ -516,6 +518,8 @@ class MetadataSingleDialogBase(QDialog):
|
||||
gui=gui, never_shutdown=True)
|
||||
|
||||
def download_cover(self, *args):
|
||||
from calibre.ebooks.metadata.sources.update import update_sources
|
||||
update_sources()
|
||||
from calibre.gui2.metadata.single_download import CoverFetch
|
||||
d = CoverFetch(self.cover.pixmap(), self)
|
||||
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
|
||||
d.deleteLater()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calibre.gui2 import Application as QApplication
|
||||
app = QApplication([])
|
||||
|
Loading…
x
Reference in New Issue
Block a user