Merge lp:~user-none/calibre/dev into lp:calibre

Proposed by John Schember
Status: Merged
Merged at revision: 13638
Proposed branch: lp:~user-none/calibre/dev
Merge into: lp:calibre
Diff against target: 625 lines (+105/-371)
6 files modified
src/calibre/gui2/store/stores/amazon_de_plugin.py (+11/-94)
src/calibre/gui2/store/stores/amazon_es_plugin.py (+10/-71)
src/calibre/gui2/store/stores/amazon_fr_plugin.py (+9/-72)
src/calibre/gui2/store/stores/amazon_it_plugin.py (+10/-71)
src/calibre/gui2/store/stores/amazon_uk_plugin.py (+46/-49)
src/calibre/gui2/store/stores/libri_de_plugin.py (+19/-14)
To merge this branch: bzr merge lp:~user-none/calibre/dev
Reviewer Review Type Date Requested Status
Kovid Goyal Pending
Review via email: mp+133159@code.launchpad.net
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
1=== modified file 'src/calibre/gui2/store/stores/amazon_de_plugin.py'
2--- src/calibre/gui2/store/stores/amazon_de_plugin.py 2012-04-29 08:39:09 +0000
3+++ src/calibre/gui2/store/stores/amazon_de_plugin.py 2012-11-06 23:56:30 +0000
4@@ -6,102 +6,19 @@
5 __copyright__ = '2011, John Schember <john@nachtimwald.com>'
6 __docformat__ = 'restructuredtext en'
7
8-from contextlib import closing
9-
10-from lxml import html
11-
12-from PyQt4.Qt import QUrl
13-
14-from calibre import browser
15-from calibre.gui2 import open_url
16-from calibre.gui2.store import StorePlugin
17-from calibre.gui2.store.search_result import SearchResult
18-
19-class AmazonDEKindleStore(StorePlugin):
20+from calibre.gui2.store.stores.amazon_uk_plugin import AmazonUKKindleStore
21+
22+class AmazonDEKindleStore(AmazonUKKindleStore):
23 '''
24 For comments on the implementation, please see amazon_plugin.py
25 '''
26
27- def open(self, parent=None, detail_item=None, external=False):
28- aff_id = {'tag': 'charhale0a-21'}
29- store_link = ('http://www.amazon.de/gp/redirect.html?ie=UTF8&site-redirect=de'
30- '&tag=%(tag)s&linkCode=ur2&camp=1638&creative=19454'
31- '&location=http://www.amazon.de/ebooks-kindle/b?node=530886031') % aff_id
32- if detail_item:
33- aff_id['asin'] = detail_item
34- store_link = ('http://www.amazon.de/gp/redirect.html?ie=UTF8'
35+ aff_id = {'tag': 'charhale0a-21'}
36+ store_link = ('http://www.amazon.de/gp/redirect.html?ie=UTF8&site-redirect=de'
37+ '&tag=%(tag)s&linkCode=ur2&camp=1638&creative=19454'
38+ '&location=http://www.amazon.de/ebooks-kindle/b?node=530886031')
39+ store_link_details = ('http://www.amazon.de/gp/redirect.html?ie=UTF8'
40 '&location=http://www.amazon.de/dp/%(asin)s&site-redirect=de'
41- '&tag=%(tag)s&linkCode=ur2&camp=1638&creative=6742') % aff_id
42- open_url(QUrl(store_link))
43-
44- def search(self, query, max_results=10, timeout=60):
45- search_url = 'http://www.amazon.de/s/?url=search-alias%3Ddigital-text&field-keywords='
46- url = search_url + query.encode('ascii', 'backslashreplace').replace('%', '%25').replace('\\x', '%').replace(' ', '+')
47- br = browser()
48-
49- counter = max_results
50- with closing(br.open(url, timeout=timeout)) as f:
51- # doc = html.fromstring(f.read().decode('latin-1', 'replace'))
52- # Apparently amazon Europe is responding in UTF-8 now
53- doc = html.fromstring(f.read())
54-
55- data_xpath = '//div[contains(@class, "result") and contains(@class, "product")]'
56- format_xpath = './/span[@class="format"]/text()'
57- cover_xpath = './/img[@class="productImage"]/@src'
58-
59- for data in doc.xpath(data_xpath):
60- if counter <= 0:
61- break
62-
63- # Even though we are searching digital-text only Amazon will still
64- # put in results for non Kindle books (author pages). So we need
65- # to explicitly check if the item is a Kindle book and ignore it
66- # if it isn't.
67- format = ''.join(data.xpath(format_xpath))
68- if 'kindle' not in format.lower():
69- continue
70-
71- # We must have an asin otherwise we can't easily reference the
72- # book later.
73- asin = ''.join(data.xpath("@name"))
74-
75- cover_url = ''.join(data.xpath(cover_xpath))
76-
77- title = ''.join(data.xpath('.//a[@class="title"]/text()'))
78- price = ''.join(data.xpath('.//div[@class="newPrice"]/span[contains(@class, "price")]/text()'))
79-
80- author = ''.join(data.xpath('.//h3[@class="title"]/span[@class="ptBrand"]/text()'))
81- if author.startswith('von '):
82- author = author[4:]
83-
84- counter -= 1
85-
86- s = SearchResult()
87- s.cover_url = cover_url.strip()
88- s.title = title.strip()
89- s.author = author.strip()
90- s.price = price.strip()
91- s.detail_item = asin.strip()
92- s.formats = 'Kindle'
93-
94- yield s
95-
96- def get_details(self, search_result, timeout):
97- drm_search_text = u'Gleichzeitige Verwendung von Geräten'
98- drm_free_text = u'Keine Einschränkung'
99- url = 'http://amazon.de/dp/'
100-
101- br = browser()
102- with closing(br.open(url + search_result.detail_item, timeout=timeout)) as nf:
103- idata = html.fromstring(nf.read())
104- if idata.xpath('boolean(//div[@class="content"]//li/b[contains(text(), "' +
105- drm_search_text + '")])'):
106- if idata.xpath('boolean(//div[@class="content"]//li[contains(., "' +
107- drm_free_text + '") and contains(b, "' +
108- drm_search_text + '")])'):
109- search_result.drm = SearchResult.DRM_UNLOCKED
110- else:
111- search_result.drm = SearchResult.DRM_UNKNOWN
112- else:
113- search_result.drm = SearchResult.DRM_LOCKED
114- return True
115+ '&tag=%(tag)s&linkCode=ur2&camp=1638&creative=6742')
116+ search_url = 'http://www.amazon.de/s/?url=search-alias%3Ddigital-text&field-keywords='
117+
118
119=== modified file 'src/calibre/gui2/store/stores/amazon_es_plugin.py'
120--- src/calibre/gui2/store/stores/amazon_es_plugin.py 2012-04-29 08:39:09 +0000
121+++ src/calibre/gui2/store/stores/amazon_es_plugin.py 2012-11-06 23:56:30 +0000
122@@ -6,78 +6,17 @@
123 __copyright__ = '2011, John Schember <john@nachtimwald.com>'
124 __docformat__ = 'restructuredtext en'
125
126-from contextlib import closing
127-
128-from lxml import html
129-
130-from PyQt4.Qt import QUrl
131-
132-from calibre import browser
133-from calibre.gui2 import open_url
134-from calibre.gui2.store import StorePlugin
135-from calibre.gui2.store.search_result import SearchResult
136-
137-class AmazonESKindleStore(StorePlugin):
138+from calibre.gui2.store.stores.amazon_uk_plugin import AmazonUKKindleStore
139+
140+class AmazonESKindleStore(AmazonUKKindleStore):
141 '''
142 For comments on the implementation, please see amazon_plugin.py
143 '''
144
145- def open(self, parent=None, detail_item=None, external=False):
146- aff_id = {'tag': 'charhale09-21'}
147- store_link = 'http://www.amazon.es/ebooks-kindle/b?_encoding=UTF8&node=827231031&tag=%(tag)s&ie=UTF8&linkCode=ur2&camp=3626&creative=24790' % aff_id
148- if detail_item:
149- aff_id['asin'] = detail_item
150- store_link = 'http://www.amazon.es/gp/redirect.html?ie=UTF8&location=http://www.amazon.es/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=3626&creative=24790' % aff_id
151- open_url(QUrl(store_link))
152-
153- def search(self, query, max_results=10, timeout=60):
154- search_url = 'http://www.amazon.es/s/?url=search-alias%3Ddigital-text&field-keywords='
155- url = search_url + query.encode('ascii', 'backslashreplace').replace('%', '%25').replace('\\x', '%').replace(' ', '+')
156- br = browser()
157-
158- counter = max_results
159- with closing(br.open(url, timeout=timeout)) as f:
160- # doc = html.fromstring(f.read().decode('latin-1', 'replace'))
161- # Apparently amazon Europe is responding in UTF-8 now
162- doc = html.fromstring(f.read())
163-
164- data_xpath = '//div[contains(@class, "result") and contains(@class, "product")]'
165- format_xpath = './/span[@class="format"]/text()'
166- cover_xpath = './/img[@class="productImage"]/@src'
167-
168- for data in doc.xpath(data_xpath):
169- if counter <= 0:
170- break
171-
172- # Even though we are searching digital-text only Amazon will still
173- # put in results for non Kindle books (author pages). So we need
174- # to explicitly check if the item is a Kindle book and ignore it
175- # if it isn't.
176- format = ''.join(data.xpath(format_xpath))
177- if 'kindle' not in format.lower():
178- continue
179-
180- # We must have an asin otherwise we can't easily reference the
181- # book later.
182- asin = ''.join(data.xpath("@name"))
183-
184- cover_url = ''.join(data.xpath(cover_xpath))
185-
186- title = ''.join(data.xpath('.//a[@class="title"]/text()'))
187- price = ''.join(data.xpath('.//div[@class="newPrice"]/span[contains(@class, "price")]/text()'))
188- author = unicode(''.join(data.xpath('.//h3[@class="title"]/span[@class="ptBrand"]/text()')))
189- if author.startswith('de '):
190- author = author[3:]
191-
192- counter -= 1
193-
194- s = SearchResult()
195- s.cover_url = cover_url.strip()
196- s.title = title.strip()
197- s.author = author.strip()
198- s.price = price.strip()
199- s.detail_item = asin.strip()
200- s.formats = 'Kindle'
201- s.drm = SearchResult.DRM_UNKNOWN
202-
203- yield s
204+ aff_id = {'tag': 'charhale09-21'}
205+ store_link = ('http://www.amazon.es/ebooks-kindle/b?_encoding=UTF8&'
206+ 'node=827231031&tag=%(tag)s&ie=UTF8&linkCode=ur2&camp=3626&creative=24790')
207+ store_link_details = ('http://www.amazon.es/gp/redirect.html?ie=UTF8&'
208+ 'location=http://www.amazon.es/dp/%(asin)s&tag=%(tag)s'
209+ '&linkCode=ur2&camp=3626&creative=24790')
210+ search_url = 'http://www.amazon.es/s/?url=search-alias%3Ddigital-text&field-keywords='
211\ No newline at end of file
212
213=== modified file 'src/calibre/gui2/store/stores/amazon_fr_plugin.py'
214--- src/calibre/gui2/store/stores/amazon_fr_plugin.py 2012-04-29 08:39:09 +0000
215+++ src/calibre/gui2/store/stores/amazon_fr_plugin.py 2012-11-06 23:56:30 +0000
216@@ -6,79 +6,16 @@
217 __copyright__ = '2011, John Schember <john@nachtimwald.com>'
218 __docformat__ = 'restructuredtext en'
219
220-from contextlib import closing
221-
222-from lxml import html
223-
224-from PyQt4.Qt import QUrl
225-
226-from calibre import browser
227-from calibre.gui2 import open_url
228-from calibre.gui2.store import StorePlugin
229-from calibre.gui2.store.search_result import SearchResult
230-
231-class AmazonFRKindleStore(StorePlugin):
232+
233+from calibre.gui2.store.stores.amazon_uk_plugin import AmazonUKKindleStore
234+
235+class AmazonFRKindleStore(AmazonUKKindleStore):
236 '''
237 For comments on the implementation, please see amazon_plugin.py
238 '''
239
240- def open(self, parent=None, detail_item=None, external=False):
241- aff_id = {'tag': 'charhale-21'}
242- store_link = 'http://www.amazon.fr/livres-kindle/b?ie=UTF8&node=695398031&ref_=sa_menu_kbo1&_encoding=UTF8&tag=%(tag)s&linkCode=ur2&camp=1642&creative=19458' % aff_id
243-
244- if detail_item:
245- aff_id['asin'] = detail_item
246- store_link = 'http://www.amazon.fr/gp/redirect.html?ie=UTF8&location=http://www.amazon.fr/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=1634&creative=6738' % aff_id
247- open_url(QUrl(store_link))
248-
249- def search(self, query, max_results=10, timeout=60):
250- search_url = 'http://www.amazon.fr/s/?url=search-alias%3Ddigital-text&field-keywords='
251- url = search_url + query.encode('ascii', 'backslashreplace').replace('%', '%25').replace('\\x', '%').replace(' ', '+')
252- br = browser()
253-
254- counter = max_results
255- with closing(br.open(url, timeout=timeout)) as f:
256- # doc = html.fromstring(f.read().decode('latin-1', 'replace'))
257- # Apparently amazon Europe is responding in UTF-8 now
258- doc = html.fromstring(f.read())
259-
260- data_xpath = '//div[contains(@class, "result") and contains(@class, "product")]'
261- format_xpath = './/span[@class="format"]/text()'
262- cover_xpath = './/img[@class="productImage"]/@src'
263-
264- for data in doc.xpath(data_xpath):
265- if counter <= 0:
266- break
267-
268- # Even though we are searching digital-text only Amazon will still
269- # put in results for non Kindle books (author pages). So we need
270- # to explicitly check if the item is a Kindle book and ignore it
271- # if it isn't.
272- format = ''.join(data.xpath(format_xpath))
273- if 'kindle' not in format.lower():
274- continue
275-
276- # We must have an asin otherwise we can't easily reference the
277- # book later.
278- asin = ''.join(data.xpath("@name"))
279-
280- cover_url = ''.join(data.xpath(cover_xpath))
281-
282- title = ''.join(data.xpath('.//a[@class="title"]/text()'))
283- price = ''.join(data.xpath('.//div[@class="newPrice"]/span[contains(@class, "price")]/text()'))
284- author = unicode(''.join(data.xpath('.//h3[@class="title"]/span[@class="ptBrand"]/text()')))
285- if author.startswith('de '):
286- author = author[3:]
287-
288- counter -= 1
289-
290- s = SearchResult()
291- s.cover_url = cover_url.strip()
292- s.title = title.strip()
293- s.author = author.strip()
294- s.price = price.strip()
295- s.detail_item = asin.strip()
296- s.formats = 'Kindle'
297- s.drm = SearchResult.DRM_UNKNOWN
298-
299- yield s
300+ aff_id = {'tag': 'charhale-21'}
301+ store_link = 'http://www.amazon.fr/livres-kindle/b?ie=UTF8&node=695398031&ref_=sa_menu_kbo1&_encoding=UTF8&tag=%(tag)s&linkCode=ur2&camp=1642&creative=19458' % aff_id
302+ store_link_details = 'http://www.amazon.fr/gp/redirect.html?ie=UTF8&location=http://www.amazon.fr/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=1634&creative=6738'
303+ search_url = 'http://www.amazon.fr/s/?url=search-alias%3Ddigital-text&field-keywords='
304+
305
306=== modified file 'src/calibre/gui2/store/stores/amazon_it_plugin.py'
307--- src/calibre/gui2/store/stores/amazon_it_plugin.py 2012-04-29 08:39:09 +0000
308+++ src/calibre/gui2/store/stores/amazon_it_plugin.py 2012-11-06 23:56:30 +0000
309@@ -6,78 +6,17 @@
310 __copyright__ = '2011, John Schember <john@nachtimwald.com>'
311 __docformat__ = 'restructuredtext en'
312
313-from contextlib import closing
314-
315-from lxml import html
316-
317-from PyQt4.Qt import QUrl
318-
319-from calibre import browser
320-from calibre.gui2 import open_url
321-from calibre.gui2.store import StorePlugin
322-from calibre.gui2.store.search_result import SearchResult
323-
324-class AmazonITKindleStore(StorePlugin):
325+from calibre.gui2.store.stores.amazon_uk_plugin import AmazonUKKindleStore
326+
327+class AmazonITKindleStore(AmazonUKKindleStore):
328 '''
329 For comments on the implementation, please see amazon_plugin.py
330 '''
331
332- def open(self, parent=None, detail_item=None, external=False):
333- aff_id = {'tag': 'httpcharles07-21'}
334- store_link = 'http://www.amazon.it/ebooks-kindle/b?_encoding=UTF8&node=827182031&tag=%(tag)s&ie=UTF8&linkCode=ur2&camp=3370&creative=23322' % aff_id
335- if detail_item:
336- aff_id['asin'] = detail_item
337- store_link = 'http://www.amazon.it/gp/redirect.html?ie=UTF8&location=http://www.amazon.it/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=3370&creative=23322' % aff_id
338- open_url(QUrl(store_link))
339-
340- def search(self, query, max_results=10, timeout=60):
341- search_url = 'http://www.amazon.it/s/?url=search-alias%3Ddigital-text&field-keywords='
342- url = search_url + query.encode('ascii', 'backslashreplace').replace('%', '%25').replace('\\x', '%').replace(' ', '+')
343- br = browser()
344-
345- counter = max_results
346- with closing(br.open(url, timeout=timeout)) as f:
347- # doc = html.fromstring(f.read().decode('latin-1', 'replace'))
348- # Apparently amazon Europe is responding in UTF-8 now
349- doc = html.fromstring(f.read())
350-
351- data_xpath = '//div[contains(@class, "result") and contains(@class, "product")]'
352- format_xpath = './/span[@class="format"]/text()'
353- cover_xpath = './/img[@class="productImage"]/@src'
354-
355- for data in doc.xpath(data_xpath):
356- if counter <= 0:
357- break
358-
359- # Even though we are searching digital-text only Amazon will still
360- # put in results for non Kindle books (author pages). So we need
361- # to explicitly check if the item is a Kindle book and ignore it
362- # if it isn't.
363- format = ''.join(data.xpath(format_xpath))
364- if 'kindle' not in format.lower():
365- continue
366-
367- # We must have an asin otherwise we can't easily reference the
368- # book later.
369- asin = ''.join(data.xpath("@name"))
370-
371- cover_url = ''.join(data.xpath(cover_xpath))
372-
373- title = ''.join(data.xpath('.//a[@class="title"]/text()'))
374- price = ''.join(data.xpath('.//div[@class="newPrice"]/span[contains(@class, "price")]/text()'))
375- author = unicode(''.join(data.xpath('.//h3[@class="title"]/span[@class="ptBrand"]/text()')))
376- if author.startswith('di '):
377- author = author[3:]
378-
379- counter -= 1
380-
381- s = SearchResult()
382- s.cover_url = cover_url.strip()
383- s.title = title.strip()
384- s.author = author.strip()
385- s.price = price.strip()
386- s.detail_item = asin.strip()
387- s.formats = 'Kindle'
388- s.drm = SearchResult.DRM_UNKNOWN
389-
390- yield s
391+ aff_id = {'tag': 'httpcharles07-21'}
392+ store_link = ('http://www.amazon.it/ebooks-kindle/b?_encoding=UTF8&'
393+ 'node=827182031&tag=%(tag)s&ie=UTF8&linkCode=ur2&camp=3370&creative=23322')
394+ store_link_details = ('http://www.amazon.it/gp/redirect.html?ie=UTF8&'
395+ 'location=http://www.amazon.it/dp/%(asin)s&tag=%(tag)s&'
396+ 'linkCode=ur2&camp=3370&creative=23322')
397+ search_url = 'http://www.amazon.it/s/?url=search-alias%3Ddigital-text&field-keywords='
398
399=== modified file 'src/calibre/gui2/store/stores/amazon_uk_plugin.py'
400--- src/calibre/gui2/store/stores/amazon_uk_plugin.py 2012-04-29 08:39:09 +0000
401+++ src/calibre/gui2/store/stores/amazon_uk_plugin.py 2012-11-06 23:56:30 +0000
402@@ -6,8 +6,9 @@
403 __copyright__ = '2011, John Schember <john@nachtimwald.com>'
404 __docformat__ = 'restructuredtext en'
405
406+import re
407+
408 from contextlib import closing
409-
410 from lxml import html
411
412 from PyQt4.Qt import QUrl
413@@ -18,57 +19,80 @@
414 from calibre.gui2.store.search_result import SearchResult
415
416 class AmazonUKKindleStore(StorePlugin):
417+ aff_id = {'tag': 'calcharles-21'}
418+ store_link = ('http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&'
419+ 'location=http://www.amazon.co.uk/Kindle-eBooks/b?'
420+ 'ie=UTF8&node=341689031&ref_=sa_menu_kbo2&tag=%(tag)s&'
421+ 'linkCode=ur2&camp=1634&creative=19450')
422+ store_link_details = ('http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&'
423+ 'location=http://www.amazon.co.uk/dp/%(asin)s&tag=%(tag)s&'
424+ 'linkCode=ur2&camp=1634&creative=6738')
425+ search_url = 'http://www.amazon.co.uk/s/?url=search-alias%3Ddigital-text&field-keywords='
426+
427 '''
428 For comments on the implementation, please see amazon_plugin.py
429 '''
430
431 def open(self, parent=None, detail_item=None, external=False):
432- aff_id = {'tag': 'calcharles-21'}
433- store_link = 'http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http://www.amazon.co.uk/Kindle-eBooks/b?ie=UTF8&node=341689031&ref_=sa_menu_kbo2&tag=%(tag)s&linkCode=ur2&camp=1634&creative=19450' % aff_id
434
435+ store_link = self.store_link % self.aff_id
436 if detail_item:
437- aff_id['asin'] = detail_item
438- store_link = 'http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http://www.amazon.co.uk/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=1634&creative=6738' % aff_id
439+ self.aff_id['asin'] = detail_item
440+ store_link = self.store_link_details % self.aff_id
441 open_url(QUrl(store_link))
442
443 def search(self, query, max_results=10, timeout=60):
444- search_url = 'http://www.amazon.co.uk/s/?url=search-alias%3Ddigital-text&field-keywords='
445- url = search_url + query.encode('ascii', 'backslashreplace').replace('%', '%25').replace('\\x', '%').replace(' ', '+')
446+ url = self.search_url + query.encode('ascii', 'backslashreplace').replace('%', '%25').replace('\\x', '%').replace(' ', '+')
447 br = browser()
448
449 counter = max_results
450 with closing(br.open(url, timeout=timeout)) as f:
451- # Apparently amazon Europe is responding in UTF-8 now
452- doc = html.fromstring(f.read())
453+ doc = html.fromstring(f.read())#.decode('latin-1', 'replace'))
454
455- data_xpath = '//div[contains(@class, "result") and contains(@class, "product")]'
456- format_xpath = './/span[@class="format"]/text()'
457+ data_xpath = '//div[contains(@class, "prod")]'
458+ format_xpath = './/ul[contains(@class, "rsltL")]//span[contains(@class, "lrg") and not(contains(@class, "bld"))]/text()'
459+ asin_xpath = './/div[@class="image"]/a[1]'
460 cover_xpath = './/img[@class="productImage"]/@src'
461+ title_xpath = './/h3[@class="newaps"]/a//text()'
462+ author_xpath = './/h3[@class="newaps"]//span[contains(@class, "reg")]/text()'
463+ price_xpath = './/ul[contains(@class, "rsltL")]//span[contains(@class, "lrg") and contains(@class, "bld")]/text()'
464
465 for data in doc.xpath(data_xpath):
466 if counter <= 0:
467 break
468
469 # Even though we are searching digital-text only Amazon will still
470- # put in results for non Kindle books (author pages). So we need
471+ # put in results for non Kindle books (author pages). Se we need
472 # to explicitly check if the item is a Kindle book and ignore it
473 # if it isn't.
474- format = ''.join(data.xpath(format_xpath))
475- if 'kindle' not in format.lower():
476+ format_ = ''.join(data.xpath(format_xpath))
477+ if 'kindle' not in format_.lower():
478 continue
479
480 # We must have an asin otherwise we can't easily reference the
481 # book later.
482- asin = ''.join(data.xpath("@name"))
483+ asin_href = None
484+ asin_a = data.xpath(asin_xpath)
485+ if asin_a:
486+ asin_href = asin_a[0].get('href', '')
487+ m = re.search(r'/dp/(?P<asin>.+?)(/|$)', asin_href)
488+ if m:
489+ asin = m.group('asin')
490+ else:
491+ continue
492+ else:
493+ continue
494
495 cover_url = ''.join(data.xpath(cover_xpath))
496
497- title = ''.join(data.xpath('.//a[@class="title"]/text()'))
498- price = ''.join(data.xpath('.//div[@class="newPrice"]/span[contains(@class, "price")]/text()'))
499+ title = ''.join(data.xpath(title_xpath))
500+ author = ''.join(data.xpath(author_xpath))
501+ try:
502+ author = author.split('by ', 1)[1].split(" (")[0]
503+ except:
504+ pass
505
506- author = ''.join(data.xpath('.//h3[@class="title"]/span[@class="ptBrand"]/text()'))
507- if author.startswith('by '):
508- author = author[3:]
509+ price = ''.join(data.xpath(price_xpath))
510
511 counter -= 1
512
513@@ -78,37 +102,10 @@
514 s.author = author.strip()
515 s.price = price.strip()
516 s.detail_item = asin.strip()
517+ s.drm = SearchResult.DRM_UNKNOWN
518 s.formats = 'Kindle'
519
520 yield s
521
522 def get_details(self, search_result, timeout):
523- # We might already have been called.
524- if search_result.drm:
525- return
526-
527- url = 'http://amazon.co.uk/dp/'
528- drm_search_text = u'Simultaneous Device Usage'
529- drm_free_text = u'Unlimited'
530-
531- br = browser()
532- with closing(br.open(url + search_result.detail_item, timeout=timeout)) as nf:
533- idata = html.fromstring(nf.read())
534- if not search_result.author:
535- search_result.author = ''.join(idata.xpath('//div[@class="buying" and contains(., "Author")]/a/text()'))
536- is_kindle = idata.xpath('boolean(//div[@class="buying"]/h1/span/span[contains(text(), "Kindle Edition")])')
537- if is_kindle:
538- search_result.formats = 'Kindle'
539- if idata.xpath('boolean(//div[@class="content"]//li/b[contains(text(), "' +
540- drm_search_text + '")])'):
541- if idata.xpath('boolean(//div[@class="content"]//li[contains(., "' +
542- drm_free_text + '") and contains(b, "' +
543- drm_search_text + '")])'):
544- search_result.drm = SearchResult.DRM_UNLOCKED
545- else:
546- search_result.drm = SearchResult.DRM_UNKNOWN
547- else:
548- search_result.drm = SearchResult.DRM_LOCKED
549- return True
550-
551-
552+ pass
553
554=== modified file 'src/calibre/gui2/store/stores/libri_de_plugin.py'
555--- src/calibre/gui2/store/stores/libri_de_plugin.py 2012-04-29 08:39:09 +0000
556+++ src/calibre/gui2/store/stores/libri_de_plugin.py 2012-11-06 23:56:30 +0000
557@@ -25,7 +25,7 @@
558 def open(self, parent=None, detail_item=None, external=False):
559 url = 'http://ad.zanox.com/ppc/?18817073C15644254T'
560 url_details = ('http://ad.zanox.com/ppc/?18817073C15644254T&ULP=[['
561- 'http://www.libri.de/shop/action/productDetails?artiId={0}]]')
562+ 'http://www.ebook.de/shop/action/productDetails?artiId={0}]]')
563
564 if external or self.config.get('open_external', False):
565 if detail_item:
566@@ -41,33 +41,38 @@
567 d.exec_()
568
569 def search(self, query, max_results=10, timeout=60):
570- url = ('http://www.libri.de/shop/action/quickSearch?facetNodeId=6'
571- '&mainsearchSubmit=Los!&searchString=' + urllib2.quote(query))
572+ url = ('http://www.ebook.de/de/pathSearch?nav=52122&searchString='
573+ + urllib2.quote(query))
574 br = browser()
575
576 counter = max_results
577 with closing(br.open(url, timeout=timeout)) as f:
578 doc = html.fromstring(f.read())
579- for data in doc.xpath('//div[contains(@class, "item")]'):
580+ for data in doc.xpath('//div[contains(@class, "articlecontainer")]'):
581 if counter <= 0:
582 break
583
584- details = data.xpath('./div[@class="beschreibungContainer"]')
585+ details = data.xpath('./div[@class="articleinfobox"]')
586 if not details:
587 continue
588 details = details[0]
589- id = ''.join(details.xpath('./div[@class="text"]/a/@name')).strip()
590- if not id:
591+ id_ = ''.join(details.xpath('./a/@name')).strip()
592+ if not id_:
593 continue
594- cover_url = ''.join(details.xpath('.//div[@class="coverImg"]/a/img/@src'))
595- title = ''.join(details.xpath('./div[@class="text"]/span[@class="titel"]/a/text()')).strip()
596- author = ''.join(details.xpath('./div[@class="text"]/span[@class="author"]/text()')).strip()
597+ title = ''.join(details.xpath('.//a[@class="su1_c_l_titel"]/text()')).strip()
598+
599+ author = ''.join(details.xpath('.//div[@class="author"]/text()')).strip()
600+ if author.startswith('von'):
601+ author = author[4:]
602+
603 pdf = details.xpath(
604- 'boolean(.//span[@class="format" and contains(text(), "pdf")]/text())')
605+ 'boolean(.//span[@class="bindername" and contains(text(), "pdf")]/text())')
606 epub = details.xpath(
607- 'boolean(.//span[@class="format" and contains(text(), "epub")]/text())')
608+ 'boolean(.//span[@class="bindername" and contains(text(), "epub")]/text())')
609 mobi = details.xpath(
610- 'boolean(.//span[@class="format" and contains(text(), "mobipocket")]/text())')
611+ 'boolean(.//span[@class="bindername" and contains(text(), "mobipocket")]/text())')
612+
613+ cover_url = ''.join(data.xpath('.//div[@class="coverImg"]/a/img/@src'))
614 price = ''.join(data.xpath('.//span[@class="preis"]/text()')).replace('*', '').strip()
615
616 counter -= 1
617@@ -78,7 +83,7 @@
618 s.author = author.strip()
619 s.price = price
620 s.drm = SearchResult.DRM_UNKNOWN
621- s.detail_item = id
622+ s.detail_item = id_
623 formats = []
624 if epub:
625 formats.append('ePub')

Subscribers

People subscribed via source and target branches

to status/vote changes: