mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Store: Add drm status indicators. Add DRM status results for Manybooks, amazon, baen and bwrite.
This commit is contained in:
parent
0b64888105
commit
ebf4ee8fed
BIN
resources/images/drm-locked.png
Normal file
BIN
resources/images/drm-locked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
resources/images/drm-unlocked.png
Normal file
BIN
resources/images/drm-unlocked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -159,6 +159,16 @@ class AmazonKindleStore(StorePlugin):
|
|||||||
author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
|
author = ''.join(data.xpath('div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
|
||||||
author = author.split('by')[-1]
|
author = author.split('by')[-1]
|
||||||
price = ''.join(data.xpath('div[@class="newPrice"]/span/text()'))
|
price = ''.join(data.xpath('div[@class="newPrice"]/span/text()'))
|
||||||
|
|
||||||
|
with closing(br.open(asin_href, timeout=timeout/4)) as nf:
|
||||||
|
idata = html.fromstring(nf.read())
|
||||||
|
if idata.xpath('boolean(//div[@class="content"]//li/b[contains(text(), "Simultaneous Device Usage")])'):
|
||||||
|
if idata.xpath('boolean(//div[@class="content"]//li[contains(., "Unlimited") and contains(b, "Simultaneous Device Usage")])'):
|
||||||
|
drm = False
|
||||||
|
else:
|
||||||
|
drm = None
|
||||||
|
else:
|
||||||
|
drm = True
|
||||||
|
|
||||||
counter -= 1
|
counter -= 1
|
||||||
|
|
||||||
@ -168,5 +178,6 @@ 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.drm = drm
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
@ -85,5 +85,6 @@ class BaenWebScriptionStore(BasicStoreConfig, StorePlugin):
|
|||||||
s.author = author.strip()
|
s.author = author.strip()
|
||||||
s.price = price
|
s.price = price
|
||||||
s.detail_item = id.strip()
|
s.detail_item = id.strip()
|
||||||
|
s.drm = False
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
@ -76,5 +76,6 @@ class BeWriteStore(BasicStoreConfig, StorePlugin):
|
|||||||
s.author = author.strip()
|
s.author = author.strip()
|
||||||
s.price = price.strip()
|
s.price = price.strip()
|
||||||
s.detail_item = id.strip()
|
s.detail_item = id.strip()
|
||||||
|
s.drm = False
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
@ -89,5 +89,6 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
s.author = author.strip()
|
s.author = author.strip()
|
||||||
s.price = price.strip()
|
s.price = price.strip()
|
||||||
s.detail_item = '/titles/' + id
|
s.detail_item = '/titles/' + id
|
||||||
|
s.drm = False
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
|
@ -95,9 +95,11 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
# Author
|
# Author
|
||||||
self.results_view.setColumnWidth(2,int(total*.35))
|
self.results_view.setColumnWidth(2,int(total*.35))
|
||||||
# Price
|
# Price
|
||||||
self.results_view.setColumnWidth(3, int(total*.10))
|
self.results_view.setColumnWidth(3, int(total*.5))
|
||||||
|
# DRM
|
||||||
|
self.results_view.setColumnWidth(4, int(total*.5))
|
||||||
# Store
|
# Store
|
||||||
self.results_view.setColumnWidth(4, int(total*.20))
|
self.results_view.setColumnWidth(5, int(total*.20))
|
||||||
|
|
||||||
def do_search(self, checked=False):
|
def do_search(self, checked=False):
|
||||||
# Stop all running threads.
|
# Stop all running threads.
|
||||||
@ -311,6 +313,7 @@ class SearchThread(Thread):
|
|||||||
self.results.put(res)
|
self.results.put(res)
|
||||||
self.tasks.task_done()
|
self.tasks.task_done()
|
||||||
except:
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _clean_query(self, query):
|
def _clean_query(self, query):
|
||||||
@ -379,10 +382,15 @@ class CoverThread(Thread):
|
|||||||
|
|
||||||
class Matches(QAbstractItemModel):
|
class Matches(QAbstractItemModel):
|
||||||
|
|
||||||
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('Store')]
|
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('DRM'), _('Store')]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QAbstractItemModel.__init__(self)
|
QAbstractItemModel.__init__(self)
|
||||||
|
|
||||||
|
self.DRM_LOCKED_ICON = QPixmap(I('drm-locked.png')).scaledToHeight(64)
|
||||||
|
self.DRM_UNLOCKED_ICON = QPixmap(I('drm-unlocked.png')).scaledToHeight(64)
|
||||||
|
self.DRM_UNKNOWN_ICON = QPixmap(I('dialog_warning.png')).scaledToHeight(64)
|
||||||
|
|
||||||
self.matches = []
|
self.matches = []
|
||||||
self.cover_pool = CoverThreadPool(CoverThread, 2)
|
self.cover_pool = CoverThreadPool(CoverThread, 2)
|
||||||
self.cover_pool.start_threads()
|
self.cover_pool.start_threads()
|
||||||
@ -448,7 +456,7 @@ class Matches(QAbstractItemModel):
|
|||||||
return QVariant(result.author)
|
return QVariant(result.author)
|
||||||
elif col == 3:
|
elif col == 3:
|
||||||
return QVariant(result.price)
|
return QVariant(result.price)
|
||||||
elif col == 4:
|
elif col == 5:
|
||||||
return QVariant(result.store_name)
|
return QVariant(result.store_name)
|
||||||
return NONE
|
return NONE
|
||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
@ -456,6 +464,13 @@ class Matches(QAbstractItemModel):
|
|||||||
p = QPixmap()
|
p = QPixmap()
|
||||||
p.loadFromData(result.cover_data)
|
p.loadFromData(result.cover_data)
|
||||||
return QVariant(p)
|
return QVariant(p)
|
||||||
|
if col == 4:
|
||||||
|
if result.drm:
|
||||||
|
return QVariant(self.DRM_LOCKED_ICON)
|
||||||
|
if result.drm == False:
|
||||||
|
return QVariant(self.DRM_UNLOCKED_ICON)
|
||||||
|
else:
|
||||||
|
return QVariant(self.DRM_UNKNOWN_ICON)
|
||||||
elif role == Qt.SizeHintRole:
|
elif role == Qt.SizeHintRole:
|
||||||
return QSize(64, 64)
|
return QSize(64, 64)
|
||||||
return NONE
|
return NONE
|
||||||
@ -469,6 +484,13 @@ class Matches(QAbstractItemModel):
|
|||||||
elif col == 3:
|
elif col == 3:
|
||||||
text = comparable_price(result.price)
|
text = comparable_price(result.price)
|
||||||
elif col == 4:
|
elif col == 4:
|
||||||
|
if result.drm:
|
||||||
|
text = 'a'
|
||||||
|
elif result.drm == False:
|
||||||
|
text = 'b'
|
||||||
|
else:
|
||||||
|
text = 'c'
|
||||||
|
elif col == 5:
|
||||||
text = result.store_name
|
text = result.store_name
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@ -490,6 +512,7 @@ class SearchFilter(SearchQueryParser):
|
|||||||
'author',
|
'author',
|
||||||
'authors',
|
'authors',
|
||||||
'cover',
|
'cover',
|
||||||
|
'drm',
|
||||||
'price',
|
'price',
|
||||||
'title',
|
'title',
|
||||||
'store',
|
'store',
|
||||||
@ -528,7 +551,7 @@ class SearchFilter(SearchQueryParser):
|
|||||||
q = {
|
q = {
|
||||||
'author': self.search_result.author.lower(),
|
'author': self.search_result.author.lower(),
|
||||||
'cover': self.search_result.cover_url,
|
'cover': self.search_result.cover_url,
|
||||||
'drm': '',
|
'drm': self.search_result.drm,
|
||||||
'format': '',
|
'format': '',
|
||||||
'price': comparable_price(self.search_result.price),
|
'price': comparable_price(self.search_result.price),
|
||||||
'store': self.search_result.store_name.lower(),
|
'store': self.search_result.store_name.lower(),
|
||||||
@ -539,12 +562,23 @@ class SearchFilter(SearchQueryParser):
|
|||||||
for locvalue in locations:
|
for locvalue in locations:
|
||||||
ac_val = q[locvalue]
|
ac_val = q[locvalue]
|
||||||
if query == 'true':
|
if query == 'true':
|
||||||
if ac_val is not None:
|
if locvalue == 'drm':
|
||||||
matches.add(self.search_result)
|
if ac_val == True:
|
||||||
|
matches.add(self.search_result)
|
||||||
|
else:
|
||||||
|
if ac_val is not None:
|
||||||
|
matches.add(self.search_result)
|
||||||
continue
|
continue
|
||||||
if query == 'false':
|
if query == 'false':
|
||||||
if ac_val is None:
|
if locvalue == 'drm':
|
||||||
matches.add(self.search_result)
|
if ac_val == False:
|
||||||
|
matches.add(self.search_result)
|
||||||
|
else:
|
||||||
|
if ac_val is None:
|
||||||
|
matches.add(self.search_result)
|
||||||
|
continue
|
||||||
|
# this is bool, so can't match below
|
||||||
|
if locvalue == 'drm':
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
### Can't separate authors because comma is used for name sep and author sep
|
### Can't separate authors because comma is used for name sep and author sep
|
||||||
|
Loading…
x
Reference in New Issue
Block a user