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] 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