diff --git a/src/calibre/gui2/store/amazon_plugin.py b/src/calibre/gui2/store/amazon_plugin.py index 18fd7bbe2c..00965f31e2 100644 --- a/src/calibre/gui2/store/amazon_plugin.py +++ b/src/calibre/gui2/store/amazon_plugin.py @@ -47,29 +47,38 @@ class AmazonKindleStore(StorePlugin): if 'kindle' not in type.lower(): continue - title = ''.join(data.xpath('div[@class="productTitle"]/a/text()')) - author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()')) - author = author.split('by')[-1] - price = ''.join(data.xpath('div[@class="newPrice"]/span/text()')) - # We must have an asin otherwise we can't easily reference the # book later. - asin = data.xpath('div[@class="productTitle"]/a[1]') - if asin: - asin = asin[0].get('href', '') - m = re.search(r'/dp/(?P.+?)(/|$)', asin) + asin_href = None + asin_a = data.xpath('div[@class="productTitle"]/a[1]') + if asin_a: + asin_href = asin_a[0].get('href', '') + m = re.search(r'/dp/(?P.+?)(/|$)', asin_href) if m: asin = m.group('asin') else: continue + else: + continue + + cover_url = '' + if asin_href: + cover_img = data.xpath('//div[@class="productImage"]/a[@href="%s"]/img/@src' % asin_href) + if cover_img: + cover_url = cover_img[0] + + title = ''.join(data.xpath('div[@class="productTitle"]/a/text()')) + author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()')) + author = author.split('by')[-1] + price = ''.join(data.xpath('div[@class="newPrice"]/span/text()')) - counter -= 1 - - s = SearchResult() - s.cover_url = '' - s.title = title.strip() - s.author = author.strip() - s.price = price.strip() - s.detail_item = '/detail/' + asin.strip() - - yield s + counter -= 1 + + s = SearchResult() + s.cover_url = cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price.strip() + s.detail_item = '/detail/' + asin.strip() + + yield s diff --git a/src/calibre/gui2/store/gutenberg_plugin.py b/src/calibre/gui2/store/gutenberg_plugin.py index a039ae2c66..8d7649f814 100644 --- a/src/calibre/gui2/store/gutenberg_plugin.py +++ b/src/calibre/gui2/store/gutenberg_plugin.py @@ -52,7 +52,7 @@ class GutenbergStore(StorePlugin): id = url.split('/')[-1] heading = ''.join(url_a.xpath('text()')) - title, _, author = heading.partition('by') + title, _, author = heading.partition('by ') author = author.split('-')[0] price = '$0.00' diff --git a/src/calibre/gui2/store/manybooks_plugin.py b/src/calibre/gui2/store/manybooks_plugin.py index 3f85c6bec3..807f8fe562 100644 --- a/src/calibre/gui2/store/manybooks_plugin.py +++ b/src/calibre/gui2/store/manybooks_plugin.py @@ -56,7 +56,7 @@ class ManyBooksStore(StorePlugin): id = id.strip() heading = ''.join(url_a.xpath('text()')) - title, _, author = heading.partition('by') + title, _, author = heading.partition('by ') author = author.split('-')[0] price = '$0.00' diff --git a/src/calibre/gui2/store/smashwords_plugin.py b/src/calibre/gui2/store/smashwords_plugin.py index 5b84ce58ad..31bce64398 100644 --- a/src/calibre/gui2/store/smashwords_plugin.py +++ b/src/calibre/gui2/store/smashwords_plugin.py @@ -4,6 +4,7 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' +import random import re import urllib2 from contextlib import closing @@ -22,7 +23,11 @@ class SmashwordsStore(StorePlugin): def open(self, gui, parent=None, detail_item=None): from calibre.gui2.store.web_store_dialog import WebStoreDialog - d = WebStoreDialog(gui, 'http://www.smashwords.com/?ref=usernone', parent, detail_item) + aff_id = 'usernone' + # Use Kovid's affiliate id 30% of the time. + if random.randint(1, 10) in (1, 2, 3): + aff_id = 'kovidgoyal' + d = WebStoreDialog(gui, 'http://www.smashwords.com/?ref=%s' % aff_id, parent, detail_item) d.setWindowTitle(self.name) d.set_tags(self.name + ',' + _('store')) d = d.exec_()