mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get Books: Diesel, fix results not showing when only a single match is found
This commit is contained in:
commit
e638c9f3f3
@ -157,8 +157,6 @@ class AmazonKindleStore(StorePlugin):
|
||||
title_xpath = './/div[@class="productTitle"]/a/text()'
|
||||
price_xpath = './/div[@class="newPrice"]//span//text()'
|
||||
|
||||
|
||||
|
||||
for data in doc.xpath(data_xpath):
|
||||
if counter <= 0:
|
||||
break
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user