Cover download from google and amazon tested

This commit is contained in:
Kovid Goyal 2011-03-23 16:41:54 -06:00
parent 3b15681840
commit e0dc4e0998
3 changed files with 40 additions and 2 deletions

11
recipes/planet_kde.recipe Normal file
View File

@ -0,0 +1,11 @@
from calibre.web.feeds.news import AutomaticNewsRecipe
class BasicUserRecipe1300864518(AutomaticNewsRecipe):
title = u'KDE News'
language = 'en'
__author__ = 'Riccardo Iaconelli'
oldest_article = 10
max_articles_per_feed = 100
feeds = [(u'Planet KDE', u'http://planetkde.org/rss20.xml'), (u'Got the Dot?', u'http://dot.kde.org/rss.xml')]

View File

@ -230,7 +230,7 @@ class GoogleBooks(Source):
# When no cover is present, returns a PNG saying image not available
# Try for example google identifier llNqPwAACAAJ
# I have yet to see an actual cover in PNG format
return raw and len(raw) > 17000 and raw[1:4] != 'PNG'
return raw and len(raw) > 17000 and raw[1:4] != b'PNG'
def get_all_details(self, br, log, entries, abort, result_queue, timeout):
for relevance, i in enumerate(entries):

View File

@ -12,7 +12,7 @@ from Queue import Queue, Empty
from threading import Event
from calibre.customize.ui import metadata_plugins
from calibre import prints
from calibre import prints, sanitize_file_name2
from calibre.ebooks.metadata import check_isbn
from calibre.ebooks.metadata.sources.base import create_log
@ -124,7 +124,34 @@ def test_identify_plugin(name, tests):
if results[0] is not possibles[0]:
prints('Most relevant result failed the tests')
raise SystemExit(1)
if 'cover' in plugin.capabilities:
rq = Queue()
mi = results[0]
plugin.download_cover(log, rq, abort, title=mi.title,
authors=mi.authors, identifiers=mi.identifiers)
results = []
while True:
try:
results.append(rq.get_nowait())
except Empty:
break
if not results:
prints('Cover download failed')
raise SystemExit(1)
cdata = results[0]
cover = os.path.join(tdir, plugin.name.replace(' ',
'')+'-%s-cover.jpg'%sanitize_file_name2(mi.title.replace(' ',
'_')))
with open(cover, 'wb') as f:
f.write(cdata)
prints('Cover downloaded to:', cover)
if len(cdata) < 10240:
prints('Downloaded cover too small')
raise SystemExit(1)
prints('Average time per query', sum(times)/len(times))