Diesel ebooks plugin.

This commit is contained in:
John Schember 2011-03-02 07:53:09 -05:00
parent e0b6a9a769
commit a6a0b6ece3
4 changed files with 159 additions and 6 deletions

View File

@ -1047,17 +1047,21 @@ class StoreAmazonKindleStore(StoreBase):
description = _('Kindle books from Amazon')
actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore'
class StoreGutenbergStore(StoreBase):
name = 'Project Gutenberg'
description = _('The first producer of free ebooks.')
actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore'
class StoreDieselEbooksStore(StoreBase):
name = 'Diesel eBooks'
description = _('World Famous eBook Store.')
actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore'
class StoreFeedbooksStore(StoreBase):
name = 'Feedbooks'
description = _('Read anywhere.')
actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore'
class StoreGutenbergStore(StoreBase):
name = 'Project Gutenberg'
description = _('The first producer of free ebooks.')
actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore'
class StoreManyBooksStore(StoreBase):
name = 'ManyBooks'
description = _('The best ebooks at the best price: free!')
@ -1068,6 +1072,6 @@ class StoreSmashwordsStore(StoreBase):
description = _('Your ebook. Your way.')
actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore'
plugins += [StoreAmazonKindleStore, StoreGutenbergStore, StoreFeedbooksStore, StoreManyBooksStore, StoreSmashwordsStore]
plugins += [StoreAmazonKindleStore, StoreDieselEbooksStore, StoreFeedbooksStore, StoreGutenbergStore, StoreManyBooksStore, StoreSmashwordsStore]
# }}}

View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
__license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import QWidget
from calibre.gui2 import gprefs
from calibre.gui2.store.basic_config_widget_ui import Ui_Form
def save_settings(config_widget):
tags = unicode(config_widget.tags.text())
gprefs[config_widget.store.name + '_tags'] = tags
class BasicStoreConfigWidget(QWidget, Ui_Form):
def __init__(self, store):
QWidget.__init__(self)
self.setupUi(self)
self.store = store
self.load_setings()
def load_setings(self):
settings = self.store.get_settings()
self.tags.setText(settings.get(self.store.name + '_tags', ''))
class BasicStoreConfig(object):
def customization_help(self, gui=False):
return 'Customize the behavior of this store.'
def config_widget(self):
return BasicStoreConfigWidget(self)
def save_settings(self, config_widget):
save_settings(config_widget)
def get_settings(self):
settings = {}
settings[self.name + '_tags'] = gprefs.get(self.name + '_tags', self.name + ', store, download')
return settings

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>46</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Added Tags:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="tags"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,71 @@
# -*- 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 calibre import browser
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 DieselEbooksStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False):
settings = self.get_settings()
aff_id = '2049'
# Use Kovid's affiliate id 30% of the time.
#if random.randint(1, 10) in (1, 2, 3):
#aff_id = ''
d = WebStoreDialog(self.gui, 'http://www.diesel-ebooks.com/?aid=%s' % aff_id, parent, detail_item)
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.diesel-ebooks.com/index.php?page=seek&id[m]=&id[c]=scope%253Dinventory&id[q]=' + 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="item clearfix"]'):
data = html.fromstring(html.tostring(data))
if counter <= 0:
break
id = ''.join(data.xpath('div[@class="cover"]/a/@href'))
if not id or '/item/' not in id:
continue
a, b, id = id.partition('/item/')
cover_url = ''.join(data.xpath('div[@class="cover"]//img/@src'))
if cover_url.startswith('/'):
cover_url = cover_url[1:]
cover_url = 'http://www.diesel-ebooks.com/' + cover_url
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()')
if price_elem:
price = price_elem[0]
counter -= 1
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.author = author.strip()
s.price = price.strip()
s.detail_item = '/item/' + id.strip()
yield s