GetChannelSubtitle
The GetChannelSubtitle class is designed to retrieve subtitles from all videos in a YouTube channel. This functionality supports filtering videos by various criteria such as content type and popularity. Additionally, you can get subtitles in your desired language and save them to disk for offline usage.
Class Usage
from ytkit import GetChannelSubtitle
# Example usage
get_channel_subtlte = GetChannelSubtitle()
result = get_channel_subtlte.get(
channel_username="TEDx",
sort_by="popular",
limit=2,
save_to_disk="channel_data",
language="en"
)
Method Details
Input Parameters
channel_id (Optional[str]): The unique ID of the YouTube channel.
channel_url (Optional[str]): The URL of the YouTube channel.
channel_username (Optional[str]): The username of the YouTube channel.
limit (Optional[int]): Maximum number of videos to process.
sleep (float): Time to wait between API calls. Defaults to 1 second and must be non-negative.
sort_by (Literal[“newest”, “oldest”, “popular”]): Criterion for sorting videos. Defaults to
"newest".content_type (Literal[“videos”, “shorts”, “streams”]): Type of content to include. Defaults to
"videos".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 most popular videos of the TEDx channel:
get_channel_subtlte = GetChannelSubtitle()
result = get_channel_subtlte.get(
channel_username="TEDx",
sort_by="popular",
limit=2,
save_to_disk="channel_data",
language="en"
)
print(result)
Notes
Either channel_id, channel_url, or channel_username must be provided.
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.