Store: Fix ebooks.com store plugin.

This commit is contained in:
John Schember 2011-12-03 12:48:05 -05:00
parent ea5b62a023
commit 6595a3d01c

View File

@ -54,7 +54,7 @@ class EbookscomStore(BasicStoreConfig, StorePlugin):
counter = max_results counter = max_results
with closing(br.open(url, timeout=timeout)) as f: with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read()) doc = html.fromstring(f.read())
for data in doc.xpath('//div[@class="book_a" or @class="book_b"]'): for data in doc.xpath('//div[@id="results"]//li'):
if counter <= 0: if counter <= 0:
break break
@ -64,15 +64,21 @@ class EbookscomStore(BasicStoreConfig, StorePlugin):
continue continue
id = mo.group() id = mo.group()
cover_url = ''.join(data.xpath('.//img[1]/@src')) cover_url = ''
cover_load = ''.join(data.xpath('.//div[@class="img"]//img/@onload'))
mo = re.search('(?<=\').+?(?=\')', cover_load)
if mo:
cover_url = mo.group();
title = '' title = ''
author = '' author = ''
heading_a = data.xpath('.//a[1]/text()') header_parts = data.xpath('.//div[@class="descr"]/h4//a//text()')
if heading_a: if header_parts:
title = heading_a[0] title = header_parts[0]
if len(heading_a) >= 2: header_parts = header_parts[1:]
author = heading_a[1] if header_parts:
author = ', '.join(header_parts)
counter -= 1 counter -= 1
@ -98,22 +104,18 @@ class EbookscomStore(BasicStoreConfig, StorePlugin):
with closing(br.open(url + id, timeout=timeout)) as nf: with closing(br.open(url + id, timeout=timeout)) as nf:
pdoc = html.fromstring(nf.read()) pdoc = html.fromstring(nf.read())
pdata = pdoc.xpath('//table[@class="price"]/tr/td/text()') price_l = pdoc.xpath('//span[@class="price"]/text()')
if len(pdata) >= 2: if price_l:
price = pdata[1] price = price_l[0]
search_result.price = price.strip()
search_result.drm = SearchResult.DRM_UNLOCKED search_result.drm = SearchResult.DRM_UNLOCKED
for sec in ('Printing', 'Copying', 'Lending'): permissions = ' '.join(pdoc.xpath('//div[@class="permissions-items"]//text()'))
if pdoc.xpath('boolean(//div[@class="formatTableInner"]//table//tr[contains(th, "%s") and contains(td, "Off")])' % sec): if 'off' in permissions:
search_result.drm = SearchResult.DRM_LOCKED search_result.drm = SearchResult.DRM_LOCKED
break
fdata = ', '.join(pdoc.xpath('//table[@class="price"]//tr//td[1]/text()')) fdata = pdoc.xpath('//div[contains(@class, "more-links") and contains(@class, "more-links-info")]/div//span/text()')
fdata = fdata.replace(':', '') if len(fdata) > 1:
fdata = re.sub(r'\s{2,}', ' ', fdata) search_result.formats = ', '.join(fdata[1:])
fdata = fdata.replace(' ,', ',')
fdata = fdata.strip()
search_result.formats = fdata
search_result.price = price.strip()
return True return True