GetPlaylistSubtitle

The GetPlaylistSubtitle class is designed to retrieve subtitles for all videos in a YouTube playlist. It supports filtering by various criteria, such as language and video count. The subtitles can also be saved to disk for offline usage.

Class Usage

from ytkit import GetPlaylistSubtitle

# Example usage
get_playlist_subtitle = GetPlaylistSubtitle()
result = get_playlist_subtitle.get(
    playlist_id="PL8dPuuaLjXtNamNKW5qlS-nKgA0on7Qze",
    limit=2,
    save_to_disk="data",
    language="en"
)

Method Details

Input Parameters

  • playlist_id (str): The unique ID of the YouTube playlist.

  • limit (Optional[int]): Maximum number of videos to fetch.

  • sleep (float): Time to wait between API calls. Defaults to 1 second and must be non-negative.

  • language (str): Desired language code for subtitles. Defaults to "en".

  • save_to_disk (Union[None, str]): Folder path where transcript files will be saved. If None, files are not saved to disk.

Examples

Fetching subtitles for the first two videos in a playlist:

get_playlist_subtitle = GetPlaylistSubtitle()
result = get_playlist_subtitle.get(
    playlist_id="PL8dPuuaLjXtNamNKW5qlS-nKgA0on7Qze",
    limit=2,
    save_to_disk="data",
    language="en"
)

print(result)

Notes

  • The playlist_id is required to identify the playlist.

  • If save_to_disk is specified, ensure the folder exists or provide a valid path.

  • Use the language parameter to specify the desired subtitle language.