Skip to content

Instantly share code, notes, and snippets.

@cuihaoleo

cuihaoleo/a.py

Created Oct 12, 2014
Embed
What would you like to do?
#!/usr/bin/env python3
import re
import sys
prog = re.compile(r"\\N(?:{[^{}]*})?")
prog2 = re.compile(r"(Dialogue: \w*,\w*:\w*:\w*.\w*,\w*:\w*:\w*.\w*,\w*,\w*,\w*,\w*,\w*,\w*,)(.*)")
for line in sys.stdin:
if line.startswith("Dialogue"):
mt = prog2.match(line)
if mt and len(mt.groups()) == 2:
a, b = mt.groups()
sp = prog.split(b)
if len(sp) == 2:
print((a+sp[0]).strip(), file=sys.stderr)
print((a+sp[1]).strip(), file=sys.stdout)
continue
print(line.strip(), file=sys.stderr)
if not re.findall(r'[\u4e00-\u9fff]+', line):
print(line.strip(), file=sys.stdout)
#!/bin/bash
set -e
for f in ./*.ass; do
cat "$f" | python3 a.py > "english/$f" 2> "chinese/$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment