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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2009, Kovid Goyal kovid@kovidgoyal.net'
  6. __docformat__ = 'restructuredtext en'
  7. import os
  8. from calibre.ptempfile import PersistentTemporaryFile, TemporaryDirectory
  9. from calibre.libunrar import extract_member, names
  10. from calibre import CurrentDir
  11.  
  12. def get_metadata(stream):
  13.     is_comic = is_comic
  14.     import calibre.ebooks.metadata.archive
  15.     get_metadata = get_metadata
  16.     import calibre.ebooks.metadata.meta
  17.     path = getattr(stream, 'name', False)
  18.     if not path:
  19.         pt = PersistentTemporaryFile('_rar-meta.rar')
  20.         pt.write(stream.read())
  21.         pt.close()
  22.         path = pt.name
  23.     
  24.     path = os.path.abspath(path)
  25.     file_names = list(names(path))
  26.     if is_comic(file_names):
  27.         return get_metadata(stream, 'cbr')
  28.     for f in file_names:
  29.         stream_type = os.path.splitext(f)[1].lower()
  30.         if stream_type:
  31.             stream_type = stream_type[1:]
  32.             if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub', 'rb', 'imp', 'pdf', 'lrf', 'azw'):
  33.                 
  34.                 try:
  35.                     tdir = _[1]
  36.                     CurrentDir(tdir).__enter__()
  37.                     
  38.                     try:
  39.                         stream = extract_member(path, match = None, name = f, as_file = True)[1]
  40.                     finally:
  41.                         pass
  42.  
  43.                 finally:
  44.                     pass
  45.  
  46.                 return get_metadata(stream, stream_type)
  47.             continue
  48.         stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub', 'rb', 'imp', 'pdf', 'lrf', 'azw')
  49.     
  50.     raise ValueError('No ebook found in RAR archive')
  51.  
  52.