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