diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 91e81bd46f..a79078988a 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/chitanka_plugin.py b/src/calibre/gui2/store/stores/chitanka_plugin.py index 6f84acba33..3e4364d9fa 100644 --- a/src/calibre/gui2/store/stores/chitanka_plugin.py +++ b/src/calibre/gui2/store/stores/chitanka_plugin.py @@ -54,36 +54,21 @@ class ChitankaStore(BasicStoreConfig, StorePlugin): if counter <= 0: break - id = ''.join(data.xpath('.//a[@class="booklink"]/@href')) + id = ''.join(data.xpath('.//a[@class="booklink"]/@href')).strip() if not id: continue - cover_url = ''.join(data.xpath('.//a[@class="booklink"]/img/@src')) - title = ''.join(data.xpath('.//a[@class="booklink"]/i/text()')) - author = ''.join(data.xpath('.//span[@class="bookauthor"]/a/text()')) - fb2 = ''.join(data.xpath('.//a[@class="dl dl-fb2"]/@href')) - epub = ''.join(data.xpath('.//a[@class="dl dl-epub"]/@href')) - txt = ''.join(data.xpath('.//a[@class="dl dl-txt"]/@href')) - - # remove .zip extensions - if fb2.find('.zip') != -1: - fb2 = fb2[:fb2.find('.zip')] - if epub.find('.zip') != -1: - epub = epub[:epub.find('.zip')] - if txt.find('.zip') != -1: - txt = txt[:txt.find('.zip')] - counter -= 1 s = SearchResult() - s.cover_url = cover_url - s.title = title.strip() - s.author = author.strip() - s.detail_item = id.strip() + s.cover_url = ''.join(data.xpath('.//a[@class="booklink"]/img/@src')).strip() + s.title = ''.join(data.xpath('.//a[@class="booklink"]/i/text()')).strip() + s.author = ''.join(data.xpath('.//span[@class="bookauthor"]/a/text()')).strip() + s.detail_item = id s.drm = SearchResult.DRM_UNLOCKED - s.downloads['FB2'] = base_url + fb2.strip() - s.downloads['EPUB'] = base_url + epub.strip() - s.downloads['TXT'] = base_url + txt.strip() + s.downloads['FB2'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-fb2"]/@href')).strip().replace('.zip', '') + s.downloads['EPUB'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-epub"]/@href')).strip().replace('.zip', '') + s.downloads['TXT'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-txt"]/@href')).strip().replace('.zip', '') s.formats = 'FB2, EPUB, TXT, SFB' yield s @@ -105,35 +90,20 @@ class ChitankaStore(BasicStoreConfig, StorePlugin): if counter <= 0: break - id = ''.join(data.xpath('.//a[@class="booklink"]/@href')) + id = ''.join(data.xpath('.//a[@class="booklink"]/@href')).strip() if not id: continue - cover_url = ''.join(data.xpath('.//a[@class="booklink"]/img/@src')) - title = ''.join(data.xpath('.//a[@class="booklink"]/i/text()')) - author = ''.join(data.xpath('.//span[@class="bookauthor"]/a/text()')) - fb2 = ''.join(data.xpath('.//a[@class="dl dl-fb2"]/@href')) - epub = ''.join(data.xpath('.//a[@class="dl dl-epub"]/@href')) - txt = ''.join(data.xpath('.//a[@class="dl dl-txt"]/@href')) - - # remove .zip extensions - if fb2.find('.zip') != -1: - fb2 = fb2[:fb2.find('.zip')] - if epub.find('.zip') != -1: - epub = epub[:epub.find('.zip')] - if txt.find('.zip') != -1: - txt = txt[:txt.find('.zip')] - counter -= 1 s = SearchResult() - s.cover_url = cover_url - s.title = title.strip() - s.author = author.strip() - s.detail_item = id.strip() + s.cover_url = ''.join(data.xpath('.//a[@class="booklink"]/img/@src')).strip() + s.title = ''.join(data.xpath('.//a[@class="booklink"]/i/text()')).strip() + s.author = ''.join(data.xpath('.//span[@class="bookauthor"]/a/text()')).strip() + s.detail_item = id s.drm = SearchResult.DRM_UNLOCKED - s.downloads['FB2'] = base_url + fb2.strip() - s.downloads['EPUB'] = base_url + epub.strip() - s.downloads['TXT'] = base_url + txt.strip() + s.downloads['FB2'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-fb2"]/@href')).strip().replace('.zip', '') + s.downloads['EPUB'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-epub"]/@href')).strip().replace('.zip', '') + s.downloads['TXT'] = base_url + ''.join(data.xpath('.//a[@class="dl dl-txt"]/@href')).strip().replace('.zip', '') s.formats = 'FB2, EPUB, TXT, SFB' yield s 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..b2f5f170b6 --- /dev/null +++ b/src/calibre/gui2/store/stores/eknigi_plugin.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, Alex Stanev ' +__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 eKnigiStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + # Use Kovid's affiliate id 30% of the time + if random.randint(1, 10) in (1, 2, 3): + aff_suffix = '&amigosid=23' + else: + aff_suffix = '&amigosid=22' + url = 'http://e-knigi.net/?' + aff_suffix[1:] + + 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