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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  7. import os
  8. from calibre.utils.zipfile import ZipFile
  9. from calibre.ptempfile import TemporaryDirectory
  10. from calibre import CurrentDir
  11.  
  12. def get_metadata(stream):
  13.     get_metadata = get_metadata
  14.     import calibre.ebooks.metadata.meta
  15.     is_comic = is_comic
  16.     import calibre.ebooks.metadata.archive
  17.     stream_type = None
  18.     zf = ZipFile(stream, 'r')
  19.     names = zf.namelist()
  20.     if is_comic(names):
  21.         return get_metadata(stream, 'cbz')
  22.     for f in names:
  23.         stream_type = os.path.splitext(f)[1].lower()
  24.         if stream_type:
  25.             stream_type = stream_type[1:]
  26.             if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub', 'rb', 'imp', 'pdf', 'lrf', 'azw'):
  27.                 
  28.                 try:
  29.                     tdir = _[1]
  30.                     CurrentDir(tdir).__enter__()
  31.                     
  32.                     try:
  33.                         path = zf.extract(f)
  34.                         return get_metadata(open(path, 'rb'), stream_type)
  35.                     finally:
  36.                         pass
  37.  
  38.                 finally:
  39.                     pass
  40.  
  41.             
  42.         stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub', 'rb', 'imp', 'pdf', 'lrf', 'azw')
  43.     
  44.     raise ValueError('No ebook found in ZIP archive')
  45.  
  46.