Store: Diesel, show results when only on is found and the result page is the page for the ebook itself.

This commit is contained in:
John Schember 2012-05-12 14:25:14 -04:00
parent c1961c902c
commit 300ba54e96

View File

@ -7,6 +7,7 @@ __copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import random
import re
import urllib
from contextlib import closing
@ -52,6 +53,38 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
if doc.xpath('not(boolean(//select[contains(@id, "selection")]))'):
id = ''.join(doc.xpath('//div[@class="price_fat"]//a/@href'))
mo = re.search('(?<=id=).+?(?=&)', id)
if not mo:
yield None
id = mo.group()
cover_url = ''.join(doc.xpath('//div[@class="cover"]/a/@href'))
title = ''.join(doc.xpath('//div[@class="desc_fat"]//h1/text()'))
author = ''.join(doc.xpath('//div[@class="desc_fat"]//span[@itemprop="author"]/text()'))
price = ''.join(doc.xpath('//div[@class="price_fat"]//h1/text()'))
formats = ', '.join(doc.xpath('//div[@class="desc_fat"]//p[contains(text(), "Format")]/text()'))
a, b, formats = formats.partition('Format:')
drm = SearchResult.DRM_LOCKED
if 'drm free' in formats.lower():
drm = SearchResult.DRM_UNLOCKED
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.author = author.strip()
s.price = price.strip()
s.detail_item = id.strip()
s.formats = formats
s.drm = drm
yield s
else:
for data in doc.xpath('//div[contains(@class, "item")]'):
if counter <= 0:
break
@ -75,7 +108,6 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
if 'drm free' in formats.lower():
drm = SearchResult.DRM_UNLOCKED
counter -= 1
s = SearchResult()