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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Ashish Kulkarni <kulkarni.ashish@gmail.com>'
  6. import sys
  7. import struct
  8. from calibre.ebooks.metadata import MetaInformation, string_to_authors
  9. MAGIC = '\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00'
  10.  
  11. def get_metadata(stream):
  12.     title = 'Unknown'
  13.     mi = MetaInformation(title, [
  14.         'Unknown'])
  15.     stream.seek(0)
  16.     
  17.     try:
  18.         if not stream.read(14) == MAGIC:
  19.             print >>sys.stderr, u"Couldn't read RB header from file"
  20.             return mi
  21.         stream.read(10)
  22.         
  23.         read_i32 = lambda : struct.unpack('<I', stream.read(4))[0]
  24.         stream.seek(read_i32())
  25.         toc_count = read_i32()
  26.         for i in range(toc_count):
  27.             stream.read(32)
  28.             length = read_i32()
  29.             offset = read_i32()
  30.             flag = read_i32()
  31.             if flag == 2:
  32.                 break
  33.                 continue
  34.             (stream.read(14) == MAGIC,)
  35.         else:
  36.             print >>sys.stderr, u"Couldn't find INFO from RB file"
  37.             return mi
  38.         None.seek(offset)
  39.         info = stream.read(length).splitlines()
  40.         for line in info:
  41.             if '=' not in line:
  42.                 continue
  43.             
  44.             (key, value) = line.split('=')
  45.             if key.strip() == 'TITLE':
  46.                 mi.title = value.strip()
  47.                 continue
  48.             if key.strip() == 'AUTHOR':
  49.                 mi.author = value
  50.                 mi.authors = string_to_authors(value)
  51.                 continue
  52.     except Exception:
  53.         err = None
  54.         msg = u"Couldn't read metadata from rb: %s with error %s" % (mi.title, unicode(err))
  55.         print >>sys.stderr, msg.encode('utf8')
  56.         raise 
  57.  
  58.     return mi
  59.  
  60.