From bd456d1b860f02c312570586053c9f119997ee91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Wed, 31 Jul 2013 16:53:27 +0200 Subject: [PATCH 1/4] add unicode_literals in koobe plugin --- src/calibre/gui2/store/stores/koobe_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py index 52bdd41e54..b8b7386593 100644 --- a/src/calibre/gui2/store/stores/koobe_plugin.py +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import (division, absolute_import, print_function) +from __future__ import (unicode_literals, division, absolute_import, print_function) store_version = 3 # Needed for dynamic plugin loading __license__ = 'GPL 3' From ed9e3ab4368965904cf64450c6175d27659bb54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Fri, 2 Aug 2013 23:34:11 +0200 Subject: [PATCH 2/4] move format detection to get_details() --- src/calibre/gui2/store/stores/cdp_plugin.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/store/stores/cdp_plugin.py b/src/calibre/gui2/store/stores/cdp_plugin.py index 738ee5e3d5..1aacd23d00 100644 --- a/src/calibre/gui2/store/stores/cdp_plugin.py +++ b/src/calibre/gui2/store/stores/cdp_plugin.py @@ -62,11 +62,6 @@ class CdpStore(BasicStoreConfig, StorePlugin): author = ''.join(data.xpath('.//div[@class="product-description"]//ul[@class="taxons"]/li[2]/a/text()')) price = ''.join(data.xpath('.//span[@itemprop="price"]/text()')) - with closing(br.open(id.strip(), timeout=timeout/4)) as nf: - idata = html.fromstring(nf.read()) - formats = ', '.join(idata.xpath('//div[@id="product-bonus"]/div/ul/li/text()')) - - counter -= 1 s = SearchResult() @@ -76,9 +71,16 @@ class CdpStore(BasicStoreConfig, StorePlugin): s.price = price s.detail_item = id.strip() s.drm = SearchResult.DRM_UNLOCKED - s.formats = formats.upper() yield s if not doc.xpath('//span[@class="next"]/a'): break page+=1 + + def get_details(self, search_result, timeout): + br = browser() + with closing(br.open(search_result.detail_item, timeout=timeout)) as nf: + idata = html.fromstring(nf.read()) + formats = ', '.join(idata.xpath('//div[@id="product-bonus"]/div/ul/li/text()')) + search_result.formats = formats.upper() + return True From 1c7a229ebca9a093e338a84c48fb85b76040c4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sat, 3 Aug 2013 00:13:02 +0200 Subject: [PATCH 3/4] bump up plugin version --- src/calibre/gui2/store/stores/cdp_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/store/stores/cdp_plugin.py b/src/calibre/gui2/store/stores/cdp_plugin.py index 1aacd23d00..4e696f822f 100644 --- a/src/calibre/gui2/store/stores/cdp_plugin.py +++ b/src/calibre/gui2/store/stores/cdp_plugin.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import (unicode_literals, division, absolute_import, print_function) -store_version = 1 # Needed for dynamic plugin loading +store_version = 2 # Needed for dynamic plugin loading __license__ = 'GPL 3' __copyright__ = '2013, Tomasz Długosz ' From 8f1bf67ada75a1c7d28f0ca43fc1ea1793c63aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sat, 3 Aug 2013 00:20:35 +0200 Subject: [PATCH 4/4] move format and DRM status detection to get_details() --- .../gui2/store/stores/legimi_plugin.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/calibre/gui2/store/stores/legimi_plugin.py b/src/calibre/gui2/store/stores/legimi_plugin.py index 1195866faa..0af9220f75 100644 --- a/src/calibre/gui2/store/stores/legimi_plugin.py +++ b/src/calibre/gui2/store/stores/legimi_plugin.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import (unicode_literals, division, absolute_import, print_function) -store_version = 2 # Needed for dynamic plugin loading +store_version = 3 # Needed for dynamic plugin loading __license__ = 'GPL 3' __copyright__ = '2011-2013, Tomasz Długosz ' @@ -45,7 +45,6 @@ class LegimiStore(BasicStoreConfig, StorePlugin): url = 'http://www.legimi.com/pl/ebooki/?szukaj=' + urllib.quote_plus(query) br = browser() - drm_pattern = re.compile("zabezpieczona DRM") counter = max_results with closing(br.open(url, timeout=timeout)) as f: @@ -62,14 +61,6 @@ class LegimiStore(BasicStoreConfig, StorePlugin): title = ''.join(data.xpath('.//span[@class="bookListTitle ellipsis"]/text()')) author = ''.join(data.xpath('.//span[@class="bookListAuthor ellipsis"]/text()')) price = ''.join(data.xpath('.//div[@class="bookListPrice"]/span/text()')) - formats = [] - with closing(br.open(id.strip(), timeout=timeout/4)) as nf: - idata = html.fromstring(nf.read()) - formatlist = idata.xpath('.//div[@id="fullBookFormats"]//span[@class="bookFormat"]/text()') - for x in formatlist: - if x.strip() not in formats: - formats.append(x.strip()) - drm = drm_pattern.search(''.join(idata.xpath('.//div[@id="fullBookFormats"]/p/text()'))) counter -= 1 @@ -79,7 +70,20 @@ class LegimiStore(BasicStoreConfig, StorePlugin): s.author = author.strip() s.price = price s.detail_item = 'http://www.legimi.com/' + id.strip() - s.formats = ', '.join(formats) - s.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED yield s + + def get_details(self, search_result, timeout): + drm_pattern = re.compile("zabezpieczona DRM") + formats = [] + br = browser() + with closing(br.open(search_result.detail_item, timeout=timeout)) as nf: + idata = html.fromstring(nf.read()) + formatlist = idata.xpath('.//div[@id="fullBookFormats"]//span[@class="bookFormat"]/text()') + for x in formatlist: + if x.strip() not in formats: + formats.append(x.strip()) + drm = drm_pattern.search(''.join(idata.xpath('.//div[@id="fullBookFormats"]/p/text()'))) + search_result.formats = ', '.join(formats) + search_result.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED + return True