mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ebooks.com plugin. Change how detail items are handled. Fix diesel books search.
This commit is contained in:
parent
381e3db369
commit
81a09ea46b
@ -1052,6 +1052,11 @@ class StoreDieselEbooksStore(StoreBase):
|
||||
description = _('World Famous eBook Store.')
|
||||
actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore'
|
||||
|
||||
class StoreEbookscomStore(StoreBase):
|
||||
name = 'eBooks.com'
|
||||
description = _('The digital bookstore.')
|
||||
actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore'
|
||||
|
||||
class StoreFeedbooksStore(StoreBase):
|
||||
name = 'Feedbooks'
|
||||
description = _('Read anywhere.')
|
||||
@ -1072,6 +1077,6 @@ class StoreSmashwordsStore(StoreBase):
|
||||
description = _('Your ebook. Your way.')
|
||||
actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore'
|
||||
|
||||
plugins += [StoreAmazonKindleStore, StoreDieselEbooksStore, StoreFeedbooksStore, StoreGutenbergStore, StoreManyBooksStore, StoreSmashwordsStore]
|
||||
plugins += [StoreAmazonKindleStore, StoreDieselEbooksStore, StoreEbookscomStore, StoreFeedbooksStore, StoreGutenbergStore, StoreManyBooksStore, StoreSmashwordsStore]
|
||||
|
||||
# }}}
|
||||
|
@ -30,12 +30,15 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
|
||||
if random.randint(1, 10) in (1, 2, 3):
|
||||
aff_id = '?aid=2053'
|
||||
|
||||
detail_url = None
|
||||
if detail_item:
|
||||
detail_url = url + detail_item + aff_id
|
||||
url = url + aff_id
|
||||
|
||||
if external or settings.get(self.name + '_open_external', False):
|
||||
if detail_item:
|
||||
url = url + detail_item
|
||||
open_url(QUrl(url_slash_cleaner(url + aff_id)))
|
||||
open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url)))
|
||||
else:
|
||||
d = WebStoreDialog(self.gui, url + aff_id, parent, detail_item)
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||
d = d.exec_()
|
||||
@ -63,7 +66,7 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
|
||||
cover_url = cover_url[1:]
|
||||
cover_url = 'http://www.diesel-ebooks.com/' + cover_url
|
||||
|
||||
title = ''.join(data.xpath('//div[@class="content"]/h2/text()'))
|
||||
title = ''.join(data.xpath('.//div[@class="content"]//h2/text()'))
|
||||
author = ''.join(data.xpath('//div[@class="content"]//div[@class="author"]/a/text()'))
|
||||
price = ''
|
||||
price_elem = data.xpath('//td[@class="price"]/text()')
|
||||
|
94
src/calibre/gui2/store/ebooks_com_plugin.py
Normal file
94
src/calibre/gui2/store/ebooks_com_plugin.py
Normal file
@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import random
|
||||
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 EbookscomStore(BasicStoreConfig, StorePlugin):
|
||||
|
||||
def open(self, parent=None, detail_item=None, external=False):
|
||||
settings = self.get_settings()
|
||||
|
||||
m_url = 'http://www.dpbolvw.net/'
|
||||
h_click = 'click-4879827-10364500'
|
||||
d_click = 'click-4879827-10281551'
|
||||
# Use Kovid's affiliate id 30% of the time.
|
||||
if random.randint(1, 10) in (1, 2, 3):
|
||||
#h_click = ''
|
||||
#d_click = ''
|
||||
pass
|
||||
|
||||
url = m_url + h_click
|
||||
detail_url = None
|
||||
if detail_item:
|
||||
detail_url = m_url + d_click + detail_item
|
||||
|
||||
if external or settings.get(self.name + '_open_external', False):
|
||||
open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url)))
|
||||
else:
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||
d = d.exec_()
|
||||
|
||||
def search(self, query, max_results=10, timeout=60):
|
||||
url = 'http://www.ebooks.com/SearchApp/SearchResults.net?term=' + 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('//div[@class="book_a" or @class="book_b"]'):
|
||||
if counter <= 0:
|
||||
break
|
||||
|
||||
id = ''.join(data.xpath('.//a[1]/@href'))
|
||||
id = id.split('=')[-1]
|
||||
if not id:
|
||||
continue
|
||||
|
||||
price = ''
|
||||
with closing(br.open('http://www.ebooks.com/ebooks/book_display.asp?IID=' + id.strip(), timeout=timeout)) as fp:
|
||||
pdoc = html.fromstring(fp.read())
|
||||
pdata = pdoc.xpath('//table[@class="price"]/tr/td/text()')
|
||||
if len(pdata) >= 2:
|
||||
price = pdata[1]
|
||||
if not price:
|
||||
continue
|
||||
|
||||
cover_url = ''.join(data.xpath('.//img[1]/@src'))
|
||||
|
||||
title = ''
|
||||
author = ''
|
||||
heading_a = data.xpath('.//a[1]/text()')
|
||||
if heading_a:
|
||||
title = heading_a[0]
|
||||
if len(heading_a) >= 2:
|
||||
author = heading_a[1]
|
||||
|
||||
counter -= 1
|
||||
|
||||
s = SearchResult()
|
||||
s.cover_url = cover_url
|
||||
s.title = title.strip()
|
||||
s.author = author.strip()
|
||||
s.price = price.strip()
|
||||
s.detail_item = '?url=http://www.ebooks.com/cj.asp?IID=' + id.strip() + '&cjsku=' + id.strip()
|
||||
|
||||
yield s
|
@ -30,7 +30,10 @@ class FeedbooksStore(BasicStoreConfig, StorePlugin):
|
||||
ext_url = ext_url + detail_item
|
||||
open_url(QUrl(url_slash_cleaner(ext_url)))
|
||||
else:
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
||||
detail_url = None
|
||||
if detail_item:
|
||||
detail_url = url + detail_item
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||
d = d.exec_()
|
||||
|
@ -30,7 +30,10 @@ class GutenbergStore(BasicStoreConfig, StorePlugin):
|
||||
ext_url = ext_url + detail_item
|
||||
open_url(QUrl(url_slash_cleaner(ext_url)))
|
||||
else:
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
||||
detail_url = None
|
||||
if detail_item:
|
||||
detail_url = url + detail_item
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||
d = d.exec_()
|
||||
|
@ -24,13 +24,15 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin):
|
||||
def open(self, parent=None, detail_item=None, external=False):
|
||||
settings = self.get_settings()
|
||||
url = 'http://manybooks.net/'
|
||||
|
||||
detail_url = None
|
||||
if detail_item:
|
||||
detail_url = url + detail_item
|
||||
|
||||
if external or settings.get(self.name + '_open_external', False):
|
||||
if detail_item:
|
||||
url = url + detail_item
|
||||
open_url(QUrl(url_slash_cleaner(url)))
|
||||
open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url)))
|
||||
else:
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||
d = d.exec_()
|
||||
|
@ -31,12 +31,16 @@ class SmashwordsStore(BasicStoreConfig, StorePlugin):
|
||||
if random.randint(1, 10) in (1, 2, 3):
|
||||
aff_id = '?ref=kovidgoyal'
|
||||
|
||||
detail_url = None
|
||||
if detail_item:
|
||||
detail_url = url + detail_item + aff_id
|
||||
url = url + aff_id
|
||||
|
||||
if external or settings.get(self.name + '_open_external', False):
|
||||
if detail_item:
|
||||
url = url + detail_item
|
||||
open_url(QUrl(url_slash_cleaner(url + aff_id)))
|
||||
open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url)))
|
||||
else:
|
||||
d = WebStoreDialog(self.gui, url + aff_id, parent, detail_item)
|
||||
print detail_url
|
||||
d = WebStoreDialog(self.gui, url, parent, detail_url)
|
||||
d.setWindowTitle(self.name)
|
||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||
d = d.exec_()
|
||||
|
@ -14,7 +14,7 @@ from calibre.gui2.store.web_store_dialog_ui import Ui_Dialog
|
||||
|
||||
class WebStoreDialog(QDialog, Ui_Dialog):
|
||||
|
||||
def __init__(self, gui, base_url, parent=None, detail_item=None):
|
||||
def __init__(self, gui, base_url, parent=None, detail_url=None):
|
||||
QDialog.__init__(self, parent=parent)
|
||||
self.setupUi(self)
|
||||
|
||||
@ -29,7 +29,7 @@ class WebStoreDialog(QDialog, Ui_Dialog):
|
||||
self.reload.clicked.connect(self.view.reload)
|
||||
self.back.clicked.connect(self.view.back)
|
||||
|
||||
self.go_home(detail_item=detail_item)
|
||||
self.go_home(detail_url=detail_url)
|
||||
|
||||
def set_tags(self, tags):
|
||||
self.view.set_tags(tags)
|
||||
@ -43,11 +43,11 @@ class WebStoreDialog(QDialog, Ui_Dialog):
|
||||
def load_finished(self, ok=True):
|
||||
self.progress.setValue(100)
|
||||
|
||||
def go_home(self, checked=False, detail_item=None):
|
||||
url = self.base_url
|
||||
if detail_item:
|
||||
url, q, ref = url.partition('?')
|
||||
url = url + '/' + urllib.quote(detail_item) + q + ref
|
||||
def go_home(self, checked=False, detail_url=None):
|
||||
if detail_url:
|
||||
url = detail_url
|
||||
else:
|
||||
url = self.base_url
|
||||
|
||||
# Reduce redundant /'s because some stores
|
||||
# (Feedbooks) and server frameworks (cherrypy)
|
||||
|
Loading…
x
Reference in New Issue
Block a user