Skip to content

Instantly share code, notes, and snippets.

@geekman
Created October 9, 2021 10:23
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 geekman/6e6380aa76ee6de7f58c908845265c55 to your computer and use it in GitHub Desktop.
Save geekman/6e6380aa76ee6de7f58c908845265c55 to your computer and use it in GitHub Desktop.
strip out SRT metadata, leaving only subtitle text
#
# strip out SRT timing information, leaving only the text
# separated by a single line
#
# 2021.10.09 darell tan
#
import sys
with open(sys.argv[1], 'r') as f:
collected = []
for l in f:
l = l.strip()
if l == '':
if collected: print # seperator
del collected[:]
continue
if len(collected) >= 2:
print l
else:
# collect number & timespan here
collected.append(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment