diff --git a/pytube/captions.py b/pytube/captions.py index fe84bec3f..544f96ed9 100644 --- a/pytube/captions.py +++ b/pytube/captions.py @@ -83,14 +83,15 @@ def xml_caption_to_srt(self, xml_captions: str) -> str: """ segments = [] root = ElementTree.fromstring(xml_captions) - for i, child in enumerate(list(root)): + body = root.find("body") + for i, child in enumerate(list(body)): text = child.text or "" caption = unescape(text.replace("\n", " ").replace(" ", " "),) try: - duration = float(child.attrib["dur"]) + duration = float(child.attrib["d"])/1000 except KeyError: duration = 0.0 - start = float(child.attrib["start"]) + start = float(child.attrib["t"])/1000 end = start + duration sequence_number = i + 1 # convert from 0-indexed to 1. line = "{seq}\n{start} --> {end}\n{text}\n".format(