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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from warnings import warnpy3k
  5. warnpy3k('the toaiff module has been removed in Python 3.0', stacklevel = 2)
  6. del warnpy3k
  7. import os
  8. import tempfile
  9. import pipes
  10. import sndhdr
  11. __all__ = [
  12.     'error',
  13.     'toaiff']
  14. table = { }
  15. t = pipes.Template()
  16. t.append('sox -t au - -t aiff -r 8000 -', '--')
  17. table['au'] = t
  18. t = pipes.Template()
  19. t.append('sox -t hcom - -t aiff -r 22050 -', '--')
  20. table['hcom'] = t
  21. t = pipes.Template()
  22. t.append('sox -t voc - -t aiff -r 11025 -', '--')
  23. table['voc'] = t
  24. t = pipes.Template()
  25. t.append('sox -t wav - -t aiff -', '--')
  26. table['wav'] = t
  27. t = pipes.Template()
  28. t.append('sox -t 8svx - -t aiff -r 16000 -', '--')
  29. table['8svx'] = t
  30. t = pipes.Template()
  31. t.append('sox -t sndt - -t aiff -r 16000 -', '--')
  32. table['sndt'] = t
  33. t = pipes.Template()
  34. t.append('sox -t sndr - -t aiff -r 16000 -', '--')
  35. table['sndr'] = t
  36. uncompress = pipes.Template()
  37. uncompress.append('uncompress', '--')
  38.  
  39. class error(Exception):
  40.     pass
  41.  
  42.  
  43. def toaiff(filename):
  44.     temps = []
  45.     ret = None
  46.     
  47.     try:
  48.         ret = _toaiff(filename, temps)
  49.     finally:
  50.         for temp in temps[:]:
  51.             if temp != ret:
  52.                 
  53.                 try:
  54.                     os.unlink(temp)
  55.                 except os.error:
  56.                     pass
  57.  
  58.                 temps.remove(temp)
  59.                 continue
  60.         
  61.  
  62.     return ret
  63.  
  64.  
  65. def _toaiff(filename, temps):
  66.     if filename[-2:] == '.Z':
  67.         (fd, fname) = tempfile.mkstemp()
  68.         os.close(fd)
  69.         temps.append(fname)
  70.         sts = uncompress.copy(filename, fname)
  71.         if sts:
  72.             raise error, filename + ': uncompress failed'
  73.         sts
  74.     else:
  75.         fname = filename
  76.     
  77.     try:
  78.         ftype = sndhdr.whathdr(fname)
  79.         if ftype:
  80.             ftype = ftype[0]
  81.     except IOError:
  82.         msg = None
  83.         if type(msg) == type(()) and len(msg) == 2 and type(msg[0]) == type(0) and type(msg[1]) == type(''):
  84.             msg = msg[1]
  85.         
  86.         if type(msg) != type(''):
  87.             msg = repr(msg)
  88.         
  89.         raise error, filename + ': ' + msg
  90.  
  91.     if ftype == 'aiff':
  92.         return fname
  93.     if ftype is None or ftype not in table:
  94.         raise error, '%s: unsupported audio file type %r' % (filename, ftype)
  95.     ftype not in table
  96.     (fd, temp) = tempfile.mkstemp()
  97.     os.close(fd)
  98.     temps.append(temp)
  99.     sts = table[ftype].copy(fname, temp)
  100.     if sts:
  101.         raise error, filename + ': conversion to aiff failed'
  102.     sts
  103.     return temp
  104.  
  105.