5.2.12. ytpb.segment

Media segments and their metadata.

class ytpb.segment.SegmentMetadata(sequence_number: int, ingestion_walltime: float, ingestion_uncertainty: float, target_duration: float, first_frame_time: float, first_frame_uncertainty: float, stream_duration: float = None, max_dvr_duration: float = None, streamable: str | None = None, encoding_alias: str | None = None)

Bases: object

Represents the YouTube segment metadata.

All timestamp and time-related values are in seconds.

sequence_number: int
ingestion_walltime: float
ingestion_uncertainty: float
target_duration: float
first_frame_time: float
first_frame_uncertainty: float
stream_duration: float = None
max_dvr_duration: float = None
streamable: str | None = None
encoding_alias: str | None = None
class ytpb.segment.Segment

Bases: object

A media segment.

classmethod from_file(path: Path) Segment

Creates a Segment object by reading file from path.

classmethod from_bytes(content: bytes) Segment

Creates a Segment object from bytes.

property ingestion_start_date: datetime

A segment ingestion start date.

Corresponds to the Ingestion-Walltime-Us value.

property ingestion_end_date: datetime

A segment ingestion end date.

Corresponds to the actual segment duration started from the Ingestion-Walltime-Us value.

static parse_youtube_metadata(content: bytes) SegmentMetadata

Parses the metadata from the full or partial content of a segment.

All timestamp and time-related values are converted to units of seconds.

Notes

If partial content is provided, the amount of bytes should be enough to cover the metadata header (see PARTIAL_SEGMENT_SIZE_BYTES).

Parameters:

content – Full or partial segment byte content.

Returns:

A parsed segment metadata.

get_actual_duration() float

Gets the actual segment duration in seconds.