Reference for youtube_dl_scraper/core/caption.py
¶
youtube_dl_scraper.core.caption.Caption
¶
Data class for captions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
caption_data
|
dict
|
The raw caption data, including language code, name, and download URLs. |
required |
title
|
str
|
The title of the associated video. |
required |
download_path
|
str
|
The directory where captions will be downloaded. |
required |
translated
|
bool
|
Whether the caption is translated. Defaults to False. |
False
|
Source code in youtube_dl_scraper/core/caption.py
raw
property
¶
Retrieve the raw caption content in SRT format.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The raw SRT content as a string. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the caption does not support the SRT format. |
srt
¶
srt(content: bool = False, download_path: Optional[str] = None, filename: Optional[str] = None, skip_existent: bool = False) -> Union[str, Path]
Download or retrieve the caption in SRT format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
bool
|
If True, return the content as a string; if False, save it to disk. Defaults to False. |
False
|
download_path
|
Optional[str]
|
The directory to save the file. Defaults to self.download_dir. |
None
|
filename
|
Optional[str]
|
The name of the file. Extracted from the content-disposition header if not provided. |
None
|
skip_existent
|
bool
|
If True, skips downloading if a matching file already exists. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[str, Path]
|
Union[str, Path]: File path if content is False, otherwise the SRT content as a string. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the caption does not support the SRT format. |
FileNotFoundError
|
If the specified file path is invalid. |
PermissionError
|
If permissions are insufficient. |
IsADirectoryError
|
If the specified file path is a directory. |
IOError
|
For I/O-related errors. |
OSError
|
For OS-level errors. |
Source code in youtube_dl_scraper/core/caption.py
txt
¶
txt(content: bool = False, download_path: Optional[str] = None, filename: Optional[str] = None, skip_existent: bool = False) -> Union[str, Path]
Download or retrieve the caption in TXT format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
bool
|
If True, return the content as a string; if False, save it to disk. Defaults to False. |
False
|
download_path
|
Optional[str]
|
The directory to save the file. Defaults to self.download_dir. |
None
|
filename
|
Optional[str]
|
The name of the file. Extracted from the content-disposition header if not provided. |
None
|
skip_existent
|
bool
|
If True, skips downloading if a matching file already exists. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[str, Path]
|
Union[str, Path]: File path if content is False, otherwise the TXT content as a string. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the caption does not support the TXT format. |
FileNotFoundError
|
If the specified file path is invalid. |
PermissionError
|
If permissions are insufficient. |
IsADirectoryError
|
If the specified file path is a directory. |
IOError
|
For I/O-related errors. |
OSError
|
For OS-level errors. |