Reference for youtube_dl_scraper/core/stream_array.py
¶
youtube_dl_scraper.core.stream_array.StreamArray
¶
A utility class to manage and manipulate a collection of video and audio streams.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
streams
|
List[Stream]
|
A list of initial streams to add. |
required |
video_api
|
Callable
|
A callable for video stream APIs (reserved for future use). |
required |
audio_api
|
Callable
|
A callable for audio stream APIs (reserved for future use). |
required |
Source code in youtube_dl_scraper/core/stream_array.py
available_qualities
property
¶
Get available video and audio qualities.
Returns:
Type | Description |
---|---|
dict[str, tuple[int, ...]]
|
dict[str, tuple[int, ...]]: A dictionary containing video resolutions and audio bitrates. |
bitrates
property
¶
Get all unique audio bitrates in the stream collection.
Returns:
Type | Description |
---|---|
tuple[int, ...]
|
tuple[int, ...]: Tuple of audio bitrates. |
frame_rates
property
¶
Get all unique frame rates from video streams.
Returns:
Type | Description |
---|---|
tuple[int, ...]
|
tuple[int, ...]: Tuple of frame rates. |
resolutions
property
¶
Get all unique video resolutions in the stream collection.
Returns:
Type | Description |
---|---|
tuple[int, ...]
|
tuple[int, ...]: Tuple of video resolutions. |
streams
property
¶
Return all streams, sorted by resolution for videos and bitrate for audio.
Returns:
Type | Description |
---|---|
tuple[Stream, ...]
|
tuple[Stream, ...]: Sorted tuple of streams. |
__getitem__
¶
Access a stream by its index or sliced stream array by its slice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
Union[int, slice]
|
index (int): The index of the stream. slice (slice): The slice of the streams. |
required |
Returns:
Type | Description |
---|---|
Stream
|
outputs (Union[Stream, StreamArray]) Stream: The stream at the given index. StreamArray: The stream array from the slice. |
Source code in youtube_dl_scraper/core/stream_array.py
__iter__
¶
Initialize iteration over the streams.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The StreamArray object. |
__len__
¶
__next__
¶
Get the next stream during iteration.
Returns:
Name | Type | Description |
---|---|---|
Stream |
Stream
|
The next stream. |
Raises:
Type | Description |
---|---|
StopIteration
|
If no more streams are available. |
Source code in youtube_dl_scraper/core/stream_array.py
__str__
¶
Get a string representation of the streams.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
String representation of the streams. |
add_stream
¶
Add one or more streams to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*streams
|
Stream
|
Streams to add. |
()
|
filter
¶
Filter streams based on attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Union[str, int, bool]
|
Attribute-value pairs to filter by. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
A StreamArray with the filtered streams. |
Source code in youtube_dl_scraper/core/stream_array.py
first
¶
Get the first stream in the collection.
Returns:
Type | Description |
---|---|
Optional[Stream]
|
Optional[Stream]: The first stream, or None if empty. |
get_audio_streams
¶
Get a new StreamArray containing only audio streams.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
A StreamArray with audio streams. |
Source code in youtube_dl_scraper/core/stream_array.py
get_highest_bitrate
¶
Get the audio stream with the highest bitrate.
Returns:
Type | Description |
---|---|
Optional[AudioStream]
|
Optional[AudioStream]: The highest bitrate audio stream. |
Source code in youtube_dl_scraper/core/stream_array.py
get_highest_resolution
¶
Get the video stream with the highest resolution.
Returns:
Type | Description |
---|---|
Optional[VideoStream]
|
Optional[VideoStream]: The highest resolution video stream. |
Source code in youtube_dl_scraper/core/stream_array.py
get_video_streams
¶
Get a new StreamArray containing only video streams.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
A StreamArray with video streams. |
Source code in youtube_dl_scraper/core/stream_array.py
last
¶
Get the last stream in the collection.
Returns:
Type | Description |
---|---|
Optional[Stream]
|
Optional[Stream]: The last stream, or None if empty. |
order_by
¶
Order streams by a specific attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The attribute to order by. |
required |
reverse
|
bool
|
Whether to reverse the order. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
A StreamArray with ordered streams. |