Skip to content

Instantly share code, notes, and snippets.

@hannsen
Created March 22, 2023 12:35
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 hannsen/10e4f13b3d5371aa0bec09a96803918f to your computer and use it in GitHub Desktop.
Save hannsen/10e4f13b3d5371aa0bec09a96803918f to your computer and use it in GitHub Desktop.
ZDF Mediathek Subtitle XML to SRT converter
import xml.etree.ElementTree as ET
# Parse the XML file
tree = ET.parse('in.xml')
root = tree.getroot()
f = open("out.srt", "a")
# Find and print every tt:p tag
i = 0
for p in root.findall('.//{http://www.w3.org/ns/ttml}p'):
i += 1
texts = ''
for elem in p.iter():
texts += (elem.text + ' ') if elem.text else ''
f.write(str(i) + "\n")
f.write(p.attrib['begin'] + " --> " + p.attrib['end'] + "\n")
f.write(texts + "\n\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment