From e0dc4e099880359b99f1b7b131a15779806955a6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Mar 2011 16:41:54 -0600 Subject: [PATCH] Cover download from google and amazon tested --- recipes/planet_kde.recipe | 11 +++++++ src/calibre/ebooks/metadata/sources/google.py | 2 +- src/calibre/ebooks/metadata/sources/test.py | 29 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 recipes/planet_kde.recipe diff --git a/recipes/planet_kde.recipe b/recipes/planet_kde.recipe new file mode 100644 index 0000000000..8345fdde38 --- /dev/null +++ b/recipes/planet_kde.recipe @@ -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')] + diff --git a/src/calibre/ebooks/metadata/sources/google.py b/src/calibre/ebooks/metadata/sources/google.py index 9677027662..4d61fdc7ab 100644 --- a/src/calibre/ebooks/metadata/sources/google.py +++ b/src/calibre/ebooks/metadata/sources/google.py @@ -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): diff --git a/src/calibre/ebooks/metadata/sources/test.py b/src/calibre/ebooks/metadata/sources/test.py index 3419a91d31..d4344c7f49 100644 --- a/src/calibre/ebooks/metadata/sources/test.py +++ b/src/calibre/ebooks/metadata/sources/test.py @@ -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))