mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix kobo store not showing any results.
This commit is contained in:
parent
3b040f585d
commit
18871b185d
@ -9,7 +9,6 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import random
|
||||
import urllib
|
||||
import urllib2
|
||||
from contextlib import closing
|
||||
|
||||
from lxml import html
|
||||
@ -49,44 +48,44 @@ class KoboStore(BasicStoreConfig, StorePlugin):
|
||||
d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
url = 'http://www.kobobooks.com/search/search.html?q=' + urllib2.quote(query)
|
||||
url = 'http://www.kobobooks.com/search/search.html?q=' + urllib.quote_plus(query)
|
||||
|
||||
br = browser()
|
||||
|
||||
counter = max_results
|
||||
with closing(br.open(url, timeout=timeout)) as f:
|
||||
doc = html.fromstring(f.read())
|
||||
for data in doc.xpath('//ul[@class="SCShortCoverList"]/li'):
|
||||
for data in doc.xpath('//ul[contains(@class, "flowview-items")]/li'):
|
||||
if counter <= 0:
|
||||
break
|
||||
|
||||
id = ''.join(data.xpath('.//div[@class="SearchImageContainer"]/a[1]/@href'))
|
||||
id = ''.join(data.xpath('./a[contains(@class, "block-link")]/@href'))
|
||||
if not id:
|
||||
continue
|
||||
try:
|
||||
id = id.split('?', 1)[0]
|
||||
except:
|
||||
continue
|
||||
id = id[1:]
|
||||
|
||||
price = ''.join(data.xpath('.//span[@class="KV2OurPrice"]/strong/text()'))
|
||||
if not price:
|
||||
price = '$0.00'
|
||||
price = ''.join(data.xpath('.//a[contains(@class, "primary-button")]//text()'))
|
||||
|
||||
cover_url = ''.join(data.xpath('.//div[@class="SearchImageContainer"]//img[1]/@src'))
|
||||
cover_url = ''.join(data.xpath('.//img[1]/@src'))
|
||||
cover_url = 'http:%s' % cover_url
|
||||
|
||||
title = ''.join(data.xpath('.//div[@class="SCItemHeader"]//a[1]/text()'))
|
||||
author = ', '.join(data.xpath('.//div[@class="SCItemSummary"]//span[contains(@class, "Author")]//a/text()'))
|
||||
drm = data.xpath('boolean(.//span[@class="SCAvailibilityFormatsText" and not(contains(text(), "DRM-Free"))])')
|
||||
title = ''.join(data.xpath('.//p[contains(@class, "flowview-item-title")]//text()'))
|
||||
|
||||
counter -= 1
|
||||
|
||||
s = SearchResult()
|
||||
s.cover_url = cover_url
|
||||
s.title = title.strip()
|
||||
s.author = author.strip()
|
||||
s.price = price.strip()
|
||||
s.detail_item = 'http://www.kobobooks.com/' + id.strip()
|
||||
s.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED
|
||||
s.detail_item = 'http://store.kobobooks.com/' + id.strip()
|
||||
s.formats = 'EPUB'
|
||||
s.drm = SearchResult.DRM_UNKNOWN
|
||||
|
||||
yield s
|
||||
|
||||
def get_details(self, search_result, timeout):
|
||||
br = browser()
|
||||
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
|
||||
idata = html.fromstring(nf.read())
|
||||
search_result.author = ', '.join(idata.xpath('.//h2[contains(@class, "author")]//a/text()'))
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user