From d43178b0910318adf0d41285e3bd00122f45c894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Tue, 9 Aug 2011 20:34:04 +0200 Subject: [PATCH 1/3] escapemagazine plugin --- src/calibre/customize/builtins.py | 12 ++++ .../store/stores/escapemagazine_plugin.py | 71 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/calibre/gui2/store/stores/escapemagazine_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 620254b1f5..0bdabe3bd3 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1257,6 +1257,17 @@ class StoreEKnigiStore(StoreBase): formats = ['EPUB', 'PDF', 'HTML'] affiliate = True +class StoreEscapeMagazineStore(StoreBase): + name = 'EscapeMagazine' + author = 'Tomasz Długosz' + description = u'Książki elektroniczne w formie pliku komputerowego PDF. Zabezpieczone hasłem.' + actual_plugin = 'calibre.gui2.store.stores.escapemagazine_plugin:EscapeMagazineStore' + + drm_free_only = True + headquarters = 'PL' + formats = ['PDF'] + affiliate = True + class StoreFeedbooksStore(StoreBase): name = 'Feedbooks' description = u'Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.' @@ -1485,6 +1496,7 @@ plugins += [ StoreEBookShoppeUKStore, StoreEHarlequinStore, StoreEKnigiStore, + StoreEscapeMagazineStore, StoreFeedbooksStore, StoreFoylesUKStore, StoreGandalfStore, diff --git a/src/calibre/gui2/store/stores/escapemagazine_plugin.py b/src/calibre/gui2/store/stores/escapemagazine_plugin.py new file mode 100644 index 0000000000..5d1c2dcae1 --- /dev/null +++ b/src/calibre/gui2/store/stores/escapemagazine_plugin.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, Tomasz Długosz ' +__docformat__ = 'restructuredtext en' + +import re +import urllib +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 EscapeMagazineStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + pid = '44010' + + url = 'http://www.escapemagazine.pl/s/' + pid + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner(detail_item + '/s/' + pid if detail_item else url))) + else: + d = WebStoreDialog(self.gui, url, parent, detail_item) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=20, timeout=60): + url = 'http://www.escapemagazine.pl/wyszukiwarka?query=' + urllib.quote_plus(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 item_short"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//h2[@class="title"]/a[1]/@href')) + if not id: + continue + + title = ''.join(data.xpath('.//h2[@class="title"]/a[1]/text()')) + author = ''.join(data.xpath('.//div[@class="author"]/text()')) + price = ''.join(data.xpath('.//span[@class="price_now"]/strong/text()')) + ' zł' + cover_url = ''.join(data.xpath('.//img[@class="cover"]/@src')) + + counter -= 1 + + s = SearchResult() + s.cover_url = cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price + s.detail_item = 'http://www.escapemagazine.pl' + id.strip() + s.drm = SearchResult.DRM_UNLOCKED + s.formats = 'PDF' + + yield s From b21d13350e5d2c983375f15a29ef4fa26a316c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sat, 27 Aug 2011 22:17:45 +0200 Subject: [PATCH 2/3] rw2010 plugin --- src/calibre/customize/builtins.py | 11 +++ .../gui2/store/stores/rw2010_plugin.py | 77 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/calibre/gui2/store/stores/rw2010_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 7740329795..9cfb765b74 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1424,6 +1424,16 @@ class StorePragmaticBookshelfStore(StoreBase): headquarters = 'US' formats = ['EPUB', 'MOBI', 'PDF'] +class StoreRW2010Store(StoreBase): + name = 'RW2010' + description = u'Polski serwis self-publishingowy. Pliki PDF, EPUB i MOBI. Maksymalna cena utworu nie przekracza u nas 10 złotych!' + actual_plugin = 'calibre.gui2.store.stores.rw2010_plugin:RW2010Store' + author = 'Tomasz Długosz' + + drm_free_only = True + headquarters = 'PL' + formats = ['EPUB', 'MOBI', 'PDF'] + class StoreSmashwordsStore(StoreBase): name = 'Smashwords' description = u'An ebook publishing and distribution platform for ebook authors, publishers and readers. Covers many genres and formats.' @@ -1538,6 +1548,7 @@ plugins += [ StoreOReillyStore, StoreOzonRUStore, StorePragmaticBookshelfStore, + StoreRW2010Store, StoreSmashwordsStore, StoreVirtualoStore, StoreWaterstonesUKStore, diff --git a/src/calibre/gui2/store/stores/rw2010_plugin.py b/src/calibre/gui2/store/stores/rw2010_plugin.py new file mode 100644 index 0000000000..4726b2b980 --- /dev/null +++ b/src/calibre/gui2/store/stores/rw2010_plugin.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, Tomasz Długosz ' +__docformat__ = 'restructuredtext en' + +import re +import urllib +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 RW2010Store(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + url = 'http://www.rw2010.pl/' + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url))) + else: + d = WebStoreDialog(self.gui, url, parent, detail_item) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=10, timeout=60): + url = 'http://www.rw2010.pl/go.live.php/?launch_macro=catalogue-search-rd' + values={ + 'fkeyword': query, + 'file_type':'' + } + + br = browser() + + counter = max_results + with closing(br.open(url, data=urllib.urlencode(values), timeout=timeout)) as f: + doc = html.fromstring(f.read()) + for data in doc.xpath('//div[@class="ProductDetail"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//div[@class="img"]/a/@href')) + if not id: + continue + + with closing(br.open(id.strip(), timeout=timeout/4)) as nf: + idata = html.fromstring(nf.read()) + cover_url = ''.join(idata.xpath('//div[@class="boxa"]/div[1]/img/@src')) + author = ''.join(idata.xpath('//div[@class="boxb"]/h3[3]/span/text()')) + title = ''.join(idata.xpath('//div[@class="boxb"]/h2[1]/text()')) + title = re.sub(r'\(#.+\)', '', title) + formats = ''.join(idata.xpath('//div[@class="boxb"]/h3[6]/span/text()')) + price = ''.join(idata.xpath('//div[@class="price-box"]/span/text()')) + ',00 zł' + + counter -= 1 + + s = SearchResult() + s.cover_url = 'http://www.rw2010.pl/' + cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price + s.detail_item = re.sub(r'%3D', '=', id) + s.drm = SearchResult.DRM_UNLOCKED + s.formats = formats[0:-2].upper() + + yield s From 6a3ad1d22f8a214f8f83e12bf3fd7e60bb9a500f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sat, 27 Aug 2011 22:44:44 +0200 Subject: [PATCH 3/3] improved HTML parsing --- src/calibre/gui2/store/stores/rw2010_plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/store/stores/rw2010_plugin.py b/src/calibre/gui2/store/stores/rw2010_plugin.py index 4726b2b980..ed4d5a53f7 100644 --- a/src/calibre/gui2/store/stores/rw2010_plugin.py +++ b/src/calibre/gui2/store/stores/rw2010_plugin.py @@ -56,11 +56,11 @@ class RW2010Store(BasicStoreConfig, StorePlugin): with closing(br.open(id.strip(), timeout=timeout/4)) as nf: idata = html.fromstring(nf.read()) - cover_url = ''.join(idata.xpath('//div[@class="boxa"]/div[1]/img/@src')) - author = ''.join(idata.xpath('//div[@class="boxb"]/h3[3]/span/text()')) + cover_url = ''.join(idata.xpath('//div[@class="boxa"]//div[@class="img"]/img/@src')) + author = ''.join(idata.xpath('//div[@class="boxb"]//h3[text()="Autor: "]/span/text()')) title = ''.join(idata.xpath('//div[@class="boxb"]/h2[1]/text()')) title = re.sub(r'\(#.+\)', '', title) - formats = ''.join(idata.xpath('//div[@class="boxb"]/h3[6]/span/text()')) + formats = ''.join(idata.xpath('//div[@class="boxb"]//h3[text()="Format pliku: "]/span/text()')) price = ''.join(idata.xpath('//div[@class="price-box"]/span/text()')) + ',00 zł' counter -= 1