mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle data URLs for covers in Get Books results
This commit is contained in:
parent
21346e3e20
commit
dbf36e96e7
@ -6,7 +6,7 @@ __license__ = 'GPL 3'
|
||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||
__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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user