From e1cf8e63602d9f412997d57e658b3c30a70b0546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Wed, 25 May 2011 21:33:30 +0200 Subject: [PATCH 1/6] Virtualo Store --- src/calibre/customize/builtins.py | 11 ++++ src/calibre/gui2/store/virtualo_plugin.py | 72 +++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/calibre/gui2/store/virtualo_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index d9e8be00b5..ac5377700e 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1346,6 +1346,16 @@ class StoreSmashwordsStore(StoreBase): headquarters = 'US' formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT'] +class StoreVirtualoStore(StoreBase): + name = 'Virtualo' + author = 'Tomasz Długosz' + description = u'Księgarnia internetowa, która oferuje bezpieczny i szeroki dostęp do książek w formie cyfrowej.' + actual_plugin = 'calibre.gui2.store.virtualo_plugin:VirtualoStore' + + drm_free_only = False + location = 'PL' + formats = ['EPUB', 'PDF'] + class StoreWaterstonesUKStore(StoreBase): name = 'Waterstones UK' author = 'Charles Haley' @@ -1411,6 +1421,7 @@ plugins += [ StoreOReillyStore, StorePragmaticBookshelfStore, StoreSmashwordsStore, + StoreVirtualoStore, StoreWaterstonesUKStore, StoreWeightlessBooksStore, StoreWizardsTowerBooksStore, diff --git a/src/calibre/gui2/store/virtualo_plugin.py b/src/calibre/gui2/store/virtualo_plugin.py new file mode 100644 index 0000000000..b1fe0091b6 --- /dev/null +++ b/src/calibre/gui2/store/virtualo_plugin.py @@ -0,0 +1,72 @@ +# -*- 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 VirtualoStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + url = 'http://virtualo.pl/ebook/c2/' + detail_url = None + + 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_url) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=10, timeout=60): + url = 'http://virtualo.pl/c2/?q=' + urllib.quote(query.encode('utf-8')) + + 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[@id="product_list"]/div/div[@class="column"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//table/tr[2]/td[1]/a/@href')) + if not id: + continue + + price = ''.join(data.xpath('.//span[@class="price"]/text() | .//span[@class="price abbr"]/text()')) + cover_url = ''.join(data.xpath('.//table/tr[2]/td[1]/a/img/@src')) + title = ''.join(data.xpath('.//div[@class="title"]/a/text()')) + author = ', '.join(data.xpath('.//div[@class="authors"]/a/text()')) + formats = ', '.join(data.xpath('.//span[@class="format"]/a/text()')) + formats = re.sub(r'(, )?ONLINE(, )?', '', formats) + + counter -= 1 + + s = SearchResult() + s.cover_url = cover_url + s.title = title.strip() + ' ' + formats + s.author = author.strip() + s.price = price + ' zł' + s.detail_item = 'http://virtualo.pl' + id.strip() + s.formats = formats.upper().strip() + s.drm = SearchResult.DRM_LOCKED if formats == 'EPUB' else SearchResult.DRM_UNKNOWN + + yield s From df81def0cf452d5063567e5aae8cdccf5f2e1c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Wed, 25 May 2011 21:44:33 +0200 Subject: [PATCH 2/6] fix Virtualo headquarters --- src/calibre/customize/builtins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 5a56a89cf0..14565da152 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1353,7 +1353,7 @@ class StoreVirtualoStore(StoreBase): actual_plugin = 'calibre.gui2.store.virtualo_plugin:VirtualoStore' drm_free_only = False - location = 'PL' + headquarters = 'PL' formats = ['EPUB', 'PDF'] class StoreWaterstonesUKStore(StoreBase): From 75782ed4f2c0dec3f27a440f831f455bee8400dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Wed, 25 May 2011 21:56:08 +0200 Subject: [PATCH 3/6] fix headquarters in chooser --- src/calibre/gui2/store/config/chooser/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/store/config/chooser/models.py b/src/calibre/gui2/store/config/chooser/models.py index 460b698878..f76ca45a01 100644 --- a/src/calibre/gui2/store/config/chooser/models.py +++ b/src/calibre/gui2/store/config/chooser/models.py @@ -132,7 +132,7 @@ class Matches(QAbstractItemModel): elif col == 2: text = 'b' if match.drm else 'a' elif col == 3: - text = match.headquarteres + text = match.headquarters return text def sort(self, col, order, reset=True): @@ -241,4 +241,4 @@ class SearchFilter(SearchQueryParser): traceback.print_exc() return matches - \ No newline at end of file + From 3734b12cc5a0d36d528bc2c4281d87c04bd1d231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Wed, 25 May 2011 22:05:06 +0200 Subject: [PATCH 4/6] not all EPUBs have DRM in Virtualo --- src/calibre/gui2/store/virtualo_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/store/virtualo_plugin.py b/src/calibre/gui2/store/virtualo_plugin.py index b1fe0091b6..d86aa3e0e5 100644 --- a/src/calibre/gui2/store/virtualo_plugin.py +++ b/src/calibre/gui2/store/virtualo_plugin.py @@ -67,6 +67,6 @@ class VirtualoStore(BasicStoreConfig, StorePlugin): s.price = price + ' zł' s.detail_item = 'http://virtualo.pl' + id.strip() s.formats = formats.upper().strip() - s.drm = SearchResult.DRM_LOCKED if formats == 'EPUB' else SearchResult.DRM_UNKNOWN + s.drm = SearchResult.DRM_UNKNOWN yield s From 7b98249b90366e26900d2b2cc5a86ff54595b083 Mon Sep 17 00:00:00 2001 From: John Schember Date: Wed, 25 May 2011 17:51:29 -0400 Subject: [PATCH 5/6] Store: chooser, fix sorting by drm. --- src/calibre/gui2/store/config/chooser/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/store/config/chooser/models.py b/src/calibre/gui2/store/config/chooser/models.py index 0c784f6614..3ceed6fb00 100644 --- a/src/calibre/gui2/store/config/chooser/models.py +++ b/src/calibre/gui2/store/config/chooser/models.py @@ -130,7 +130,7 @@ class Matches(QAbstractItemModel): elif col == 1: text = match.name elif col == 2: - text = 'b' if getattr(match, 'drm', True) else 'a' + text = 'a' if getattr(match, 'drm_free_only', True) else 'b' elif col == 3: text = getattr(match, 'headquarters', '') return text From 47cd16b6656e3f830f67fabc36fd3169242293c3 Mon Sep 17 00:00:00 2001 From: John Schember Date: Wed, 25 May 2011 18:53:11 -0400 Subject: [PATCH 6/6] Store: ... --- src/calibre/customize/builtins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 14565da152..bbbb8a738f 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1348,7 +1348,7 @@ class StoreSmashwordsStore(StoreBase): class StoreVirtualoStore(StoreBase): name = 'Virtualo' - author = 'Tomasz Długosz' + author = u'Tomasz Długosz' description = u'Księgarnia internetowa, która oferuje bezpieczny i szeroki dostęp do książek w formie cyfrowej.' actual_plugin = 'calibre.gui2.store.virtualo_plugin:VirtualoStore' @@ -1386,7 +1386,7 @@ class StoreWizardsTowerBooksStore(StoreBase): class StoreWoblinkStore(StoreBase): name = 'Woblink' - author = 'Tomasz Długosz' + author = u'Tomasz Długosz' description = u'Czytanie zdarza się wszędzie!' actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore'