Here is a shortened example of the TTML file, which looks to me just like a specially formatted XML file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:nttm="http://www.netflix.com/ns/ttml#metadata" xmlns:ttp="http://www.w3.org/ns/ttml#parameter" xmlns:tts="http://www.w3.org/ns/ttml#styling" ttp:timeBase="media" ttp:version="2" tts:extent="1280px 720px" xml:lang="zh-Hans">
<head>
<metadata nttm:movieId="81170257" nttm:packageId="1618461" nttm:schemaVersion="0" nttm:textType="SUBS" nttm:uuid="9c50201b-f11e-4665-9944-3bda07268f29"/>
</head>
<body>
<div begin="00:00:06.833" end="00:00:09.958" tts:extent="479px 51px" tts:origin="407px 597px">
<image src="1.png"/>
</div>
<div begin="00:00:26.083" end="00:00:29.250" tts:extent="431px 46px" tts:origin="431px 602px">
<image src="2.png"/>
</div>
<div begin="00:14:27.125" end="00:14:27.958" tts:extent="161px 46px" tts:origin="566px 602px">
<image src="165.png"/>
</div>
</body>
</tt>
Here is the code that I am running:
import lxml.etree as ET
tree = ET.parse("sample_ttml2.xml")
root = tree.getroot()
print(root.tag)
for div in root.iterfind(".//div"):
print(div)
for div in root.iterfind("div"):
print(div)
This outputs:
{http://www.w3.org/ns/ttml}tt
What I was expecting was the tt tag, without this namespace thing. When I attempt to iterate through, I get nothing, even when using an XPath. I think there is some problem with parsing it, but I have no idea why. Will I have to write my own parser?