mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New store: EBookShoppeUKStore.
small correction to FoylesUKStore. fix to threading problem in search causing range errors. Disable waterstones.
This commit is contained in:
parent
1bfa5d0873
commit
b04eed0012
@ -1393,6 +1393,16 @@ class StoreWoblinkStore(StoreBase):
|
|||||||
headquarters = 'PL'
|
headquarters = 'PL'
|
||||||
formats = ['EPUB']
|
formats = ['EPUB']
|
||||||
|
|
||||||
|
class StoreEBookShoppeUKStore(StoreBase):
|
||||||
|
name = 'ebookShoppe UK'
|
||||||
|
author = u'Charles Haley'
|
||||||
|
description = u'We made this website in an attempt to offer the widest range of UK eBooks possible across and as many formats as we could manage.'
|
||||||
|
actual_plugin = 'calibre.gui2.store.ebookshoppe_uk_plugin:EBookShoppeUKStore'
|
||||||
|
|
||||||
|
drm_free_only = False
|
||||||
|
headquarters = 'UK'
|
||||||
|
formats = ['EPUB', 'PDF']
|
||||||
|
|
||||||
plugins += [
|
plugins += [
|
||||||
StoreArchiveOrgStore,
|
StoreArchiveOrgStore,
|
||||||
StoreAmazonKindleStore,
|
StoreAmazonKindleStore,
|
||||||
@ -1404,6 +1414,7 @@ plugins += [
|
|||||||
StoreBeWriteStore,
|
StoreBeWriteStore,
|
||||||
StoreDieselEbooksStore,
|
StoreDieselEbooksStore,
|
||||||
StoreEbookscomStore,
|
StoreEbookscomStore,
|
||||||
|
StoreEBookShoppeUKStore,
|
||||||
StoreEPubBuyDEStore,
|
StoreEPubBuyDEStore,
|
||||||
StoreEHarlequinStore,
|
StoreEHarlequinStore,
|
||||||
StoreFeedbooksStore,
|
StoreFeedbooksStore,
|
||||||
@ -1421,7 +1432,7 @@ plugins += [
|
|||||||
StorePragmaticBookshelfStore,
|
StorePragmaticBookshelfStore,
|
||||||
StoreSmashwordsStore,
|
StoreSmashwordsStore,
|
||||||
StoreVirtualoStore,
|
StoreVirtualoStore,
|
||||||
StoreWaterstonesUKStore,
|
# StoreWaterstonesUKStore,
|
||||||
StoreWeightlessBooksStore,
|
StoreWeightlessBooksStore,
|
||||||
StoreWizardsTowerBooksStore,
|
StoreWizardsTowerBooksStore,
|
||||||
StoreWoblinkStore
|
StoreWoblinkStore
|
||||||
|
97
src/calibre/gui2/store/ebookshoppe_uk_plugin.py
Normal file
97
src/calibre/gui2/store/ebookshoppe_uk_plugin.py
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import urllib2
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser, url_slash_cleaner
|
||||||
|
from calibre.gui2 import open_url
|
||||||
|
from calibre.gui2.store import StorePlugin
|
||||||
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
|
from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
||||||
|
|
||||||
|
class EBookShoppeUKStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
|
url_details = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p={0}'
|
||||||
|
url = 'http://www.awin1.com/awclick.php?mid=2666&id=120917'
|
||||||
|
|
||||||
|
if external or self.config.get('open_external', False):
|
||||||
|
if detail_item:
|
||||||
|
url = url_details.format(detail_item)
|
||||||
|
open_url(QUrl(url))
|
||||||
|
else:
|
||||||
|
detail_url = None
|
||||||
|
if detail_item:
|
||||||
|
detail_url = url_details.format(detail_item)
|
||||||
|
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(self.config.get('tags', ''))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
# reduce max_results because the filter will match everything. See the
|
||||||
|
# setting of 'author' below for more details
|
||||||
|
|
||||||
|
def search(self, query, max_results=5, timeout=60):
|
||||||
|
url = 'http://www.ebookshoppe.com/search.php?search_query=' + urllib2.quote(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="ProductList"]/li'):
|
||||||
|
if counter <= 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = ''.join(data.xpath('./div[@class="ProductDetails"]/'
|
||||||
|
'strong/a/@href')).strip()
|
||||||
|
if not id:
|
||||||
|
continue
|
||||||
|
cover_url = ''.join(data.xpath('./div[@class="ProductImage"]/a/img/@src'))
|
||||||
|
title = ''.join(data.xpath('./div[@class="ProductDetails"]/strong/a/text()'))
|
||||||
|
price = ''.join(data.xpath('./div[@class="ProductPriceRating"]/em/text()'))
|
||||||
|
counter -= 1
|
||||||
|
|
||||||
|
s = SearchResult()
|
||||||
|
s.cover_url = cover_url
|
||||||
|
s.title = title.strip()
|
||||||
|
# Set the author to the query terms to ensure that author
|
||||||
|
# queries match something when pruning searches. Of course, this
|
||||||
|
# means that all books will match. Sigh...
|
||||||
|
s.author = query
|
||||||
|
s.price = price
|
||||||
|
s.drm = SearchResult.DRM_UNLOCKED
|
||||||
|
s.detail_item = id
|
||||||
|
s.formats = ''
|
||||||
|
|
||||||
|
# Call this here instead of later. Reason: painting then
|
||||||
|
# removing matches looks very strange. There are also issues
|
||||||
|
# with threading. Yes, this makes things take longer, but we
|
||||||
|
# will do the work anyway.
|
||||||
|
self.my_get_details(s, timeout)
|
||||||
|
|
||||||
|
yield s
|
||||||
|
|
||||||
|
def my_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())
|
||||||
|
author = ''.join(idata.xpath('//div[@id="ProductOtherDetails"]/dl/dd[1]/text()'))
|
||||||
|
if author:
|
||||||
|
search_result.author = author
|
||||||
|
formats = idata.xpath('//dl[@class="ProductAddToCart"]/dd/'
|
||||||
|
'ul[@class="ProductOptionList"]/li/label/text()')
|
||||||
|
if formats:
|
||||||
|
search_result.formats = ', '.join(formats)
|
||||||
|
search_result.drm = SearchResult.DRM_UNKNOWN
|
||||||
|
return True
|
@ -23,12 +23,13 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
|
|||||||
class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
url = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p='
|
url = 'http://www.awin1.com/awclick.php?mid=1414&id=120917'
|
||||||
|
detail_url = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p='
|
||||||
url_redirect = 'http://www.foyles.co.uk'
|
url_redirect = 'http://www.foyles.co.uk'
|
||||||
|
|
||||||
if external or self.config.get('open_external', False):
|
if external or self.config.get('open_external', False):
|
||||||
if detail_item:
|
if detail_item:
|
||||||
url = url + url_redirect + detail_item
|
url = detail_url + url_redirect + detail_item
|
||||||
open_url(QUrl(url_slash_cleaner(url)))
|
open_url(QUrl(url_slash_cleaner(url)))
|
||||||
else:
|
else:
|
||||||
detail_url = None
|
detail_url = None
|
||||||
@ -54,6 +55,10 @@ class FoylesUKStore(BasicStoreConfig, StorePlugin):
|
|||||||
if not id:
|
if not id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# filter out the audio books
|
||||||
|
if not data.xpath('boolean(.//div[@class="Relative"]/ul/li[contains(text(), "ePub")])'):
|
||||||
|
continue
|
||||||
|
|
||||||
cover_url = ''.join(data.xpath('.//a[@class="Jacket"]/img/@src'))
|
cover_url = ''.join(data.xpath('.//a[@class="Jacket"]/img/@src'))
|
||||||
if cover_url:
|
if cover_url:
|
||||||
cover_url = 'http://www.foyles.co.uk' + cover_url
|
cover_url = 'http://www.foyles.co.uk' + cover_url
|
||||||
|
@ -150,6 +150,8 @@ class Matches(QAbstractItemModel):
|
|||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
row, col = index.row(), index.column()
|
row, col = index.row(), index.column()
|
||||||
|
if row >= len(self.matches):
|
||||||
|
return NONE
|
||||||
result = self.matches[row]
|
result = self.matches[row]
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
if col == 1:
|
if col == 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user