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 random
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
@ -49,44 +48,44 @@ class KoboStore(BasicStoreConfig, StorePlugin):
|
|||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
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()
|
br = browser()
|
||||||
|
|
||||||
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('//ul[@class="SCShortCoverList"]/li'):
|
for data in doc.xpath('//ul[contains(@class, "flowview-items")]/li'):
|
||||||
if counter <= 0:
|
if counter <= 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
id = ''.join(data.xpath('.//div[@class="SearchImageContainer"]/a[1]/@href'))
|
id = ''.join(data.xpath('./a[contains(@class, "block-link")]/@href'))
|
||||||
if not id:
|
if not id:
|
||||||
continue
|
continue
|
||||||
try:
|
id = id[1:]
|
||||||
id = id.split('?', 1)[0]
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
price = ''.join(data.xpath('.//span[@class="KV2OurPrice"]/strong/text()'))
|
price = ''.join(data.xpath('.//a[contains(@class, "primary-button")]//text()'))
|
||||||
if not price:
|
|
||||||
price = '$0.00'
|
|
||||||
|
|
||||||
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()'))
|
title = ''.join(data.xpath('.//p[contains(@class, "flowview-item-title")]//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"))])')
|
|
||||||
|
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|
||||||
s = SearchResult()
|
s = SearchResult()
|
||||||
s.cover_url = cover_url
|
s.cover_url = cover_url
|
||||||
s.title = title.strip()
|
s.title = title.strip()
|
||||||
s.author = author.strip()
|
|
||||||
s.price = price.strip()
|
s.price = price.strip()
|
||||||
s.detail_item = 'http://www.kobobooks.com/' + id.strip()
|
s.detail_item = 'http://store.kobobooks.com/' + id.strip()
|
||||||
s.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED
|
|
||||||
s.formats = 'EPUB'
|
s.formats = 'EPUB'
|
||||||
|
s.drm = SearchResult.DRM_UNKNOWN
|
||||||
|
|
||||||
yield s
|
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