Reference for youtube_dl_scraper/core/stream.py
¶
youtube_dl_scraper.core.stream.Stream
¶
A base class for handling streams and downloading files.
Attributes:
Name | Type | Description |
---|---|---|
file_name |
str
|
The name of the file to download. |
download_dir |
str
|
The directory where the file will be downloaded. |
size |
dict
|
A dictionary containing size details (width and height). |
get_url |
Callable
|
A callable to retrieve the stream URL. |
Methods:
Name | Description |
---|---|
download |
Downloads the file and handles renaming based on its type. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream_data
|
dict
|
Metadata about the stream. |
required |
download_dir
|
str
|
Directory to download the file. Defaults to "download". |
''
|
file_name
|
str
|
Name of the file to be downloaded. Defaults to "download". |
''
|
Source code in youtube_dl_scraper/core/stream.py
download
¶
download(file_name: str = '', skip_existent: bool = False, error_on_existent: bool = False, download_dir: str = '', on_complete: Optional[Callable[[str], None]] = None) -> str
Download the stream and optionally rename it based on its type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Name of the file to be downloaded. Defaults to the initialized file name. |
''
|
skip_existent
|
bool
|
Skip download if the file already exists. Defaults to False. |
False
|
error_on_existent
|
bool
|
Raise an error if the file already exists. Defaults to False. |
False
|
download_dir
|
str
|
Directory to download the file. Defaults to the initialized directory. |
''
|
on_complete
|
Callable
|
A callback function to run after download. Receives the file path as an argument. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The path to the downloaded file. |
Raises:
Type | Description |
---|---|
FileExistsError
|
If the file exists and |
RuntimeError
|
If the download fails. |
Source code in youtube_dl_scraper/core/stream.py
youtube_dl_scraper.core.stream.VideoStream
¶
Bases: Stream
A class for handling video streams.
Attributes:
Name | Type | Description |
---|---|---|
resolution_label |
str
|
The resolution label of the video (e.g., "1080p"). |
resolution_value |
str
|
The numeric resolution quality. |
has_audio |
bool
|
Indicates if the video has audio. |
frame_rate |
int
|
The frame rate of the video. |
is_hdr |
bool
|
Indicates if the video supports HDR. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream_data
|
dict
|
Metadata about the video stream. |
required |
download_path
|
str
|
Directory to download the file. Defaults to "". |
''
|
file_name
|
str
|
Name of the file to be downloaded. Defaults to "". |
''
|
Source code in youtube_dl_scraper/core/stream.py
youtube_dl_scraper.core.stream.AudioStream
¶
Bases: Stream
A class for handling audio streams.
Attributes:
Name | Type | Description |
---|---|---|
abr_label |
str
|
The audio bitrate label (e.g., "128kbps"). |
abr |
str
|
The numeric audio quality (alias for bitrate). |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stream_data
|
dict
|
Metadata about the audio stream. |
required |
download_path
|
str
|
Directory to download the file. Defaults to "". |
''
|
file_name
|
str
|
Name of the file to be downloaded. Defaults to "". |
''
|
Source code in youtube_dl_scraper/core/stream.py
youtube_dl_scraper.core.stream.file_exists
¶
Check if a file with the given name (without extension) exists in the directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The stem (name without extension) of the file to search for. |
required |
directory
|
Union[str, Path]
|
The path to the directory to search in. Can be a string or a Path object. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The full path to the file if it exists, otherwise None. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided directory path is invalid or does not exist. |