Closed phasefactor closed 3 months ago
Both Caption.download() and Caption.save_captions() are calling Caption.xml_caption_to_srt() which is throwing:
Caption.download()
Caption.save_captions()
Caption.xml_caption_to_srt()
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/user/miniconda3/lib/python3.12/site-packages/pytubefix/captions.py", line 74, in save_captions srt_captions = self.xml_caption_to_srt(self.xml_captions) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/user/miniconda3/lib/python3.12/site-packages/pytubefix/captions.py", line 115, in xml_caption_to_srt caption = unescape(caption.replace("\n", " ").replace(" ", " "),) ^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'replace'
from pytubefix import YouTube yt = YouTube('https://www.youtube.com/watch?v=MFRWDuduuSw') yt.captions['en'].save_captions('test.srt')
The quick fix for this was to just check the type of caption on the line before captions.py:115:
caption
if caption == None: continue caption = unescape(caption.replace("\n", " ").replace(" ", " "),)
This seems to pull down the SRTs correctly, but I am sure there is a more elegant fix.
Describe the bug
Both
Caption.download()
andCaption.save_captions()
are callingCaption.xml_caption_to_srt()
which is throwing:To Reproduce
Additional Context
The quick fix for this was to just check the type of
caption
on the line before captions.py:115:This seems to pull down the SRTs correctly, but I am sure there is a more elegant fix.