Enable the Google Images cover download plugin

This commit is contained in:
Kovid Goyal 2013-04-06 09:58:43 +05:30
parent 279013573a
commit f491ff67cc
3 changed files with 9 additions and 7 deletions

View File

@ -757,9 +757,9 @@ from calibre.ebooks.metadata.sources.isbndb import ISBNDB
from calibre.ebooks.metadata.sources.overdrive import OverDrive from calibre.ebooks.metadata.sources.overdrive import OverDrive
from calibre.ebooks.metadata.sources.douban import Douban from calibre.ebooks.metadata.sources.douban import Douban
from calibre.ebooks.metadata.sources.ozon import Ozon from calibre.ebooks.metadata.sources.ozon import Ozon
# from calibre.ebooks.metadata.sources.google_images import GoogleImages from calibre.ebooks.metadata.sources.google_images import GoogleImages
plugins += [GoogleBooks, Amazon, Edelweiss, OpenLibrary, ISBNDB, OverDrive, Douban, Ozon] plugins += [GoogleBooks, GoogleImages, Amazon, Edelweiss, OpenLibrary, ISBNDB, OverDrive, Douban, Ozon]
# }}} # }}}

View File

@ -18,12 +18,13 @@ from calibre.utils.magick.draw import Image, save_cover_data_to
class Worker(Thread): class Worker(Thread):
def __init__(self, plugin, abort, title, authors, identifiers, timeout, rq): def __init__(self, plugin, abort, title, authors, identifiers, timeout, rq, get_best_cover=False):
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
self.plugin = plugin self.plugin = plugin
self.abort = abort self.abort = abort
self.get_best_cover = get_best_cover
self.buf = BytesIO() self.buf = BytesIO()
self.log = create_log(self.buf) self.log = create_log(self.buf)
self.title, self.authors, self.identifiers = (title, authors, self.title, self.authors, self.identifiers = (title, authors,
@ -37,7 +38,7 @@ class Worker(Thread):
try: try:
if self.plugin.can_get_multiple_covers: if self.plugin.can_get_multiple_covers:
self.plugin.download_cover(self.log, self.rq, self.abort, self.plugin.download_cover(self.log, self.rq, self.abort,
title=self.title, authors=self.authors, get_best_cover=True, title=self.title, authors=self.authors, get_best_cover=self.get_best_cover,
identifiers=self.identifiers, timeout=self.timeout) identifiers=self.identifiers, timeout=self.timeout)
else: else:
self.plugin.download_cover(self.log, self.rq, self.abort, self.plugin.download_cover(self.log, self.rq, self.abort,
@ -72,7 +73,7 @@ def process_result(log, result):
return (plugin, width, height, fmt, data) return (plugin, width, height, fmt, data)
def run_download(log, results, abort, def run_download(log, results, abort,
title=None, authors=None, identifiers={}, timeout=30): title=None, authors=None, identifiers={}, timeout=30, get_best_cover=False):
''' '''
Run the cover download, putting results into the queue :param:`results`. Run the cover download, putting results into the queue :param:`results`.
@ -89,7 +90,7 @@ def run_download(log, results, abort,
plugins = [p for p in metadata_plugins(['cover']) if p.is_configured()] plugins = [p for p in metadata_plugins(['cover']) if p.is_configured()]
rq = Queue() rq = Queue()
workers = [Worker(p, abort, title, authors, identifiers, timeout, rq) for p workers = [Worker(p, abort, title, authors, identifiers, timeout, rq, get_best_cover=get_best_cover) for p
in plugins] in plugins]
for w in workers: for w in workers:
w.start() w.start()
@ -163,7 +164,7 @@ def download_cover(log,
abort = Event() abort = Event()
run_download(log, rq, abort, title=title, authors=authors, run_download(log, rq, abort, title=title, authors=authors,
identifiers=identifiers, timeout=timeout) identifiers=identifiers, timeout=timeout, get_best_cover=True)
results = [] results = []

View File

@ -51,6 +51,7 @@ class GoogleImages(Source):
urls = urls[:self.prefs['max_covers']] urls = urls[:self.prefs['max_covers']]
if get_best_cover: if get_best_cover:
urls = urls[:1] urls = urls[:1]
log('Downloading %d covers'%len(urls))
workers = [Thread(target=self.download_image, args=(url, timeout, log, result_queue)) for url in urls] workers = [Thread(target=self.download_image, args=(url, timeout, log, result_queue)) for url in urls]
for w in workers: for w in workers:
w.daemon = True w.daemon = True