Merge lp:~tomek3d/calibre/store into lp:calibre

Proposed by Tomasz Długosz
Status: Merged
Merged at revision: 13729
Proposed branch: lp:~tomek3d/calibre/store
Merge into: lp:calibre
Diff against target: 303 lines (+109/-107)
4 files modified
src/calibre/customize/builtins.py (+11/-11)
src/calibre/gui2/store/stores/gandalf_plugin.py (+0/-82)
src/calibre/gui2/store/stores/legimi_plugin.py (+18/-14)
src/calibre/gui2/store/stores/publio_plugin.py (+80/-0)
To merge this branch: bzr merge lp:~tomek3d/calibre/store
Reviewer Review Type Date Requested Status
Kovid Goyal Pending
Review via email: mp+135792@code.launchpad.net

Description of the change

Publio added, Legimi updated, Gandalf removed.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/calibre/customize/builtins.py'
--- src/calibre/customize/builtins.py 2012-11-20 10:47:44 +0000
+++ src/calibre/customize/builtins.py 2012-11-22 22:41:20 +0000
@@ -1433,15 +1433,6 @@
1433 formats = ['EPUB', 'PDF']1433 formats = ['EPUB', 'PDF']
1434 affiliate = True1434 affiliate = True
14351435
1436class StoreGandalfStore(StoreBase):
1437 name = 'Gandalf'
1438 author = u'Tomasz Długosz'
1439 description = u'Księgarnia internetowa Gandalf.'
1440 actual_plugin = 'calibre.gui2.store.stores.gandalf_plugin:GandalfStore'
1441
1442 headquarters = 'PL'
1443 formats = ['EPUB', 'PDF']
1444
1445class StoreGoogleBooksStore(StoreBase):1436class StoreGoogleBooksStore(StoreBase):
1446 name = 'Google Books'1437 name = 'Google Books'
1447 description = u'Google Books'1438 description = u'Google Books'
@@ -1472,7 +1463,7 @@
1472class StoreLegimiStore(StoreBase):1463class StoreLegimiStore(StoreBase):
1473 name = 'Legimi'1464 name = 'Legimi'
1474 author = u'Tomasz Długosz'1465 author = u'Tomasz Długosz'
1475 description = u'Tanie oraz darmowe ebooki, egazety i blogi w formacie EPUB, wprost na Twój e-czytnik, iPhone, iPad, Android i komputer'1466 description = u'Ebooki w formacie EPUB, MOBI i PDF'
1476 actual_plugin = 'calibre.gui2.store.stores.legimi_plugin:LegimiStore'1467 actual_plugin = 'calibre.gui2.store.stores.legimi_plugin:LegimiStore'
14771468
1478 headquarters = 'PL'1469 headquarters = 'PL'
@@ -1566,6 +1557,15 @@
1566 headquarters = 'US'1557 headquarters = 'US'
1567 formats = ['EPUB', 'MOBI', 'PDF']1558 formats = ['EPUB', 'MOBI', 'PDF']
15681559
1560class StorePublioStore(StoreBase):
1561 name = 'Publio'
1562 description = u'Publio.pl to księgarnia internetowa, w której mogą Państwo nabyć e-booki i audiobooki.'
1563 actual_plugin = 'calibre.gui2.store.stores.publio_plugin:PublioStore'
1564 author = u'Tomasz Długosz'
1565
1566 headquarters = 'PL'
1567 formats = ['EPUB', 'MOBI', 'PDF']
1568
1569class StoreRW2010Store(StoreBase):1569class StoreRW2010Store(StoreBase):
1570 name = 'RW2010'1570 name = 'RW2010'
1571 description = u'Polski serwis self-publishingowy. Pliki PDF, EPUB i MOBI. Maksymalna cena utworu nie przekracza u nas 10 złotych!'1571 description = u'Polski serwis self-publishingowy. Pliki PDF, EPUB i MOBI. Maksymalna cena utworu nie przekracza u nas 10 złotych!'
@@ -1675,7 +1675,6 @@
1675 StoreEscapeMagazineStore,1675 StoreEscapeMagazineStore,
1676 StoreFeedbooksStore,1676 StoreFeedbooksStore,
1677 StoreFoylesUKStore,1677 StoreFoylesUKStore,
1678 StoreGandalfStore,
1679 StoreGoogleBooksStore,1678 StoreGoogleBooksStore,
1680 StoreGutenbergStore,1679 StoreGutenbergStore,
1681 StoreKoboStore,1680 StoreKoboStore,
@@ -1689,6 +1688,7 @@
1689 StoreOpenBooksStore,1688 StoreOpenBooksStore,
1690 StoreOzonRUStore,1689 StoreOzonRUStore,
1691 StorePragmaticBookshelfStore,1690 StorePragmaticBookshelfStore,
1691 StorePublioStore,
1692 StoreRW2010Store,1692 StoreRW2010Store,
1693 StoreSmashwordsStore,1693 StoreSmashwordsStore,
1694 StoreVirtualoStore,1694 StoreVirtualoStore,
16951695
=== removed file 'src/calibre/gui2/store/stores/gandalf_plugin.py'
--- src/calibre/gui2/store/stores/gandalf_plugin.py 2012-01-30 21:43:19 +0000
+++ src/calibre/gui2/store/stores/gandalf_plugin.py 1970-01-01 00:00:00 +0000
@@ -1,82 +0,0 @@
1# -*- coding: utf-8 -*-
2
3from __future__ import (unicode_literals, division, absolute_import, print_function)
4
5__license__ = 'GPL 3'
6__copyright__ = '2011-2012, Tomasz Długosz <tomek3d@gmail.com>'
7__docformat__ = 'restructuredtext en'
8
9import re
10import urllib
11from contextlib import closing
12
13from lxml import html
14
15from PyQt4.Qt import QUrl
16
17from calibre import browser, url_slash_cleaner
18from calibre.gui2 import open_url
19from calibre.gui2.store import StorePlugin
20from calibre.gui2.store.basic_config import BasicStoreConfig
21from calibre.gui2.store.search_result import SearchResult
22from calibre.gui2.store.web_store_dialog import WebStoreDialog
23
24class GandalfStore(BasicStoreConfig, StorePlugin):
25
26 def open(self, parent=None, detail_item=None, external=False):
27 url = 'http://www.gandalf.com.pl/ebooks/'
28
29 if external or self.config.get('open_external', False):
30 open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url)))
31 else:
32 d = WebStoreDialog(self.gui, url, parent, detail_item)
33 d.setWindowTitle(self.name)
34 d.set_tags(self.config.get('tags', ''))
35 d.exec_()
36
37 def search(self, query, max_results=10, timeout=60):
38 counter = max_results
39 page = 1
40 url = 'http://www.gandalf.com.pl/we/' + urllib.quote_plus(query.decode('utf-8').encode('iso8859_2')) + '/bdb'
41
42 br = browser()
43
44 while counter:
45 with closing(br.open((url + str(page-1) + '/#s') if (page-1) else (url + '/#s'), timeout=timeout)) as f:
46 doc = html.fromstring(f.read())
47 for data in doc.xpath('//div[@class="box"]'):
48 if counter <= 0:
49 break
50
51 id = ''.join(data.xpath('.//div[@class="info"]/h3/a/@href'))
52 if not id:
53 continue
54
55 cover_url = ''.join(data.xpath('.//div[@class="info"]/h3/a/@id'))
56 title = ''.join(data.xpath('.//div[@class="info"]/h3/a/@title'))
57 formats = ''.join(data.xpath('.//div[@class="info"]/p[1]/text()'))
58 formats = re.findall(r'\((.*?)\)',formats)[0]
59 author = ''.join(data.xpath('.//div[@class="info"]/h4/text() | .//div[@class="info"]/h4/span/text()'))
60 price = ''.join(data.xpath('.//div[@class="options"]/h3/text()'))
61 price = re.sub('PLN', 'zł', price)
62 price = re.sub('\.', ',', price)
63 drm = data.xpath('boolean(.//div[@class="info" and contains(., "Zabezpieczenie: DRM")])')
64
65 counter -= 1
66
67 s = SearchResult()
68 s.cover_url = 'http://imguser.gandalf.com.pl/' + re.sub('p', 'p_', cover_url) + '.jpg'
69 s.title = title.strip()
70 s.author = author.strip()
71 s.price = price
72 s.detail_item = id.strip()
73 if drm:
74 s.drm = SearchResult.DRM_LOCKED
75 else:
76 s.drm = SearchResult.DRM_UNLOCKED
77 s.formats = formats.upper().strip()
78
79 yield s
80 if not doc.xpath('boolean(//div[@class="wyszukiwanie_podstawowe_header"]//div[@class="box"])'):
81 break
82 page+=1
830
=== modified file 'src/calibre/gui2/store/stores/legimi_plugin.py'
--- src/calibre/gui2/store/stores/legimi_plugin.py 2012-08-15 20:09:42 +0000
+++ src/calibre/gui2/store/stores/legimi_plugin.py 2012-11-22 22:41:20 +0000
@@ -25,7 +25,7 @@
2525
26 def open(self, parent=None, detail_item=None, external=False):26 def open(self, parent=None, detail_item=None, external=False):
27 27
28 plain_url = 'http://www.legimi.com/pl/ebooks/?price=any'28 plain_url = 'http://www.legimi.com/pl/ebooki/'
29 url = 'https://ssl.afiliant.com/affskrypt,,2f9de2,,11483,,,?u=(' + plain_url + ')'29 url = 'https://ssl.afiliant.com/affskrypt,,2f9de2,,11483,,,?u=(' + plain_url + ')'
30 detail_url = None30 detail_url = None
3131
@@ -41,32 +41,36 @@
41 d.exec_()41 d.exec_()
4242
43 def search(self, query, max_results=10, timeout=60):43 def search(self, query, max_results=10, timeout=60):
44 url = 'http://www.legimi.com/pl/ebooks/?price=any&lang=pl&search=' + urllib.quote_plus(query) + '&sort=relevance'44 url = 'http://www.legimi.com/pl/ebooki/?szukaj=' + urllib.quote_plus(query)
45 45
46 br = browser()46 br = browser()
47 drm_pattern = re.compile("(DRM)")47 drm_pattern = re.compile("zabezpieczona DRM")
48 48
49 counter = max_results49 counter = max_results
50 with closing(br.open(url, timeout=timeout)) as f:50 with closing(br.open(url, timeout=timeout)) as f:
51 doc = html.fromstring(f.read())51 doc = html.fromstring(f.read())
52 for data in doc.xpath('//div[@class="list"]/ul/li'):52 for data in doc.xpath('//div[@id="listBooks"]/div'):
53 if counter <= 0:53 if counter <= 0:
54 break54 break
55 55
56 id = ''.join(data.xpath('.//div[@class="item_cover_container"]/a[1]/@href'))56 id = ''.join(data.xpath('.//a[@class="plainLink"]/@href'))
57 if not id:57 if not id:
58 continue58 continue
5959
60 cover_url = ''.join(data.xpath('.//div[@class="item_cover_container"]/a/img/@src'))60 cover_url = ''.join(data.xpath('.//img[1]/@src'))
61 title = ''.join(data.xpath('.//div[@class="item_entries"]/h2/a/text()'))61 title = ''.join(data.xpath('.//span[@class="bookListTitle ellipsis"]/text()'))
62 author = ''.join(data.xpath('.//div[@class="item_entries"]/span[1]/a/text()'))62 author = ''.join(data.xpath('.//span[@class="bookListAuthor ellipsis"]/text()'))
63 author = re.sub(',','',author)63 author = re.sub(',','',author)
64 author = re.sub(';',',',author)64 author = re.sub(';',',',author)
65 price = ''.join(data.xpath('.//span[@class="ebook_price"]/text()'))65 price = ''.join(data.xpath('.//div[@class="bookListPrice"]/span/text()'))
66 formats = ''.join(data.xpath('.//div[@class="item_entries"]/span[3]/text()'))66 formats = []
67 formats = re.sub('Format:','',formats)67 with closing(br.open(id.strip(), timeout=timeout/4)) as nf:
68 drm = drm_pattern.search(formats)68 idata = html.fromstring(nf.read())
69 formats = re.sub('\(DRM\)','',formats)69 formatlist = idata.xpath('.//div[@id="fullBookFormats"]//span[@class="bookFormat"]/text()')
70 for x in formatlist:
71 if x.strip() not in formats:
72 formats.append(x.strip())
73 drm = drm_pattern.search(''.join(idata.xpath('.//div[@id="fullBookFormats"]/p/text()')))
7074
71 counter -= 175 counter -= 1
72 76
@@ -76,7 +80,7 @@
76 s.author = author.strip()80 s.author = author.strip()
77 s.price = price81 s.price = price
78 s.detail_item = 'http://www.legimi.com/' + id.strip()82 s.detail_item = 'http://www.legimi.com/' + id.strip()
83 s.formats = ', '.join(formats)
79 s.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED84 s.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED
80 s.formats = formats.strip()
81 85
82 yield s86 yield s
8387
=== added file 'src/calibre/gui2/store/stores/publio_plugin.py'
--- src/calibre/gui2/store/stores/publio_plugin.py 1970-01-01 00:00:00 +0000
+++ src/calibre/gui2/store/stores/publio_plugin.py 2012-11-22 22:41:20 +0000
@@ -0,0 +1,80 @@
1# -*- coding: utf-8 -*-
2
3from __future__ import (unicode_literals, division, absolute_import, print_function)
4
5__license__ = 'GPL 3'
6__copyright__ = '2012, Tomasz Długosz <tomek3d@gmail.com>'
7__docformat__ = 'restructuredtext en'
8
9import re
10import urllib
11from contextlib import closing
12
13from lxml import html
14
15from PyQt4.Qt import QUrl
16
17from calibre import browser, url_slash_cleaner
18from calibre.gui2 import open_url
19from calibre.gui2.store import StorePlugin
20from calibre.gui2.store.basic_config import BasicStoreConfig
21from calibre.gui2.store.search_result import SearchResult
22from calibre.gui2.store.web_store_dialog import WebStoreDialog
23
24class PublioStore(BasicStoreConfig, StorePlugin):
25
26 def open(self, parent=None, detail_item=None, external=False):
27 google_analytics = '?utm_source=tdcalibre&utm_medium=calibre'
28 url = 'http://www.publio.pl/e-booki.html' + google_analytics
29
30 if external or self.config.get('open_external', False):
31 open_url(QUrl(url_slash_cleaner((detail_item + google_analytics) if detail_item else url)))
32 else:
33 d = WebStoreDialog(self.gui, url, parent, detail_item)
34 d.setWindowTitle(self.name)
35 d.set_tags(self.config.get('tags', ''))
36 d.exec_()
37
38 def search(self, query, max_results=20, timeout=60):
39
40 br = browser()
41
42 counter = max_results
43 page = 1
44 while counter:
45 with closing(br.open('http://www.publio.pl/e-booki,strona' + str(page) + '.html?q=' + urllib.quote(query), timeout=timeout)) as f:
46 doc = html.fromstring(f.read())
47 for data in doc.xpath('//div[@class="item"]'):
48 if counter <= 0:
49 break
50
51 id = ''.join(data.xpath('.//div[@class="img"]/a/@href'))
52 if not id:
53 continue
54
55 cover_url = ''.join(data.xpath('.//div[@class="img"]/a/img/@data-original'))
56 title = ''.join(data.xpath('.//div[@class="desc"]/h4/a/text()'))
57 title2 = ''.join(data.xpath('.//div[@class="desc"]/h5/a/text()'))
58 if title2:
59 title = title + '. ' + title2
60 author = ', '.join(data.xpath('./div[@class="desc"]/div[@class="detailShortList"]/div[@class="row"]/a/text()'))
61 price = ''.join(data.xpath('.//div[@class="priceBoxContener "]/div/ins/text()'))
62 if not price:
63 price = ''.join(data.xpath('.//div[@class="priceBoxContener "]/div/text()'))
64 formats = ', '.join(data.xpath('.//div[@class="formats"]/a/img/@alt'))
65
66 counter -= 1
67
68 s = SearchResult()
69 s.cover_url = 'http://www.publio.pl' + cover_url
70 s.title = title.strip()
71 s.author = author.strip()
72 s.price = price.strip()
73 s.detail_item = 'http://www.publio.pl' + id.strip()
74 s.drm = SearchResult.DRM_LOCKED if 'DRM' in formats else SearchResult.DRM_UNLOCKED
75 s.formats = formats.replace(' DRM','').strip()
76
77 yield s
78 if not doc.xpath('boolean(//a[@class="next"])'):
79 break
80 page+=1

Subscribers

People subscribed via source and target branches