Skip to content

Instantly share code, notes, and snippets.

@mgaitan
Last active April 23, 2020 18:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mgaitan/31942c5fc77dad468313bed7d0ce5eb1 to your computer and use it in GitHub Desktop.
Save mgaitan/31942c5fc77dad468313bed7d0ce5eb1 to your computer and use it in GitHub Desktop.
Convert subtitles to plain text
#!/usr/bin/env python
import sys
import re
import textwrap
def str2txt(srt):
lines = re.sub(r'^$\n|^[0-9].*\n|^\n','', srt, flags=re.MULTILINE | re.UNICODE)
print(textwrap.fill(lines, 70))
if __name__ == '__main__':
str2txt(open(sys.argv[0]).read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment