W.H. Nipuna Sudharaka commited on
Commit
888aa41
·
unverified ·
1 Parent(s): a92dd5e

Fix #957 KeyError when 'dur' not present in XML subtitles (#958)

Browse files

* Fix #957 KeyError when 'dur' not present in XML subtitles by setting a default duration of 0.0 seconds

Files changed (1) hide show
  1. pytube/captions.py +4 -1
pytube/captions.py CHANGED
@@ -67,7 +67,10 @@ class Caption:
67
  for i, child in enumerate(list(root)):
68
  text = child.text or ""
69
  caption = unescape(text.replace("\n", " ").replace(" ", " "),)
70
- duration = float(child.attrib["dur"])
 
 
 
71
  start = float(child.attrib["start"])
72
  end = start + duration
73
  sequence_number = i + 1 # convert from 0-indexed to 1.
 
67
  for i, child in enumerate(list(root)):
68
  text = child.text or ""
69
  caption = unescape(text.replace("\n", " ").replace(" ", " "),)
70
+ try:
71
+ duration = float(child.attrib["dur"])
72
+ except KeyError:
73
+ duration = 0.0
74
  start = float(child.attrib["start"])
75
  end = start + duration
76
  sequence_number = i + 1 # convert from 0-indexed to 1.