Spaces:
Runtime error
Runtime error
Fix no text but only \n in xml, eg: uwIHyLPBZkY.
Browse files- fetchYoutubeSubtitle.py +8 -1
fetchYoutubeSubtitle.py
CHANGED
@@ -215,6 +215,13 @@ def float_to_srt_time_format(d: float) -> str:
|
|
215 |
return time_fmt + ms
|
216 |
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
def xml_caption_to_srt(xml_captions: str) -> str:
|
219 |
"""Convert xml caption tracks to "SubRip Subtitle (srt)".
|
220 |
:param str xml_captions:
|
@@ -227,7 +234,7 @@ def xml_caption_to_srt(xml_captions: str) -> str:
|
|
227 |
caption = unescape(
|
228 |
text.replace("\n", " ").replace(" ", " "),
|
229 |
)
|
230 |
-
if len(caption) == 0:
|
231 |
continue
|
232 |
try:
|
233 |
duration = float(child.attrib["dur"])
|
|
|
215 |
return time_fmt + ms
|
216 |
|
217 |
|
218 |
+
def is_spaces_only(variable):
|
219 |
+
for char in variable:
|
220 |
+
if not char.isspace():
|
221 |
+
return False
|
222 |
+
return True
|
223 |
+
|
224 |
+
|
225 |
def xml_caption_to_srt(xml_captions: str) -> str:
|
226 |
"""Convert xml caption tracks to "SubRip Subtitle (srt)".
|
227 |
:param str xml_captions:
|
|
|
234 |
caption = unescape(
|
235 |
text.replace("\n", " ").replace(" ", " "),
|
236 |
)
|
237 |
+
if len(caption) == 0 or is_spaces_only(caption):
|
238 |
continue
|
239 |
try:
|
240 |
duration = float(child.attrib["dur"])
|