#!/usr/bin/env python """ Convert TTML subtitles to SubRip format Creates .srt file with same base path as TTML file usage: ttml2srt.py [-h] [--srt-ignore-colors] [--stdout] ttml_file [ttml_file ...] positional arguments: ttml_file optional arguments: -h, --help show this help message and exit --srt-ignore-colors ignore subtitle text colors --stdout print to stdout instead of creating .srt file """ from HTMLParser import HTMLParser from htmlentitydefs import name2codepoint from datetime import datetime import argparse, codecs, os, re, sys class TTML2SRTParser(HTMLParser): """ Parse TTML subtitles to SubRip format Usage: parser = TTML2SRTParser() captions = parser.parse_file(ttml_fp, srt_ignore_colors) ttml_fp = TTML file object opened by codecs.open() srt_ignore_colors = if true, ignore subtitle text colors TTML format example (from ITV Player):