YourPaste - For your paste! Archive - Tools - Login

subtitle converter

Posted by ass2srt.py on Sat 21 Jun 2008 23:07 2503 views - Syntax: Python - Expires: never - Report - IMG - Download -

  1. #/usr/bin/env python
  2. # -*- encoding:cp1251 -*-
  3. import re
  4. import glob
  5.  
  6. for fname_ass in glob.glob('*.ass'):
  7.         fname_srt = re.compile('\.ass$').sub('.srt', fname_ass)
  8.        
  9.         fi = open(fname_ass)
  10.         fo = open(fname_srt,'w')
  11.  
  12.         start = False
  13.         num = 1;
  14.  
  15.         for line in fi:
  16.                 if start:
  17.                         if line[:10] == 'Dialogue: ':
  18.                                 line = line[10:]
  19.                                 elems = line.split(',')
  20.                                 linetext = ",".join(elems[9:])
  21.                                 linetext = unicode( linetext, "utf-8" )
  22.                                 linetext = linetext.replace('\\N','\n');
  23.  
  24.                                 def timesrt(stamp):
  25.                                         return "0%s0".replace('.', ',') % (stamp)
  26.  
  27.                                 fo.write( "%d\n%s --> %s\n%s\n" % (num,timesrt(elems[1]),timesrt(elems[2]),linetext.encode('cp1251') ) )
  28.                                 num += 1
  29.  
  30.                 if re.compile('Format\: Layer, Start, End').match(line):
  31.                         start = True;
  32.  
  33.         fi.close()
  34.         fo.close()
  35.  

Comments


Name:
Comment:

© 2010 YourPaste.net - Disclaimer