~ubuntu-branches/debian/experimental/calibre/experimental

« back to all changes in this revision

Viewing changes to src/calibre/gui2/store/stores/legimi_plugin.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-02-12 16:45:34 UTC
  • mfrom: (1.3.38)
  • Revision ID: package-import@ubuntu.com-20130212164534-4tue9c37ui3lgdsl
Tags: 0.9.18+dfsg-1
* New upstream release. (Closes: #699700)
* Unfuzz patches.
* Add new libqt4-private-dev build dependency, required by this version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
 
3
3
from __future__ import (unicode_literals, division, absolute_import, print_function)
 
4
store_version = 1 # Needed for dynamic plugin loading
4
5
 
5
6
__license__ = 'GPL 3'
6
7
__copyright__ = '2011, Tomasz Długosz <tomek3d@gmail.com>'
24
25
class LegimiStore(BasicStoreConfig, StorePlugin):
25
26
 
26
27
    def open(self, parent=None, detail_item=None, external=False):
27
 
        
 
28
 
28
29
        plain_url = 'http://www.legimi.com/pl/ebooki/'
29
30
        url = 'https://ssl.afiliant.com/affskrypt,,2f9de2,,11483,,,?u=(' + plain_url + ')'
30
31
        detail_url = None
42
43
 
43
44
    def search(self, query, max_results=10, timeout=60):
44
45
        url = 'http://www.legimi.com/pl/ebooki/?szukaj=' + urllib.quote_plus(query)
45
 
        
 
46
 
46
47
        br = browser()
47
48
        drm_pattern = re.compile("zabezpieczona DRM")
48
 
        
 
49
 
49
50
        counter = max_results
50
51
        with closing(br.open(url, timeout=timeout)) as f:
51
52
            doc = html.fromstring(f.read())
52
53
            for data in doc.xpath('//div[@id="listBooks"]/div'):
53
54
                if counter <= 0:
54
55
                    break
55
 
                
 
56
 
56
57
                id = ''.join(data.xpath('.//a[@class="plainLink"]/@href'))
57
58
                if not id:
58
59
                    continue
73
74
                    drm = drm_pattern.search(''.join(idata.xpath('.//div[@id="fullBookFormats"]/p/text()')))
74
75
 
75
76
                counter -= 1
76
 
                
 
77
 
77
78
                s = SearchResult()
78
79
                s.cover_url = 'http://www.legimi.com/' + cover_url
79
80
                s.title = title.strip()
82
83
                s.detail_item = 'http://www.legimi.com/' + id.strip()
83
84
                s.formats = ', '.join(formats)
84
85
                s.drm = SearchResult.DRM_LOCKED if drm else SearchResult.DRM_UNLOCKED
85
 
                
 
86
 
86
87
                yield s