From 381cd47f71408ab09e93322e5042fb03c4fd7b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sun, 7 Apr 2013 15:55:10 +0200 Subject: [PATCH 1/7] koobe draft --- src/calibre/customize/builtins.py | 9 +++ src/calibre/gui2/store/stores/koobe_plugin.py | 71 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/calibre/gui2/store/stores/koobe_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 474617c911..c14cd26c6e 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1467,6 +1467,15 @@ class StoreKoboStore(StoreBase): formats = ['EPUB'] affiliate = True +class StoreBookotekaStore(StoreBase): + name = 'Koobe' + author = u'Tomasz Długosz' + description = u'Księgarnia internetowa oferuje ebooki (książki elektroniczne) w postaci plików epub, mobi i pdf.' + actual_plugin = 'calibre.gui2.store.stores.koobe_plugin:KoobeStore' + + headquarters = 'PL' + formats = ['EPUB', 'MOBI', 'PDF'] + class StoreLegimiStore(StoreBase): name = 'Legimi' author = u'Tomasz Długosz' diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py new file mode 100644 index 0000000000..ffb9a26a7f --- /dev/null +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) +store_version = 1 # Needed for dynamic plugin loading + +__license__ = 'GPL 3' +__copyright__ = '2013, 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 KoobeStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + url = 'http://www.koobe.pl/' + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner(detail_item))) + 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=12, timeout=60): + url = 'http://www.koobe.pl/szukaj/fraza:' + urllib.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="seach_result"]/div[@class="result"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//div[@class="cover"]/a/@href')) + if not id: + continue + + cover_url = ''.join(data.xpath('.//div[@class="cover"]/a/img/@src')) + price = ''.join(data.xpath('.//span[@class="current_price"]/text()')) + title = ''.join(data.xpath('.//h2[@class="title"]/a/text()')) + author = ''.join(data.xpath('.//h3[@class="book_author"]/a/text()')) + formats = ''.join(data.xpath('.//div[@class="formats"]/div/div/@title')) + + counter -= 1 + + s = SearchResult() + s.cover_url = 'http://koobe.pl/' + cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price + ' zł' + s.detail_item = 'http://koobe.pl' + id[1:] + s.formats = ', '.join(formats).upper() + s.drm = SearchResult.DRM_UNKNOWN + + yield s From 3f05d5fabb64c15f092520b8df4f48a447d9d65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sun, 7 Apr 2013 21:35:43 +0200 Subject: [PATCH 2/7] fix formats and price improvement in koobe --- src/calibre/gui2/store/stores/koobe_plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py index ffb9a26a7f..0370e70666 100644 --- a/src/calibre/gui2/store/stores/koobe_plugin.py +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -55,7 +55,7 @@ class KoobeStore(BasicStoreConfig, StorePlugin): price = ''.join(data.xpath('.//span[@class="current_price"]/text()')) title = ''.join(data.xpath('.//h2[@class="title"]/a/text()')) author = ''.join(data.xpath('.//h3[@class="book_author"]/a/text()')) - formats = ''.join(data.xpath('.//div[@class="formats"]/div/div/@title')) + formats = ', '.join(data.xpath('.//div[@class="formats"]/div/div/@title')) counter -= 1 @@ -63,9 +63,9 @@ class KoobeStore(BasicStoreConfig, StorePlugin): s.cover_url = 'http://koobe.pl/' + cover_url s.title = title.strip() s.author = author.strip() - s.price = price + ' zł' + s.price = price s.detail_item = 'http://koobe.pl' + id[1:] - s.formats = ', '.join(formats).upper() + s.formats = formats.upper() s.drm = SearchResult.DRM_UNKNOWN yield s From 0b98eb5b38e45c71cd08c68024993a814f1f52f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sun, 7 Apr 2013 21:38:50 +0200 Subject: [PATCH 3/7] koobe in builtins --- src/calibre/customize/builtins.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index c14cd26c6e..883aba20f2 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1467,7 +1467,7 @@ class StoreKoboStore(StoreBase): formats = ['EPUB'] affiliate = True -class StoreBookotekaStore(StoreBase): +class StoreKoobeStore(StoreBase): name = 'Koobe' author = u'Tomasz Długosz' description = u'Księgarnia internetowa oferuje ebooki (książki elektroniczne) w postaci plików epub, mobi i pdf.' @@ -1695,6 +1695,7 @@ plugins += [ StoreGoogleBooksStore, StoreGutenbergStore, StoreKoboStore, + StoreKoobeStore, StoreLegimiStore, StoreLibreDEStore, StoreLitResStore, From dc5e32ae0571fc8236a684958fc739fda0eb9587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Mon, 8 Apr 2013 21:37:14 +0200 Subject: [PATCH 4/7] fix encoding and drm status --- src/calibre/customize/builtins.py | 1 + src/calibre/gui2/store/stores/koobe_plugin.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 883aba20f2..9d93d1e26a 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1473,6 +1473,7 @@ class StoreKoobeStore(StoreBase): description = u'Księgarnia internetowa oferuje ebooki (książki elektroniczne) w postaci plików epub, mobi i pdf.' actual_plugin = 'calibre.gui2.store.stores.koobe_plugin:KoobeStore' + drm_free_only = True headquarters = 'PL' formats = ['EPUB', 'MOBI', 'PDF'] diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py index 0370e70666..c3c58532e6 100644 --- a/src/calibre/gui2/store/stores/koobe_plugin.py +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import (unicode_literals, division, absolute_import, print_function) +from __future__ import (division, absolute_import, print_function) store_version = 1 # Needed for dynamic plugin loading __license__ = 'GPL 3' @@ -42,7 +42,7 @@ class KoobeStore(BasicStoreConfig, StorePlugin): counter = max_results with closing(br.open(url, timeout=timeout)) as f: - doc = html.fromstring(f.read()) + doc = html.fromstring(f.read().decode('utf-8')) for data in doc.xpath('//div[@class="seach_result"]/div[@class="result"]'): if counter <= 0: break @@ -66,6 +66,6 @@ class KoobeStore(BasicStoreConfig, StorePlugin): s.price = price s.detail_item = 'http://koobe.pl' + id[1:] s.formats = formats.upper() - s.drm = SearchResult.DRM_UNKNOWN + s.drm = SearchResult.DRM_UNLOCKED yield s From 4050fc66ae39c3640fa68ef2b07b54424a843d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Mon, 8 Apr 2013 22:26:26 +0200 Subject: [PATCH 5/7] fetch more than 10 results from kooobe store --- src/calibre/gui2/store/stores/koobe_plugin.py | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py index c3c58532e6..101a87bc6f 100644 --- a/src/calibre/gui2/store/stores/koobe_plugin.py +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -35,37 +35,41 @@ class KoobeStore(BasicStoreConfig, StorePlugin): d.set_tags(self.config.get('tags', '')) d.exec_() - def search(self, query, max_results=12, timeout=60): - url = 'http://www.koobe.pl/szukaj/fraza:' + urllib.quote(query) + def search(self, query, max_results=10, timeout=60): br = browser() + page=1 counter = max_results - with closing(br.open(url, timeout=timeout)) as f: - doc = html.fromstring(f.read().decode('utf-8')) - for data in doc.xpath('//div[@class="seach_result"]/div[@class="result"]'): - if counter <= 0: + while counter: + with closing(br.open('http://www.koobe.pl/s,p,' + str(page) + ',szukaj/fraza:' + urllib.quote(query), timeout=timeout)) as f: + doc = html.fromstring(f.read().decode('utf-8')) + for data in doc.xpath('//div[@class="seach_result"]/div[@class="result"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//div[@class="cover"]/a/@href')) + if not id: + continue + + cover_url = ''.join(data.xpath('.//div[@class="cover"]/a/img/@src')) + price = ''.join(data.xpath('.//span[@class="current_price"]/text()')) + title = ''.join(data.xpath('.//h2[@class="title"]/a/text()')) + author = ''.join(data.xpath('.//h3[@class="book_author"]/a/text()')) + formats = ', '.join(data.xpath('.//div[@class="formats"]/div/div/@title')) + + counter -= 1 + + s = SearchResult() + s.cover_url = 'http://koobe.pl/' + cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price + s.detail_item = 'http://koobe.pl' + id[1:] + s.formats = formats.upper() + s.drm = SearchResult.DRM_UNLOCKED + + yield s + if not doc.xpath('//div[@class="site_bottom"]//a[@class="right"]'): break - - id = ''.join(data.xpath('.//div[@class="cover"]/a/@href')) - if not id: - continue - - cover_url = ''.join(data.xpath('.//div[@class="cover"]/a/img/@src')) - price = ''.join(data.xpath('.//span[@class="current_price"]/text()')) - title = ''.join(data.xpath('.//h2[@class="title"]/a/text()')) - author = ''.join(data.xpath('.//h3[@class="book_author"]/a/text()')) - formats = ', '.join(data.xpath('.//div[@class="formats"]/div/div/@title')) - - counter -= 1 - - s = SearchResult() - s.cover_url = 'http://koobe.pl/' + cover_url - s.title = title.strip() - s.author = author.strip() - s.price = price - s.detail_item = 'http://koobe.pl' + id[1:] - s.formats = formats.upper() - s.drm = SearchResult.DRM_UNLOCKED - - yield s + page+=1 From bf6b5c734908dc1e02b38c091502ff358d38ffad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Thu, 11 Apr 2013 00:33:43 +0200 Subject: [PATCH 6/7] Koobe as an affiliate --- src/calibre/customize/builtins.py | 1 + src/calibre/gui2/store/stores/koobe_plugin.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 9d93d1e26a..d54527bea5 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1476,6 +1476,7 @@ class StoreKoobeStore(StoreBase): drm_free_only = True headquarters = 'PL' formats = ['EPUB', 'MOBI', 'PDF'] + affiliate = True class StoreLegimiStore(StoreBase): name = 'Legimi' diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py index 101a87bc6f..12f1905bfe 100644 --- a/src/calibre/gui2/store/stores/koobe_plugin.py +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -9,6 +9,7 @@ __docformat__ = 'restructuredtext en' import re import urllib +from base64 import b64encode from contextlib import closing from lxml import html @@ -25,12 +26,19 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog class KoobeStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): + aff_root = 'https://www.a4b-tracking.com/pl/stat-click-text-link/15/58/' url = 'http://www.koobe.pl/' + aff_url = aff_root + str(b64encode(url)) + + detail_url = None + if detail_item: + detail_url = aff_root + str(b64encode(detail_item)) + if external or self.config.get('open_external', False): - open_url(QUrl(url_slash_cleaner(detail_item))) + open_url(QUrl(url_slash_cleaner(detail_url if detail_url else aff_url))) else: - d = WebStoreDialog(self.gui, url, parent, detail_item) + d = WebStoreDialog(self.gui, url, parent, detail_url) d.setWindowTitle(self.name) d.set_tags(self.config.get('tags', '')) d.exec_() From 10f603fb527bf628711abe9c59245fd4ea6ab3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Thu, 11 Apr 2013 00:56:34 +0200 Subject: [PATCH 7/7] Woblink as an affiliate --- src/calibre/customize/builtins.py | 1 + src/calibre/gui2/store/stores/koobe_plugin.py | 2 +- src/calibre/gui2/store/stores/woblink_plugin.py | 15 +++++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index d54527bea5..ba5e316c6f 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1660,6 +1660,7 @@ class StoreWoblinkStore(StoreBase): headquarters = 'PL' formats = ['EPUB', 'MOBI', 'PDF', 'WOBLINK'] + affiliate = True class XinXiiStore(StoreBase): name = 'XinXii' diff --git a/src/calibre/gui2/store/stores/koobe_plugin.py b/src/calibre/gui2/store/stores/koobe_plugin.py index 12f1905bfe..343e6ffec9 100644 --- a/src/calibre/gui2/store/stores/koobe_plugin.py +++ b/src/calibre/gui2/store/stores/koobe_plugin.py @@ -38,7 +38,7 @@ class KoobeStore(BasicStoreConfig, StorePlugin): if external or self.config.get('open_external', False): open_url(QUrl(url_slash_cleaner(detail_url if detail_url else aff_url))) else: - d = WebStoreDialog(self.gui, url, parent, detail_url) + d = WebStoreDialog(self.gui, url, parent, detail_url if detail_url else aff_url) d.setWindowTitle(self.name) d.set_tags(self.config.get('tags', '')) d.exec_() diff --git a/src/calibre/gui2/store/stores/woblink_plugin.py b/src/calibre/gui2/store/stores/woblink_plugin.py index 63ec259dbf..596bb76199 100644 --- a/src/calibre/gui2/store/stores/woblink_plugin.py +++ b/src/calibre/gui2/store/stores/woblink_plugin.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- from __future__ import (unicode_literals, division, absolute_import, print_function) -store_version = 1 # Needed for dynamic plugin loading +store_version = 2 # Needed for dynamic plugin loading __license__ = 'GPL 3' -__copyright__ = '2011-2012, Tomasz Długosz ' +__copyright__ = '2011-2013, Tomasz Długosz ' __docformat__ = 'restructuredtext en' import re import urllib +from base64 import b64encode from contextlib import closing from lxml import html @@ -25,17 +26,19 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog class WoblinkStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): - + aff_root = 'https://www.a4b-tracking.com/pl/stat-click-text-link/16/58/' url = 'http://woblink.com/publication' + + aff_url = aff_root + str(b64encode(url)) detail_url = None if detail_item: - detail_url = 'http://woblink.com' + detail_item + detail_url = aff_root + str(b64encode('http://woblink.com' + detail_item)) if external or self.config.get('open_external', False): - open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url))) + open_url(QUrl(url_slash_cleaner(detail_url if detail_url else aff_url))) else: - d = WebStoreDialog(self.gui, url, parent, detail_url) + d = WebStoreDialog(self.gui, url, parent, detail_url if detail_url else aff_url) d.setWindowTitle(self.name) d.set_tags(self.config.get('tags', '')) d.exec_()