Skip to content

Instantly share code, notes, and snippets.

@zopieux
Created August 25, 2014 16:14
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 zopieux/e7f88ddf587301563d6f to your computer and use it in GitHub Desktop.
Save zopieux/e7f88ddf587301563d6f to your computer and use it in GitHub Desktop.
Find KO chapters in SRT for ~phennequin
#!/usr/bin/env python
# Usage: python srtko.py <input.srt> <output.txt>
from __future__ import print_function
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
def grouper(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)
import sys
with open(sys.argv[1], 'r') as f:
data = f.read().strip().split('\n')
i = 1
with open(sys.argv[2], 'w') as f:
for n, time, name, cont, ok, _ in grouper(data, 6, ''):
if ok.strip() != "KO":
continue
print("CHAPTER%02d=%s" % (i, time.strip().split()[0].replace(',', '.')), file=f)
print("CHAPTER%02dNAME=%s" % (i, name.strip()), file=f)
i += 1
print("Generated %d KO chapters" % (i - 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment