mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Store: Format support.
This commit is contained in:
parent
2390a90e7b
commit
7a466b2825
@ -168,6 +168,7 @@ class AmazonKindleStore(StorePlugin):
|
||||
s.author = author.strip()
|
||||
s.price = price.strip()
|
||||
s.detail_item = asin.strip()
|
||||
s.formats = 'Kindle'
|
||||
|
||||
yield s
|
||||
|
||||
|
@ -86,5 +86,6 @@ class BaenWebScriptionStore(BasicStoreConfig, StorePlugin):
|
||||
s.price = price
|
||||
s.detail_item = id.strip()
|
||||
s.drm = SearchResult.DRM_UNLOCKED
|
||||
s.formats = 'RB, MOBI, EPUB, LIT, LRF, RTF, HTML'
|
||||
|
||||
yield s
|
||||
|
@ -77,10 +77,25 @@ class BeWriteStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
|
||||
idata = html.fromstring(nf.read())
|
||||
|
||||
price = ''.join(idata.xpath('//div[@id="content"]//td[contains(text(), "ePub")]/text()'))
|
||||
if not price:
|
||||
price = ''.join(idata.xpath('//div[@id="content"]//td[contains(text(), "MOBI")]/text()'))
|
||||
if not price:
|
||||
price = ''.join(idata.xpath('//div[@id="content"]//td[contains(text(), "PDF")]/text()'))
|
||||
price = '$' + price.split('$')[-1]
|
||||
search_result.price = price.strip()
|
||||
|
||||
cover_img = idata.xpath('//div[@id="content"]//img[1]/@src')
|
||||
if cover_img:
|
||||
cover_url = 'http://www.bewrite.net/mm5/' + cover_img[0]
|
||||
search_result.cover_url = cover_url.strip()
|
||||
|
||||
formats = set([])
|
||||
if idata.xpath('boolean(//div[@id="content"]//td[contains(text(), "ePub")])'):
|
||||
formats.add('EPUB')
|
||||
if idata.xpath('boolean(//div[@id="content"]//td[contains(text(), "PDF")])'):
|
||||
formats.add('PDF')
|
||||
if idata.xpath('boolean(//div[@id="content"]//td[contains(text(), "MOBI")])'):
|
||||
formats.add('MOBI')
|
||||
search_result.formats = ', '.join(list(formats))
|
||||
|
@ -79,5 +79,6 @@ class BNStore(BasicStoreConfig, StorePlugin):
|
||||
s.price = price
|
||||
s.detail_item = id.strip()
|
||||
s.drm = SearchResult.DRM_UNKNOWN
|
||||
s.formats = 'Nook'
|
||||
|
||||
yield s
|
||||
|
@ -75,6 +75,8 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
|
||||
if price_elem:
|
||||
price = price_elem[0]
|
||||
|
||||
formats = ', '.join(data.xpath('.//td[@class="format"]/text()'))
|
||||
|
||||
counter -= 1
|
||||
|
||||
s = SearchResult()
|
||||
@ -83,6 +85,7 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
|
||||
s.author = author.strip()
|
||||
s.price = price.strip()
|
||||
s.detail_item = '/item/' + id.strip()
|
||||
s.formats = formats
|
||||
|
||||
yield s
|
||||
|
||||
|
@ -98,12 +98,21 @@ class EbookscomStore(BasicStoreConfig, StorePlugin):
|
||||
br = browser()
|
||||
with closing(br.open(url + id, timeout=timeout)) as nf:
|
||||
pdoc = html.fromstring(nf.read())
|
||||
|
||||
pdata = pdoc.xpath('//table[@class="price"]/tr/td/text()')
|
||||
if len(pdata) >= 2:
|
||||
price = pdata[1]
|
||||
|
||||
search_result.drm = SearchResult.DRM_UNLOCKED
|
||||
for sec in ('Printing', 'Copying', 'Lending'):
|
||||
if pdoc.xpath('boolean(//div[@class="formatTableInner"]//table//tr[contains(th, "%s") and contains(td, "Off")])' % sec):
|
||||
search_result.drm = SearchResult.DRM_LOCKED
|
||||
break
|
||||
|
||||
fdata = ', '.join(pdoc.xpath('//table[@class="price"]//tr//td[1]/text()'))
|
||||
fdata = fdata.replace(':', '')
|
||||
fdata = re.sub(r'\s{2,}', ' ', fdata)
|
||||
fdata = fdata.strip()
|
||||
search_result.formats = fdata
|
||||
|
||||
search_result.price = price.strip()
|
||||
|
@ -77,6 +77,7 @@ class EHarlequinStore(BasicStoreConfig, StorePlugin):
|
||||
s.author = author.strip()
|
||||
s.price = price.strip()
|
||||
s.detail_item = '?url=http://ebooks.eharlequin.com/' + id.strip()
|
||||
s.formats = 'EPUB'
|
||||
|
||||
yield s
|
||||
|
||||
|
@ -418,12 +418,11 @@ class DetailsThread(Thread):
|
||||
callback(result)
|
||||
self.tasks.task_done()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
continue
|
||||
|
||||
class Matches(QAbstractItemModel):
|
||||
|
||||
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('DRM'), _('Store')]
|
||||
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('DRM'), _('Store'), _('Formats')]
|
||||
|
||||
def __init__(self):
|
||||
QAbstractItemModel.__init__(self)
|
||||
@ -539,6 +538,8 @@ class Matches(QAbstractItemModel):
|
||||
return QVariant(result.price)
|
||||
elif col == 5:
|
||||
return QVariant(result.store_name)
|
||||
elif col == 6:
|
||||
return QVariant(result.formats)
|
||||
return NONE
|
||||
elif role == Qt.DecorationRole:
|
||||
if col == 0 and result.cover_data:
|
||||
@ -573,6 +574,8 @@ class Matches(QAbstractItemModel):
|
||||
text = 'c'
|
||||
elif col == 5:
|
||||
text = result.store_name
|
||||
elif col == 6:
|
||||
text = ', '.join(sorted(result.formats.split(',')))
|
||||
return text
|
||||
|
||||
def sort(self, col, order, reset=True):
|
||||
@ -598,6 +601,8 @@ class SearchFilter(SearchQueryParser):
|
||||
'authors',
|
||||
'cover',
|
||||
'drm',
|
||||
'format',
|
||||
'formats',
|
||||
'price',
|
||||
'title',
|
||||
'store',
|
||||
@ -643,7 +648,7 @@ class SearchFilter(SearchQueryParser):
|
||||
'author': lambda x: x.author.lower(),
|
||||
'cover': lambda x: x.cover_url,
|
||||
'drm': lambda x: x.drm,
|
||||
'format': '',
|
||||
'format': lambda x: x.formats,
|
||||
'price': lambda x: comparable_price(x.price),
|
||||
'store': lambda x: x.store_name.lower(),
|
||||
'title': lambda x: x.title.lower(),
|
||||
@ -681,6 +686,9 @@ class SearchFilter(SearchQueryParser):
|
||||
else:
|
||||
m = matchkind
|
||||
|
||||
if locvalue == 'format':
|
||||
vals = accessor(sr).split(',')
|
||||
else:
|
||||
vals = [accessor(sr)]
|
||||
if _match(query, vals, m):
|
||||
matches.add(sr)
|
||||
|
Loading…
x
Reference in New Issue
Block a user