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
@ -156,8 +156,6 @@ class AmazonKindleStore(StorePlugin):
|
|||||||
cover_xpath = './/div[@class="productImage"]//img/@src'
|
cover_xpath = './/div[@class="productImage"]//img/@src'
|
||||||
title_xpath = './/div[@class="productTitle"]/a/text()'
|
title_xpath = './/div[@class="productTitle"]/a/text()'
|
||||||
price_xpath = './/div[@class="newPrice"]//span//text()'
|
price_xpath = './/div[@class="newPrice"]//span//text()'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for data in doc.xpath(data_xpath):
|
for data in doc.xpath(data_xpath):
|
||||||
if counter <= 0:
|
if counter <= 0:
|
||||||
|
@ -7,6 +7,7 @@ __copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
@ -52,32 +53,27 @@ class DieselEbooksStore(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[contains(@class, "item")]'):
|
|
||||||
if counter <= 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
id = ''.join(data.xpath('div[@class="cover"]/a/@href'))
|
if doc.xpath('not(boolean(//select[contains(@id, "selection")]))'):
|
||||||
if not id or '/item/' not in id:
|
id = ''.join(doc.xpath('//div[@class="price_fat"]//a/@href'))
|
||||||
continue
|
mo = re.search('(?<=id=).+?(?=&)', id)
|
||||||
|
if not mo:
|
||||||
|
yield None
|
||||||
|
id = mo.group()
|
||||||
|
|
||||||
cover_url = ''.join(data.xpath('div[@class="cover"]//img/@src'))
|
cover_url = ''.join(doc.xpath('//div[@class="cover"]/a/@href'))
|
||||||
|
|
||||||
title = ''.join(data.xpath('.//div[@class="content"]//h2/a/text()'))
|
title = ''.join(doc.xpath('//div[@class="desc_fat"]//h1/text()'))
|
||||||
author = ''.join(data.xpath('.//div[@class="content"]/span//a/text()'))
|
author = ''.join(doc.xpath('//div[@class="desc_fat"]//span[@itemprop="author"]/text()'))
|
||||||
price = ''
|
price = ''.join(doc.xpath('//div[@class="price_fat"]//h1/text()'))
|
||||||
price_elem = data.xpath('.//div[@class="price_fat"]//h1/text()')
|
|
||||||
if price_elem:
|
|
||||||
price = price_elem[0]
|
|
||||||
|
|
||||||
formats = ', '.join(data.xpath('.//div[@class="book-info"]//text()')).strip()
|
formats = ', '.join(doc.xpath('//div[@class="desc_fat"]//p[contains(text(), "Format")]/text()'))
|
||||||
a, b, formats = formats.partition('Format:')
|
a, b, formats = formats.partition('Format:')
|
||||||
|
|
||||||
drm = SearchResult.DRM_LOCKED
|
drm = SearchResult.DRM_LOCKED
|
||||||
if 'drm free' in formats.lower():
|
if 'drm free' in formats.lower():
|
||||||
drm = SearchResult.DRM_UNLOCKED
|
drm = SearchResult.DRM_UNLOCKED
|
||||||
|
|
||||||
|
|
||||||
counter -= 1
|
|
||||||
|
|
||||||
s = SearchResult()
|
s = SearchResult()
|
||||||
s.cover_url = cover_url
|
s.cover_url = cover_url
|
||||||
s.title = title.strip()
|
s.title = title.strip()
|
||||||
@ -88,3 +84,39 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
s.drm = drm
|
s.drm = drm
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
else:
|
||||||
|
for data in doc.xpath('//div[contains(@class, "item")]'):
|
||||||
|
if counter <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = ''.join(data.xpath('div[@class="cover"]/a/@href'))
|
||||||
|
if not id or '/item/' not in id:
|
||||||
|
continue
|
||||||
|
|
||||||
|
cover_url = ''.join(data.xpath('div[@class="cover"]//img/@src'))
|
||||||
|
|
||||||
|
title = ''.join(data.xpath('.//div[@class="content"]//h2/a/text()'))
|
||||||
|
author = ''.join(data.xpath('.//div[@class="content"]/span//a/text()'))
|
||||||
|
price = ''
|
||||||
|
price_elem = data.xpath('.//div[@class="price_fat"]//h1/text()')
|
||||||
|
if price_elem:
|
||||||
|
price = price_elem[0]
|
||||||
|
|
||||||
|
formats = ', '.join(data.xpath('.//div[@class="book-info"]//text()')).strip()
|
||||||
|
a, b, formats = formats.partition('Format:')
|
||||||
|
drm = SearchResult.DRM_LOCKED
|
||||||
|
if 'drm free' in formats.lower():
|
||||||
|
drm = SearchResult.DRM_UNLOCKED
|
||||||
|
|
||||||
|
counter -= 1
|
||||||
|
|
||||||
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user