Skip to content

Instantly share code, notes, and snippets.

@coronin
Last active June 24, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coronin/06a56f71c4734a92fd90132a8a6deff1 to your computer and use it in GitHub Desktop.
Save coronin/06a56f71c4734a92fd90132a8a6deff1 to your computer and use it in GitHub Desktop.
I used the following to generate **Three.Seconds.zh-en.srt**
## Liang Cai, 2019-6-22
import time
import translation
def translate_line(a):
time.sleep(1)
try:
b = translation.iciba(a, dst = 'zh') # @@@@
if b.startswith('.'):
print b[1:], a
else:
print b, a
except:
print a
f = open('Three.Seconds.eng.srt', 'r')
c0 = 5001 # @@@@
lines = f.readlines()
f.close()
newLines = []
c = 0
print '\n\n\n\n'
for l in lines:
line = l.strip()
c += 1
if c < c0:
continue
if line and (line[0].isalpha() or line.startswith('...')):
translate_line(line)
elif line and line.startswith('- '):
print '-',
translate_line( line[2:] )
else:
print line
if not c % 5000:
raise Exception, 'Please copy screen output to the srt file %d~%d' % (c0, c)
print ';; Done by Liang %d' % int(time.time())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment