From ea2d72c2b93717a842c30ffa90215add4844042c Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 18 Feb 2012 12:44:28 -0500 Subject: [PATCH 1/5] Store: Fix price detection for Google Books. --- .../gui2/store/stores/google_books_plugin.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/store/stores/google_books_plugin.py b/src/calibre/gui2/store/stores/google_books_plugin.py index a04ea45ebb..60b78e3f7d 100644 --- a/src/calibre/gui2/store/stores/google_books_plugin.py +++ b/src/calibre/gui2/store/stores/google_books_plugin.py @@ -93,16 +93,13 @@ class GoogleBooksStore(BasicStoreConfig, StorePlugin): search_result.cover_url = ''.join(doc.xpath('//div[@class="sidebarcover"]//img/@src')) # Try to get the set price. - price = ''.join(doc.xpath('//div[@class="buy-price-container"]/span[contains(@class, "buy-price")]/text()')) - # Try to get the price inside of a buy button. - if not price.strip(): - price = ''.join(doc.xpath('//div[@class="buy-container"]/a/text()')) - price = price.split('-')[-1] - if 'view' in price.lower(): + price = ''.join(doc.xpath('//div[@id="gb-get-book-container"]//a/text()')) + if 'read' in price.lower(): price = 'Unknown' - # No price set for this book. - if not price.strip(): + elif 'free' in price.lower() or not price.strip(): price = '$0.00' + elif '-' in price: + a, b, price = price.partition(' - ') search_result.price = price.strip() search_result.formats = ', '.join(doc.xpath('//div[contains(@class, "download-panel-div")]//a/text()')).upper() From 1bcae76a612ec56ecd97f7bb9d959c49b3fd0a5c Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 18 Feb 2012 13:05:48 -0500 Subject: [PATCH 2/5] Store: Fix Baen. Rename Baen to its new name. --- src/calibre/customize/builtins.py | 2 +- .../gui2/store/stores/baen_webscription_plugin.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 855d105e15..8276c50087 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1217,7 +1217,7 @@ class StoreArchiveOrgStore(StoreBase): formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT'] class StoreBaenWebScriptionStore(StoreBase): - name = 'Baen WebScription' + name = 'Baen Ebooks' description = u'Sci-Fi & Fantasy brought to you by Jim Baen.' actual_plugin = 'calibre.gui2.store.stores.baen_webscription_plugin:BaenWebScriptionStore' diff --git a/src/calibre/gui2/store/stores/baen_webscription_plugin.py b/src/calibre/gui2/store/stores/baen_webscription_plugin.py index 5be7e9c161..a2a4e63d74 100644 --- a/src/calibre/gui2/store/stores/baen_webscription_plugin.py +++ b/src/calibre/gui2/store/stores/baen_webscription_plugin.py @@ -24,7 +24,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog class BaenWebScriptionStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): - url = 'http://www.webscription.net/' + url = 'http://www.baenebooks.com/' if external or self.config.get('open_external', False): if detail_item: @@ -40,19 +40,19 @@ class BaenWebScriptionStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.webscription.net/searchadv.aspx?IsSubmit=true&SearchTerm=' + urllib2.quote(query) + url = 'http://www.baenebooks.com/searchadv.aspx?IsSubmit=true&SearchTerm=' + urllib2.quote(query) br = browser() counter = max_results with closing(br.open(url, timeout=timeout)) as f: doc = html.fromstring(f.read()) - for data in doc.xpath('//table/tr/td/img[@src="skins/Skin_1/images/matchingproducts.gif"]/..//tr'): + for data in doc.xpath('//table//table//table//table//tr'): if counter <= 0: break id = ''.join(data.xpath('./td[1]/a/@href')) - if not id: + if not id or not id.startswith('p-'): continue title = ''.join(data.xpath('./td[1]/a/text()')) @@ -61,7 +61,7 @@ class BaenWebScriptionStore(BasicStoreConfig, StorePlugin): cover_url = '' price = '' - with closing(br.open('http://www.webscription.net/' + id.strip(), timeout=timeout/4)) as nf: + with closing(br.open('http://www.baenebooks.com/' + id.strip(), timeout=timeout/4)) as nf: idata = html.fromstring(nf.read()) author = ''.join(idata.xpath('//span[@class="ProductNameText"]/../b/text()')) author = author.split('by ')[-1] @@ -74,7 +74,7 @@ class BaenWebScriptionStore(BasicStoreConfig, StorePlugin): if mo: pnum = mo.group('num') if pnum: - cover_url = 'http://www.webscription.net/' + ''.join(idata.xpath('//img[@id="ProductPic%s"]/@src' % pnum)) + cover_url = 'http://www.baenebooks.com/' + ''.join(idata.xpath('//img[@id="ProductPic%s"]/@src' % pnum)) counter -= 1 From bb93eecbe7e6ac11a803b958fec11b0b57be7ccd Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 18 Feb 2012 13:25:37 -0500 Subject: [PATCH 3/5] Store: Fix OReilly. --- .../gui2/store/stores/oreilly_plugin.py | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/calibre/gui2/store/stores/oreilly_plugin.py b/src/calibre/gui2/store/stores/oreilly_plugin.py index b03fdf19e7..4ec25ef5f4 100644 --- a/src/calibre/gui2/store/stores/oreilly_plugin.py +++ b/src/calibre/gui2/store/stores/oreilly_plugin.py @@ -26,9 +26,6 @@ class OReillyStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): url = 'http://oreilly.com/ebooks/' - if detail_item: - detail_item = 'https://epoch.oreilly.com/shop/cart.orm?prod=%s.EBOOK&p=CALIBRE' % detail_item - if external or self.config.get('open_external', False): open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url))) else: @@ -49,11 +46,11 @@ class OReillyStore(BasicStoreConfig, StorePlugin): if counter <= 0: break - full_id = ''.join(data.xpath('./div[@class="book_text"]//p[@class="title"]/a/@href')) - mo = re.search('\d+', full_id) - if not mo: + ebook = ' '.join(data.xpath('.//p[@class="note"]/text()')) + if 'ebook' not in ebook.lower(): continue - id = mo.group() + + id = ''.join(data.xpath('./div[@class="book_text"]//p[@class="title"]/a/@href')) cover_url = ''.join(data.xpath('./a/img[1]/@src')) @@ -62,16 +59,14 @@ class OReillyStore(BasicStoreConfig, StorePlugin): author = author.split('By ')[-1].strip() # Get the detail here because we need to get the ebook id for the detail_item. - with closing(br.open(full_id, timeout=timeout)) as nf: + with closing(br.open(id, timeout=timeout)) as nf: idoc = html.fromstring(nf.read()) - price = ''.join(idoc.xpath('(//span[@class="price"])[1]/span//text()')) - formats = ', '.join(idoc.xpath('//div[@class="ebook_formats"]//a/text()')) - - eid = ''.join(idoc.xpath('(//a[@class="product_buy_link" and contains(@href, ".EBOOK")])[1]/@href')).strip() - mo = re.search('\d+', eid) - if mo: - id = mo.group() + for td in idoc.xpath('//td[@class="optionsTd"]'): + if 'ebook' in ''.join(td.xpath('.//text()')).lower(): + price = ''.join(td.xpath('.//span[@class="price"]/text()')).strip() + formats = ''.join(td.xpath('.//a[@id="availableFormats"]/text()')).strip() + break counter -= 1 From 6e2fb2f1e6acea14702ae6190d20b3e4c07d3f64 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 19 Feb 2012 00:14:43 +0530 Subject: [PATCH 4/5] Fix #935234 (Resize image can choose zero size for small values) --- src/calibre/ebooks/oeb/transforms/rescale.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/ebooks/oeb/transforms/rescale.py b/src/calibre/ebooks/oeb/transforms/rescale.py index d73205709b..e984fad38a 100644 --- a/src/calibre/ebooks/oeb/transforms/rescale.py +++ b/src/calibre/ebooks/oeb/transforms/rescale.py @@ -48,6 +48,8 @@ class RescaleImages(object): scaled, new_width, new_height = fit_image(width, height, page_width, page_height) if scaled: + new_width = max(1, new_width) + new_height = max(1, new_height) self.log('Rescaling image from %dx%d to %dx%d'%( width, height, new_width, new_height), item.href) try: From 826a014d595210bc514968cd2239c4f6c82012d3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 19 Feb 2012 10:09:17 +0530 Subject: [PATCH 5/5] ... --- src/calibre/gui2/tag_browser/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index c649361272..89b42950e0 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -836,7 +836,7 @@ class TagsModel(QAbstractItemModel): # {{{ deforder = y.get('*', 100) order = defaultdict(lambda : deforder) order.update(y) - tb_keys = sorted(tb_categories.iterkeys(), key=lambda x: order[x]) + tb_keys = sorted(tb_categories.iterkeys(), key=order.get) for category in tb_keys: if category in data: # The search category can come and go self.row_map.append(category)