From a1cdfeb4ba3f1573c311452baf0a8f0223281fc9 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 26 Feb 2011 21:15:54 -0500 Subject: [PATCH] Construct manybooks cover url instead of parsing it as manybooks is very slow. --- src/calibre/gui2/store/amazon_plugin.py | 2 +- src/calibre/gui2/store/feedbooks_plugin.py | 2 +- src/calibre/gui2/store/gutenberg_plugin.py | 2 +- src/calibre/gui2/store/manybooks_plugin.py | 21 +++++++++++---------- src/calibre/gui2/store/web_control.py | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/calibre/gui2/store/amazon_plugin.py b/src/calibre/gui2/store/amazon_plugin.py index d3ab7c8911..ab6fdce8d8 100644 --- a/src/calibre/gui2/store/amazon_plugin.py +++ b/src/calibre/gui2/store/amazon_plugin.py @@ -24,7 +24,7 @@ class AmazonKindleStore(StorePlugin): def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog d = WebStoreDialog(gui, self.ASTORE_URL, parent, detail_item) - d.setWindowTitle('Amazon Kindle Store') + d.setWindowTitle(self.name) d = d.exec_() def search(self, query, max_results=10, timeout=60): diff --git a/src/calibre/gui2/store/feedbooks_plugin.py b/src/calibre/gui2/store/feedbooks_plugin.py index 2be8576515..5c5d430a05 100644 --- a/src/calibre/gui2/store/feedbooks_plugin.py +++ b/src/calibre/gui2/store/feedbooks_plugin.py @@ -22,7 +22,7 @@ class FeedbooksStore(StorePlugin): def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog d = WebStoreDialog(gui, 'http://m.feedbooks.com/', parent, detail_item) - d.setWindowTitle('Feedbooks') + d.setWindowTitle(self.name) d = d.exec_() def search(self, query, max_results=10, timeout=60): diff --git a/src/calibre/gui2/store/gutenberg_plugin.py b/src/calibre/gui2/store/gutenberg_plugin.py index 5d55844180..6917165474 100644 --- a/src/calibre/gui2/store/gutenberg_plugin.py +++ b/src/calibre/gui2/store/gutenberg_plugin.py @@ -22,7 +22,7 @@ class GutenbergStore(StorePlugin): def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog d = WebStoreDialog(gui, 'http://m.gutenberg.org/', parent, detail_item) - d.setWindowTitle('Project Gutenberg') + d.setWindowTitle(self.name) d = d.exec_() def search(self, query, max_results=10, timeout=60): diff --git a/src/calibre/gui2/store/manybooks_plugin.py b/src/calibre/gui2/store/manybooks_plugin.py index 9a45ddc5b4..1d68dc774b 100644 --- a/src/calibre/gui2/store/manybooks_plugin.py +++ b/src/calibre/gui2/store/manybooks_plugin.py @@ -4,6 +4,7 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' +import re import urllib2 from contextlib import closing @@ -22,7 +23,7 @@ class ManyBooksStore(StorePlugin): def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog d = WebStoreDialog(gui, 'http://manybooks.net/', parent, detail_item) - d.setWindowTitle('ManyBooks') + d.setWindowTitle(self.name) d = d.exec_() def search(self, query, max_results=10, timeout=60): @@ -51,6 +52,7 @@ class ManyBooksStore(StorePlugin): if '/titles/' not in url: continue id = url.split('/')[-1] + id = id.strip() heading = ''.join(url_a.xpath('text()')) title, _, author = heading.partition('by') @@ -58,14 +60,13 @@ class ManyBooksStore(StorePlugin): price = '$0.00' cover_url = '' - with closing(br.open('http://manybooks.net/titles/%s' % id.strip(), timeout=timeout)) as f_i: - doc_i = html.fromstring(f_i.read()) - for img in doc_i.xpath('//img'): - src = img.get('src', None) - if src and src.endswith('-thumb.jpg'): - cover_url = src - print cover_url - + mo = re.match('^\D+', id) + if mo: + cover_name = mo.group() + cover_name = cover_name.replace('etext', '') + cover_id = id.split('.')[0] + cover_url = 'http://manybooks_images.s3.amazonaws.com/original_covers/' + id[0] + '/' + cover_name + '/' + cover_id + '-thumb.jpg' + counter -= 1 s = SearchResult() @@ -73,6 +74,6 @@ class ManyBooksStore(StorePlugin): s.title = title.strip() s.author = author.strip() s.price = price.strip() - s.detail_item = '/titles/' + id.strip() + s.detail_item = '/titles/' + id yield s diff --git a/src/calibre/gui2/store/web_control.py b/src/calibre/gui2/store/web_control.py index d679d2d45d..bd8efbe588 100644 --- a/src/calibre/gui2/store/web_control.py +++ b/src/calibre/gui2/store/web_control.py @@ -11,7 +11,7 @@ from PyQt4.Qt import QWebView, QWebPage, QNetworkCookieJar, QNetworkRequest, QSt from calibre import USER_AGENT class NPWebView(QWebView): - + def __init__(self, *args): QWebView.__init__(self, *args) self.gui = None