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

« back to all changes in this revision

Viewing changes to src/calibre/gui2/store/opensearch_store.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-10-03 23:18:14 UTC
  • mfrom: (1.3.36)
  • Revision ID: package-import@ubuntu.com-20121003231814-i67zl632zxlj4qn1
Tags: 0.9.0+dfsg-1
* New upstream release.
* debian/control, debian/rules: ttf-liberation is no more, move to
  fonts-liberation. Thanks to Kan-Ru Chen! (Closes: #674838)
* debian/calibre.install: Drop pyPdf, not shipped upstream any more.
* debian/control: Add new python-netifaces dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
7
7
__docformat__ = 'restructuredtext en'
8
8
 
9
 
import mimetypes
10
9
from contextlib import closing
11
10
 
12
11
from lxml import etree
13
12
 
14
13
from PyQt4.Qt import QUrl
15
14
 
16
 
from calibre import browser
 
15
from calibre import (browser, guess_extension)
17
16
from calibre.gui2 import open_url
18
17
from calibre.gui2.store import StorePlugin
19
18
from calibre.gui2.store.search_result import SearchResult
29
28
    def open(self, parent=None, detail_item=None, external=False):
30
29
        if not hasattr(self, 'web_url'):
31
30
            return
32
 
        
 
31
 
33
32
        if external or self.config.get('open_external', False):
34
33
            open_url(QUrl(detail_item if detail_item else self.web_url))
35
34
        else:
52
51
        oquery.searchTerms = query
53
52
        oquery.count = max_results
54
53
        url = oquery.url()
55
 
        
 
54
 
56
55
        counter = max_results
57
56
        br = browser()
58
57
        with closing(br.open(url, timeout=timeout)) as f:
60
59
            for data in doc.xpath('//*[local-name() = "entry"]'):
61
60
                if counter <= 0:
62
61
                    break
63
 
            
 
62
 
64
63
                counter -= 1
65
 
    
 
64
 
66
65
                s = SearchResult()
67
 
                
 
66
 
68
67
                s.detail_item = ''.join(data.xpath('./*[local-name() = "id"]/text()')).strip()
69
68
 
70
69
                for link in data.xpath('./*[local-name() = "link"]'):
71
70
                    rel = link.get('rel')
72
71
                    href = link.get('href')
73
72
                    type = link.get('type')
74
 
                    
 
73
 
75
74
                    if rel and href and type:
76
75
                        if 'http://opds-spec.org/thumbnail' in rel:
77
76
                            s.cover_url = href
81
80
                            s.detail_item = href
82
81
                        elif 'http://opds-spec.org/acquisition' in rel:
83
82
                            if type:
84
 
                                ext = mimetypes.guess_extension(type)
 
83
                                ext = guess_extension(type)
85
84
                                if ext:
86
85
                                    ext = ext[1:].upper().strip()
87
86
                                    s.downloads[ext] = href
88
87
                s.formats = ', '.join(s.downloads.keys()).strip()
89
 
                
 
88
 
90
89
                s.title = ' '.join(data.xpath('./*[local-name() = "title"]//text()')).strip()
91
90
                s.author = ', '.join(data.xpath('./*[local-name() = "author"]//*[local-name() = "name"]//text()')).strip()
92
 
                
 
91
 
93
92
                price_e = data.xpath('.//*[local-name() = "price"][1]')
94
93
                if price_e:
95
94
                    price_e = price_e[0]
97
96
                    price = ''.join(price_e.xpath('.//text()')).strip()
98
97
                    s.price = currency_code + ' ' + price
99
98
                    s.price = s.price.strip()
100
 
                
 
99
 
101
100
 
102
101
                yield s