diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 91e81bd46f..49865c0f19 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1258,6 +1258,16 @@ class StoreEHarlequinStore(StoreBase): formats = ['EPUB', 'PDF'] affiliate = True +class StoreEKnigiStore(StoreBase): + name = u'еКниги' + author = 'Alex Stanev' + description = u'Онлайн книжарница за електронни книги и аудио риалити романи' + actual_plugin = 'calibre.gui2.store.stores.eknigi_plugin:eKnigiStore' + + headquarters = 'BG' + formats = ['EPUB', 'PDF', 'HTML'] + affiliate = True + class StoreEpubBudStore(StoreBase): name = 'ePub Bud' description = 'Well, it\'s pretty much just "YouTube for Children\'s eBooks. A not-for-profit organization devoted to brining self published childrens books to the world.' @@ -1483,6 +1493,7 @@ plugins += [ StoreEBookShoppeUKStore, # StoreEPubBuyDEStore, StoreEHarlequinStore, + StoreEKnigiStore, StoreEpubBudStore, StoreFeedbooksStore, StoreFoylesUKStore, diff --git a/src/calibre/gui2/store/stores/eknigi_plugin.py b/src/calibre/gui2/store/stores/eknigi_plugin.py new file mode 100644 index 0000000000..08d9418d51 --- /dev/null +++ b/src/calibre/gui2/store/stores/eknigi_plugin.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, Alex Stanev ' +__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 eKnigiStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + url = 'http://e-knigi.net/?amigosid=22' + aff_suffix = '&amigosid=22' + + if external or self.config.get('open_external', False): + if detail_item: + url = detail_item + aff_suffix + open_url(QUrl(url_slash_cleaner(url))) + else: + detail_url = None + if detail_item: + url = detail_item + aff_suffix + d = WebStoreDialog(self.gui, url, parent, detail_url) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=10, timeout=60): + base_url = 'http://e-knigi.net' + url = base_url + '/virtuemart?page=shop.browse&search_category=0&search_limiter=anywhere&limitstart=0&limit=' + str(max_results) + '&keyword=' + urllib2.quote(query) + + br = browser() + + counter = max_results + with closing(br.open(url, timeout=timeout)) as f: + doc = html.fromstring(f.read()) + + # if the store finds only one product, it opens directly detail view + for data in doc.xpath('//div[@class="prod_details"]'): + s = SearchResult() + s.cover_url = ''.join(data.xpath('.//div[@class="vm_main_info clearfix"]/div[@class="lf"]/a/img/@src')).strip() + s.title = ''.join(data.xpath('.//div[@class="vm_main_info clearfix"]/div[@class="lf"]/a/img/@alt')).strip() + s.author = ''.join(data.xpath('.//div[@class="td_bg clearfix"]/div[@class="gk_product_tab"]/div/table/tr[3]/td[2]/text()')).strip() + s.price = ''.join(data.xpath('.//span[@class="productPrice"]/text()')).strip() + s.detail_item = url + s.drm = SearchResult.DRM_UNLOCKED + + yield s + return + + # search in store results + for data in doc.xpath('//div[@class="browseProductContainer"]'): + if counter <= 0: + break + id = ''.join(data.xpath('.//a[1]/@href')).strip() + if not id: + continue + + counter -= 1 + + s = SearchResult() + s.cover_url = ''.join(data.xpath('.//a[@class="gk_vm_product_image"]/img/@src')).strip() + s.title = ''.join(data.xpath('.//a[@class="gk_vm_product_image"]/img/@title')).strip() + s.author = ''.join(data.xpath('.//div[@style="float:left;width:90%"]/b/text()')).strip().replace('Автор: ', '') + s.price = ''.join(data.xpath('.//span[@class="productPrice"]/text()')).strip() + s.detail_item = base_url + id + s.drm = SearchResult.DRM_UNLOCKED + + yield s