mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
move format and DRM status detection to get_details()
This commit is contained in:
parent
1c7a229ebc
commit
8f1bf67ada
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
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'
|
__license__ = 'GPL 3'
|
||||||
__copyright__ = '2011-2013, Tomasz Długosz <tomek3d@gmail.com>'
|
__copyright__ = '2011-2013, Tomasz Długosz <tomek3d@gmail.com>'
|
||||||
@ -45,7 +45,6 @@ class LegimiStore(BasicStoreConfig, StorePlugin):
|
|||||||
url = 'http://www.legimi.com/pl/ebooki/?szukaj=' + urllib.quote_plus(query)
|
url = 'http://www.legimi.com/pl/ebooki/?szukaj=' + urllib.quote_plus(query)
|
||||||
|
|
||||||
br = browser()
|
br = browser()
|
||||||
drm_pattern = re.compile("zabezpieczona DRM")
|
|
||||||
|
|
||||||
counter = max_results
|
counter = max_results
|
||||||
with closing(br.open(url, timeout=timeout)) as f:
|
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()'))
|
title = ''.join(data.xpath('.//span[@class="bookListTitle ellipsis"]/text()'))
|
||||||
author = ''.join(data.xpath('.//span[@class="bookListAuthor ellipsis"]/text()'))
|
author = ''.join(data.xpath('.//span[@class="bookListAuthor ellipsis"]/text()'))
|
||||||
price = ''.join(data.xpath('.//div[@class="bookListPrice"]/span/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
|
counter -= 1
|
||||||
|
|
||||||
@ -79,7 +70,20 @@ class LegimiStore(BasicStoreConfig, StorePlugin):
|
|||||||
s.author = author.strip()
|
s.author = author.strip()
|
||||||
s.price = price
|
s.price = price
|
||||||
s.detail_item = 'http://www.legimi.com/' + id.strip()
|
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
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user