From dbf36e96e7144f2cea9895ac81b7bcb3a1f5d222 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 20 Dec 2015 10:37:57 +0530 Subject: [PATCH] Handle data URLs for covers in Get Books results --- src/calibre/gui2/store/search/download_thread.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/store/search/download_thread.py b/src/calibre/gui2/store/search/download_thread.py index 3781496bf0..90e760af4c 100644 --- a/src/calibre/gui2/store/search/download_thread.py +++ b/src/calibre/gui2/store/search/download_thread.py @@ -6,7 +6,7 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import traceback +import traceback, base64 from contextlib import closing from threading import Thread from Queue import Queue @@ -139,6 +139,8 @@ class CoverThreadPool(GenericDownloadThreadPool): self.tasks.put((search_result, update_callback, timeout)) GenericDownloadThreadPool.add_task(self) +def decode_data_url(url): + return base64.standard_b64decode(url.partition(',')[2]) class CoverThread(Thread): @@ -159,8 +161,11 @@ class CoverThread(Thread): try: result, callback, timeout = self.tasks.get() if result and result.cover_url: - with closing(self.br.open(result.cover_url, timeout=timeout)) as f: - result.cover_data = f.read() + if result.cover_url.startswith('data:'): + result.cover_data = decode_data_url(result.cover_url) + else: + with closing(self.br.open(result.cover_url, timeout=timeout)) as f: + result.cover_data = f.read() result.cover_data = scale_image(result.cover_data, 64, 64)[2] callback() self.tasks.task_done()