5.2.13. ytpb.streams¶
Mutable set of streams.
- class ytpb.streams.Streams(iterable: list[AudioRepresentationInfo | VideoRepresentationInfo] | None = None)¶
Bases:
MutableSetRepresents a mutable set of
ytpb.representations.RepresentationInfoobjects.- add(value: AudioRepresentationInfo | VideoRepresentationInfo)¶
Adds a stream.
- discard(value: AudioRepresentationInfo | VideoRepresentationInfo)¶
Removes a stream.
- get_by_itag(itag: str) AudioRepresentationInfo | VideoRepresentationInfo | None¶
Gets a stream by an itag value.
- filter(predicate: Callable[[AudioRepresentationInfo | VideoRepresentationInfo], bool]) Streams[AudioRepresentationInfo | VideoRepresentationInfo]¶
Filters streams by a predicate function.
- Parameters:
predicate – A predicate function.
Examples
Get only video streams:
from ytpb.types import VideoStream playback.streams.filter(lambda x: x.type == "video")
- Returns:
A new instance of this class with filtered streams.
- query(format_spec: str, functions: dict[str, QueryFunction] | None = None) list[AudioRepresentationInfo | VideoRepresentationInfo]¶
Queries streams by a format spec.
Notes
Check for attributes is strict. This means that the following code will fail with
QueryErrorbecause audio streams don’t have theheightattribute:audio_streams.query("height eq 1080")
References
https://ytpb.readthedocs.io/en/latest/reference.html#format-spec
- Parameters:
format_spec – A format spec.
functions – Additional query functions to be used in a format spec. For built-in functions, see
ytpb.format_spec.FUNCTIONS.
- Returns:
A list of queried streams.
- Raises:
QueryError – If failed to query streams with the given format spec.