home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_962 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.8 KB  |  53 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. import cStringIO
  7. import os
  8. from calibre.ebooks.metadata import MetaInformation
  9. from calibre.ebooks.metadata.opf2 import OPF
  10.  
  11. def get_metadata(stream):
  12.     LitContainer = LitContainer
  13.     import calibre.ebooks.lit.reader
  14.     Log = Log
  15.     import calibre.utils.logging
  16.     litfile = LitContainer(stream, Log())
  17.     src = litfile.get_metadata().encode('utf-8')
  18.     litfile = litfile._litfile
  19.     opf = OPF(cStringIO.StringIO(src), os.getcwd())
  20.     mi = MetaInformation(opf)
  21.     covers = []
  22.     for item in opf.iterguide():
  23.         if 'cover' not in item.get('type', '').lower():
  24.             continue
  25.         
  26.         ctype = item.get('type')
  27.         href = item.get('href', '')
  28.         candidates = [
  29.             href,
  30.             href.replace('&', '%26')]
  31.         for item in litfile.manifest.values():
  32.             if item.path in candidates:
  33.                 
  34.                 try:
  35.                     covers.append((litfile.get_file('/data/' + item.internal), ctype))
  36.                 except:
  37.                     pass
  38.  
  39.                 break
  40.                 continue
  41.         
  42.     
  43.     covers.sort(cmp = (lambda x, y: cmp(len(x[0]), len(y[0]))), reverse = True)
  44.     idx = 0
  45.     if len(covers) > 1:
  46.         if covers[1][1] == covers[0][1] + '-standard':
  47.             idx = 1
  48.         
  49.     
  50.     mi.cover_data = ('jpg', covers[idx][0])
  51.     return mi
  52.  
  53.