~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/metadata/html.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from calibre.ebooks.metadata import MetaInformation
13
13
from calibre.ebooks.chardet import xml_to_unicode
14
14
 
 
15
 
15
16
def get_metadata(stream):
16
 
    src = xml_to_unicode(stream.read())[0]
17
 
    
 
17
    src = stream.read()
 
18
    return get_metadata_(src)
 
19
 
 
20
def get_metadata_(src, encoding=None):
 
21
    if not isinstance(src, unicode):
 
22
        if not encoding:
 
23
            src = xml_to_unicode(src)[0]
 
24
        else:
 
25
            src = src.decode(encoding, 'replace')
 
26
 
18
27
    # Title
19
28
    title = None
20
29
    pat = re.compile(r'<!--.*?TITLE=(?P<q>[\'"])(.+?)(?P=q).*?-->', re.DOTALL)
26
35
        match = pat.search(src)
27
36
        if match:
28
37
            title = match.group(1)
29
 
        
 
38
 
30
39
    # Author
31
40
    author = None
32
41
    pat = re.compile(r'<!--.*?AUTHOR=(?P<q>[\'"])(.+?)(?P=q).*?-->', re.DOTALL)
33
42
    match = pat.search(src)
34
43
    if match:
35
44
        author = match.group(2).replace(',', ';')
36
 
        
 
45
 
37
46
    mi = MetaInformation(title, [author] if author else None)
38
 
    
 
47
 
39
48
    # Publisher
40
49
    pat = re.compile(r'<!--.*?PUBLISHER=(?P<q>[\'"])(.+?)(?P=q).*?-->', re.DOTALL)
41
50
    match = pat.search(src)
42
51
    if match:
43
52
        mi.publisher = match.group(2)
44
 
        
 
53
 
45
54
    # ISBN
46
55
    pat = re.compile(r'<!--.*?ISBN=[\'"]([^"\']+)[\'"].*?-->', re.DOTALL)
47
56
    match = pat.search(src)
48
57
    if match:
49
58
        isbn = match.group(1)
50
59
        mi.isbn = re.sub(r'[^0-9xX]', '', isbn)
51
 
        
 
60
 
52
61
    return mi
53
 
    
54
 
    
 
 
b'\\ No newline at end of file'
 
62
 
 
63