Skip to content

Pytubefix 1.3.0 Released

Compare
Choose a tag to compare
@JuanBindez JuanBindez released this 02 Oct 13:42
· 496 commits to main since this release

Release Notes:

  • added method to save subtitles in txt file in captions.py
def save_captions(self, filename: str):
        """Generate and save "SubRip Subtitle" captions to a text file.

        Takes the xml captions from :meth:`~pytubefix.Caption.xml_captions` and
        recompiles them into the "SubRip Subtitle" format and saves it to a text file.
        
        :param filename: The name of the file to save the captions.
        """
        srt_captions = self.xml_caption_to_srt(self.xml_captions)
        
        with open(filename, 'w', encoding='utf-8') as file:
            file.write(srt_captions)

Usage:

from pytubefix import YouTube
 

yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')

caption = yt.captions.get_by_language_code('en')
caption.save_captions("captions.txt")