Created
March 22, 2023 12:35
-
-
Save hannsen/10e4f13b3d5371aa0bec09a96803918f to your computer and use it in GitHub Desktop.
ZDF Mediathek Subtitle XML to SRT converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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