pytubefix
pytubefix copied to clipboard
caption.download throw errors
Hi, I've installed pytubefix version 5.1.2. Here's the test code:
from pytubefix import YouTube
from pytubefix import Channel
url = 'https://www.youtube.com/watch?v=JRAUvWLULEk' # caption failed
def test_YouTube():
yt = YouTube(url, on_progress_callback=show_download_progress
, use_oauth=True, allow_oauth_cache=True)
video_stream = yt.streams.get_highest_resolution()
output_path = r"./"
# video_title_file = "test.mp4"
# video_stream.download(output_path=output_path, filename=video_title_file, max_retries=5)
for caption in yt.captions:
caption_code = caption.code
if 'en' in caption_code:
print(f':{caption} {caption_code}...')
caption.download(title=yt.title,output_path=output_path)
print(f'{caption_code} downloaded successfully.')
if __name__ == '__main__':
test_YouTube()
Below is the error message I get when running the code:
PS D:\code\python\project\some-reverse-works\examples\pytube> python .\test_pytubefix.py
:<Caption lang="English (auto-generated)" code="a.en"> a.en...
Traceback (most recent call last):
File "D:\code\python\project\some-reverse-works\examples\pytube\test_pytubefix.py", line 62, in <module>
test_YouTube()
File "D:\code\python\project\some-reverse-works\examples\pytube\test_pytubefix.py", line 19, in test_YouTube
caption.download(title=yt.title,output_path=output_path)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\captions.py", line 179, in download
file_handle.write(self.generate_srt_captions())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\captions.py", line 61, in generate_srt_captions
return self.xml_caption_to_srt(self.xml_captions)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pytubefix\captions.py", line 101, in xml_caption_to_srt
for child in list(root.iter("body"))[0]:
IndexError: list index out of range
Originally posted by @jinhang87 in https://github.com/JuanBindez/pytubefix/issues/69#issuecomment-2080351497