### Install Dependencies Source: https://github.com/luanrt/googlevideo/blob/main/examples/sabr-shaka-example/README.md Run this command to install the necessary project dependencies. ```bash npm install ``` -------------------------------- ### Build and Run Downloader Example Source: https://github.com/luanrt/googlevideo/blob/main/examples/README.md Builds the LuanRT library and runs the downloader example using npm and tsx. Includes an option to run a specific ffmpeg example. ```bash npm run build # If you haven't built the library yet. cd examples/downloader npm install npx tsx main.ts # Example with ffmpeg npx tsx ffmpeg-example.ts ``` -------------------------------- ### Install googlevideo via NPM, JSR/Deno, or GitHub Source: https://github.com/luanrt/googlevideo/blob/main/README.md Shows the commands to install the googlevideo package using different package managers. ```bash # NPM npm install googlevideo # JSR / Deno npx jsr add @luanrt/googlevideo denp add jsr:@luanrt/googlevideo # GitHub npm install LuanRT/googlevideo ``` -------------------------------- ### Start Development Server Source: https://github.com/luanrt/googlevideo/blob/main/examples/sabr-shaka-example/README.md Execute this command to launch the local development server. ```bash npm run dev ``` -------------------------------- ### Logger Usage Example Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Demonstrates how to get the logger instance, set active log levels, and log messages. ```typescript const logger = Logger.getInstance(); logger.setLogLevels(LogLevel.ERROR, LogLevel.INFO); logger.error('MyTag', 'An error occurred'); ``` -------------------------------- ### start() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Initiates the streaming process for the selected formats. It returns a promise that resolves with the video/audio streams and selected formats. ```APIDOC ## start() ### Description Initiates the streaming process for the selected formats. ### Method `start` ### Parameters #### options - **options** (SabrPlaybackOptions) - Required - Playback options, including format preferences and initial state. ### Returns `Promise`<{ `audioStream`: `ReadableStream` <`Uint8Array`< `ArrayBufferLike` > >; `selectedFormats`: `SelectedFormats`; `videoStream`: `ReadableStream` <`Uint8Array`< `ArrayBufferLike` > >; }> A promise that resolves with the video/audio streams and selected formats. ### Throws If no suitable formats are found or streaming fails. ``` -------------------------------- ### Build and Run Onesie Request Example Source: https://github.com/luanrt/googlevideo/blob/main/examples/README.md Builds the LuanRT library and runs the onesie request example using npm and tsx. ```bash npm run build # If you haven't built the library yet. cd examples/onesie-request npm install npx tsx main.ts ``` -------------------------------- ### Basic UMP Data Handling with googlevideo Source: https://github.com/luanrt/googlevideo/blob/main/README.md Demonstrates how to use UMP modules to create a buffer, write parts, and process them. This example includes handlers for media headers, media parts, and media end parts. ```typescript import { CompositeBuffer, UmpReader, UmpWriter } from 'googlevideo/ump'; import { MediaHeader, UMPPartId } from 'googlevideo/protos'; import { concatenateChunks } from 'googlevideo/utils'; import { Part } from 'googlevideo/shared-types'; function handleMediaHeader(part: Part) { const mediaHeader = MediaHeader.decode(concatenateChunks(part.data.chunks)); console.log('Media Header:', mediaHeader); } function handleMedia(part: Part) { const headerId = part.data.getUint8(0); console.log(`Media Part (Associated Header ID: ${headerId}):`, part.data.split(1).remainingBuffer.getLength(), 'bytes'); } function handleMediaEnd(part: Part) { const headerId = part.data.getUint8(0); console.log(`Media End Part (Associated Header ID: ${headerId}):`, part.data.split(1).remainingBuffer.getLength(), 'bytes'); } const umpPartHandlers = new Map void>([ [ UMPPartId.MEDIA_HEADER, handleMediaHeader ], [ UMPPartId.MEDIA, handleMedia ], [ UMPPartId.MEDIA_END, handleMediaEnd ] ]); const buffer = mockUmpData(); const reader = new UmpReader(buffer); reader.read((part) => { const handler = umpPartHandlers.get(part.type); if (handler) { handler(part); } else { console.warn(`No handler for part type: ${part.type}`); } }); /** * Generates a mock UMP data buffer containing a MEDIA_HEADER, and respective MEDIA and MEDIA_END parts. * This group represents a single audio segment, which is what you would typically see * in a real UMP stream. */ function mockUmpData(): CompositeBuffer { const buffer = new CompositeBuffer(); const writer = new UmpWriter(buffer); const audioHeaderId = 0; const partsToWrite: [UMPPartId, Uint8Array][] = [ [ UMPPartId.MEDIA_HEADER, MediaHeader.encode({ headerId: audioHeaderId, videoId: "sOa4VVlI9tE", itag: 141, lmt: 1645502668395260, xtags: "", startRange: 5463800, isInitSeg: false, sequenceNumber: 0, durationMs: 0, formatId: { itag: 141, lastModified: 1645502668395260, xtags: "" }, contentLength: 963966, }).finish() ], [ UMPPartId.MEDIA, new Uint8Array([ audioHeaderId, ...new Uint8Array(827609).fill(0) ]) ], [ UMPPartId.MEDIA, new Uint8Array([ audioHeaderId, ...new Uint8Array(136357).fill(0) ]) ], [ UMPPartId.MEDIA_END, new Uint8Array([ audioHeaderId ]) ] ]; for (const [type, data] of partsToWrite) { writer.write(type, data); } return buffer; } ``` -------------------------------- ### getInstance() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Gets the singleton instance of the Logger class. ```APIDOC ## Method: getInstance() > `static` **getInstance**(): `Logger` Gets the singleton instance of the Logger class. #### Returns `Logger` ``` -------------------------------- ### getLogLevels() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Gets the current set of active log levels. ```APIDOC ## Method: getLogLevels() > **getLogLevels**(): `Set`<[`LogLevel`](../enumerations/LogLevel.md)"> Gets the current set of active log levels. #### Returns `Set`<[`LogLevel`](../enumerations/LogLevel.md)"> A new Set containing the active LogLevel enums. ``` -------------------------------- ### Method: attach Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Initializes the player adapter and sets up request/response interceptors. This method should be called to begin the integration process. ```APIDOC ## Method: attach ### Description Initializes the player adapter and sets up request/response interceptors. This method should be called to begin the integration process. ### Parameters #### player - **player** (any) - Required - The player instance to attach the adapter to. ### Returns - void ### Throws - SabrAdapterError - if the adapter has been disposed. ``` -------------------------------- ### parseRangeHeader() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/functions/parseRangeHeader.md Parses the Range header value to extract the start and end byte positions. It returns an object with 'start' and 'end' properties if the header is valid, otherwise it returns undefined. ```APIDOC ## Function: parseRangeHeader() > **parseRangeHeader**(`rangeHeaderValue`): `undefined` | `Range` Parses the Range header value to extract the start and end byte positions. ### Parameters #### rangeHeaderValue - **rangeHeaderValue** (undefined | string) - The value of the Range header. ### Returns - **Range** (object) - An object containing the start and end byte positions, or undefined if the header is invalid or not present. - **start** (number) - The starting byte position. - **end** (number) - The ending byte position. ``` -------------------------------- ### on() - formatInitialization Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Fired when the server sends initialization metadata for a media format. ```APIDOC ## on() - formatInitialization ### Description Fired when the server sends initialization metadata for a media format. ### Method `on` ### Parameters #### event - **event** (`"formatInitialization"`) - Required - The event name. #### listener - **listener** (`initializedFormat`) => `void` - Required - The callback function. ### Returns `void` ``` -------------------------------- ### Get Logger Instance Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Retrieves the singleton instance of the Logger class. ```typescript const logger = Logger.getInstance(); ``` -------------------------------- ### initialize() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/interfaces/SabrPlayerAdapter.md Initializes the SabrPlayerAdapter with the necessary player, metadata manager, and cache instances. ```APIDOC ## initialize() ### Description Initializes the SabrPlayerAdapter with the necessary player, metadata manager, and cache instances. ### Method initialize ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **player** (any) - Required - The player instance. * **requestMetadataManager** ([`RequestMetadataManager`](../../utils/classes/RequestMetadataManager.md)) - Required - The request metadata manager. * **cache** (`null` | [`CacheManager`](../../utils/classes/CacheManager.md)) - Optional - The cache manager instance. ### Request Example ```json { "player": "any", "requestMetadataManager": "RequestMetadataManager", "cache": "CacheManager | null" } ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example None ``` -------------------------------- ### Get Active Log Levels Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Retrieves the current set of active log levels configured for the logger. ```typescript const activeLevels = logger.getLogLevels(); ``` -------------------------------- ### Constructor: new SabrStreamingAdapter Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Initializes a new instance of the SabrStreamingAdapter. It requires configuration options and may throw an error if a player adapter is not provided. ```APIDOC ## Constructor: new SabrStreamingAdapter ### Description Initializes a new instance of the SabrStreamingAdapter. It requires configuration options and may throw an error if a player adapter is not provided. ### Parameters #### options - **options** (SabrOptions) - Required - Configuration options for the adapter. ### Returns - SabrStreamingAdapter - A new instance of the SabrStreamingAdapter. ### Throws - SabrAdapterError - if a player adapter is not provided. ``` -------------------------------- ### fromFormatInitializationMetadata() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/namespaces/FormatKeyUtils/functions/fromFormatInitializationMetadata.md Creates a format key from FormatInitializationMetadata. It takes a FormatInitializationMetadata object as input and returns a string representing the format key. If the formatId within the metadata is undefined, it returns undefined. ```APIDOC ## Function: fromFormatInitializationMetadata() > **fromFormatInitializationMetadata**(`formatInitMetadata`): `string` Defined in: [codeberg/googlevideo/src/utils/formatKeyUtils.ts:35](https://github.com/LuanRT/googlevideo/blob/19854137cadaf49fd755394883dfd7fe5fdaba20/src/utils/formatKeyUtils.ts#L35) Creates a format key from FormatInitializationMetadata. ## Parameters ### formatInitMetadata - **formatInitMetadata** (`FormatInitializationMetadata`) - Required - Metadata object used to create the format key. ## Returns `string` A string format key or undefined if formatId is undefined. ``` -------------------------------- ### Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/RequestMetadataManager.md Initializes a new instance of the RequestMetadataManager class. ```APIDOC ## Constructor ### Description Initializes a new instance of the RequestMetadataManager class. ### Returns `RequestMetadataManager` ``` -------------------------------- ### Method: onMintPoToken Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Registers a callback function to mint a new PoToken. This is used for authentication or authorization purposes. ```APIDOC ## Method: onMintPoToken ### Description Registers a callback function to mint a new PoToken. This is used for authentication or authorization purposes. ### Parameters #### cb - **cb** (OnMintPoTokenCallback) - Required - The callback function to be executed when a PoToken needs to be minted. ### Returns - void ``` -------------------------------- ### SabrAdapterError Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/SabrAdapterError.md Initializes a new instance of the SabrAdapterError class. This error can optionally include a specific error code. ```APIDOC ## new SabrAdapterError(message, code?) ### Description Constructs a new SabrAdapterError instance. ### Parameters #### message - **message** (string) - The error message describing the cause of the error. #### code? - **code** (string) - Optional. An error code associated with this specific adapter error. ### Returns - `SabrAdapterError` - A new instance of SabrAdapterError. ``` -------------------------------- ### SabrUmpProcessor Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrUmpProcessor.md Initializes a new instance of the SabrUmpProcessor class. It requires request metadata and optionally accepts a cache manager. ```APIDOC ## Constructor ### new SabrUmpProcessor(requestMetadata, cacheManager?) #### Parameters - **requestMetadata** (`SabrRequestMetadata`) - Required - Metadata for the request. - **cacheManager?** (`CacheManager`) - Optional - An instance of CacheManager for caching stream data. ``` -------------------------------- ### fromMediaHeader Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/namespaces/FormatKeyUtils/functions/fromMediaHeader.md Creates a format key from a MediaHeader object. ```APIDOC ## Function: fromMediaHeader() > **fromMediaHeader**(`mediaHeader`): `string` Defined in: [codeberg/googlevideo/src/utils/formatKeyUtils.ts:27](https://github.com/LuanRT/googlevideo/blob/19854137cadaf49fd755394883dfd7fe5fdaba20/src/utils/formatKeyUtils.ts#L27) Creates a format key from a MediaHeader object. ## Parameters ### mediaHeader [`MediaHeader`](../../../../protos/interfaces/MediaHeader.md) ## Returns `string` A string format key. ``` -------------------------------- ### on() - streamComplete Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Fired when the entire stream has been successfully downloaded. ```APIDOC ## on() - streamComplete ### Description Fired when the entire stream has been successfully downloaded. ### Method `on` ### Parameters #### event - **event** (`"streamComplete"`) - Required - The event name. #### listener - **listener** (`void`) => `void` - Required - The callback function. ### Returns `void` ``` -------------------------------- ### Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/CacheManager.md Initializes a new instance of the CacheManager class. It allows configuration of the maximum cache size in megabytes and the maximum age of cache entries in seconds. ```APIDOC ## new CacheManager ### Description Initializes a new instance of the CacheManager class with optional maximum size and age. ### Parameters #### maxSizeMB - **maxSizeMB** (number) - Optional - The maximum size of the cache in megabytes. Defaults to 50. #### maxAgeSeconds - **maxAgeSeconds** (number) - Optional - The maximum age of cache entries in seconds. Defaults to 600. ### Returns - `CacheManager` - A new instance of the CacheManager. ``` -------------------------------- ### SabrPlaybackOptions Interface Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/interfaces/SabrPlaybackOptions.md Defines the configuration options for SABR playback, allowing users to specify preferences for audio and video formats, languages, quality, and other playback-related settings. ```APIDOC ## Interface: SabrPlaybackOptions This interface defines the configurable options for SABR playback. ### Properties * **audioFormat?** (`number` | [`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md) | (`formats`) => `undefined` | [`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md)) - Optional. Specifies the audio format. Can be a format ID, a SabrFormat object, or a function to select a format. * **audioLanguage?** (`string`) - Optional. Preferred audio language code. * **audioQuality?** (`string`) - Optional. Preferred audio quality (e.g., "high", "medium"). * **enabledTrackTypes?** ([`EnabledTrackTypes`](../../utils/enumerations/EnabledTrackTypes.md)) - Optional. Specifies which track types (audio, video, or both) are enabled for streaming. * **maxRetries?** (`number`) - Optional. Maximum number of retry attempts for fetching segments. Defaults to 10. * **preferH264?** (`boolean`) - Optional. If true, prefers the H.264 video codec. * **preferMP4?** (`boolean`) - Optional. If true, prefers the MP4 container format. * **preferOpus?** (`boolean`) - Optional. If true, prefers the Opus audio codec. * **preferWebM?** (`boolean`) - Optional. If true, prefers the WebM container format. * **stallDetectionMs?** (`number`) - Optional. Duration in milliseconds to detect a stall if no progress is made. Defaults to 30000. * **state?** ([`SabrStreamState`](SabrStreamState.md)) - Optional. Previously saved state to resume a download. * **videoFormat?** (`number` | [`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md) | (`formats`) => `undefined` | [`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md)) - Optional. Specifies the video format. Can be a format ID, a SabrFormat object, or a function to select a format. * **videoLanguage?** (`string`) - Optional. Preferred video language code. ``` -------------------------------- ### read Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/ump/classes/UmpReader.md Parses parts from the buffer and invokes a handler for each complete part. ```APIDOC ## read(handlePart) ### Description Parses parts from the buffer and calls the handler for each complete part. ### Parameters #### Parameters - **handlePart** ((part) => void) - Required - Function called with each complete part. ### Returns `undefined` | `Part` Partial part if parsing is incomplete, undefined otherwise. ``` -------------------------------- ### UmpReader Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/ump/classes/UmpReader.md Initializes a new instance of the UmpReader class with a composite buffer. ```APIDOC ## new UmpReader(compositeBuffer) ### Description Initializes a new instance of the UmpReader class. ### Parameters #### Parameters - **compositeBuffer** (CompositeBuffer) - The composite buffer to read from. ### Returns `UmpReader` A new instance of the UmpReader class. ``` -------------------------------- ### ClientInfo Properties Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/ClientInfo.md The ClientInfo interface includes several optional properties that allow for the reporting of screen and window dimensions, pixel density, and time zone information. ```APIDOC ## ClientInfo Interface ### Description This interface provides optional fields to capture client-side information relevant to video streaming, such as screen and window dimensions, pixel density, and time zone. ### Properties #### `screenHeightPoints` - **Type**: `number` - **Optional**: Yes - **Description**: The height of the client's screen in points. #### `screenWidthPoints` - **Type**: `number` - **Optional**: Yes - **Description**: The width of the client's screen in points. #### `screenWidthInches` - **Type**: `number` - **Optional**: Yes - **Description**: The width of the client's screen in inches. #### `screenPixelDensity` - **Type**: `number` - **Optional**: Yes - **Description**: The pixel density of the client's screen. #### `windowWidthPoints` - **Type**: `number` - **Optional**: Yes - **Description**: The width of the client's window in points. #### `windowHeightPoints` - **Type**: `number` - **Optional**: Yes - **Description**: The height of the client's window in points. #### `utcOffsetMinutes` - **Type**: `number` - **Optional**: Yes - **Description**: The client's UTC offset in minutes. #### `timeZone` - **Type**: `string` - **Optional**: Yes - **Description**: The client's time zone identifier (e.g., 'America/New_York'). ``` -------------------------------- ### SabrStream Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Initializes a new instance of the SabrStream class. This constructor is used to set up the stream management with a configuration object. ```APIDOC ## new SabrStream(config) ### Description Initializes a new instance of the SabrStream class with the provided configuration. ### Parameters #### config - **config** (SabrStreamConfig) - Optional - Configuration object for SabrStream. ### Returns - SabrStream - A new instance of SabrStream. ``` -------------------------------- ### fromFormat() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/namespaces/FormatKeyUtils/functions/fromFormat.md Creates a format key from a SabrFormat object. The function accepts an optional format object which may contain 'itag' (number) and 'xtags' (string) properties. It returns a string representation of the format key or undefined if the input format is undefined. ```APIDOC ## Function: fromFormat() > **fromFormat**(`format?`): `undefined` | `string` Defined in: [codeberg/googlevideo/src/utils/formatKeyUtils.ts:18](https://github.com/LuanRT/googlevideo/blob/19854137cadaf49fd755394883dfd7fe5fdaba20/src/utils/formatKeyUtils.ts#L18) Creates a format key from a SabrFormat object. ## Parameters ### format? An optional object that can contain the following properties: #### itag? `number` #### xtags? `string` ## Returns `undefined` | `string` A string format key or undefined if format is undefined. ``` -------------------------------- ### Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Initializes a new instance of the Logger class. This constructor is typically not called directly due to the singleton pattern. ```APIDOC ## Constructor: new Logger() > **new Logger**(): `Logger` Initializes a new instance of the Logger class. #### Returns `Logger` ``` -------------------------------- ### getInitSegment() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/CacheManager.md Retrieves an initialized segment from the cache using its key. Returns undefined if the segment is not found. ```APIDOC ## getInitSegment ### Description Retrieves an initialized segment from the cache by its key. ### Parameters #### key - **key** (string) - Required - The key of the initialized segment to retrieve. ### Returns - `undefined` | `Uint8Array` - The initialized segment data as a Uint8Array, or undefined if not found. ``` -------------------------------- ### Logger Class Overview Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Provides a singleton instance for logging. Users can enable/disable log levels and log messages with tags. ```APIDOC ## Class: Logger Singleton logger utility. Allows enabling or disabling specific log levels (`ERROR`, `WARN`, `INFO`, `DEBUG`) at runtime. Supports logging with tags and message arguments. Usage: ```ts const logger = Logger.getInstance(); logger.setLogLevels(LogLevel.ERROR, LogLevel.INFO); logger.error('MyTag', 'An error occurred'); ``` ``` -------------------------------- ### MediaCapabilities Interface Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/MediaCapabilities.md The MediaCapabilities interface defines the capabilities of media playback, including supported audio and video formats, and HDR capabilities. ```APIDOC ## Interface: MediaCapabilities ### Description Represents the media capabilities of a device or system, including supported audio and video formats, and HDR mode. ### Properties #### audioFormatCapabilities - **Type**: `MediaCapabilities_AudioFormatCapability`[] - **Description**: An array of supported audio format capabilities. #### hdrModeBitmask - **Type**: `number` - **Description**: An optional bitmask representing supported HDR modes. #### videoFormatCapabilities - **Type**: `MediaCapabilities_VideoFormatCapability`[] - **Description**: An array of supported video format capabilities. ``` -------------------------------- ### InitializedFormat Interface Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/interfaces/InitializedFormat.md This interface details the properties available after a stream has been initialized, providing access to downloaded segments, format-specific initialization metadata, and the last received media headers. ```APIDOC ## Interface: InitializedFormat ### Description This interface represents the state of a stream after initialization, providing access to its properties. ### Properties - **formatInitializationMetadata** (`FormatInitializationMetadata`) - Required - Metadata required for initializing the format. - **downloadedSegments** (`Map`) - Required - A map of segment numbers to their corresponding Segment objects that have been downloaded. - **lastMediaHeaders** (`MediaHeader[]`) - Required - An array containing the last received media headers. ``` -------------------------------- ### on Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/EventEmitterLike.md Adds an event listener for the specified event type. ```APIDOC ## on ### Description Adds an event listener for the specified event type. ### Signature ```typescript on(type: string, listener: (...args) => void): void ``` ### Parameters #### type - **type** (string) - The type of the event to listen for. #### listener - **listener** ((...args) => void) - The function to call when the event is dispatched. ### Returns `void` ``` -------------------------------- ### setClientInfo(clientInfo) Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Sets the client information that will be used in subsequent SABR requests. ```APIDOC ## setClientInfo(clientInfo) ### Description Sets the client information used in SABR requests. ### Method POST (conceptual) ### Parameters #### Path Parameters - **clientInfo** (ClientInfo) - Required - The client information object. ### Returns `void` ``` -------------------------------- ### abort() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Aborts the download process, closing all streams and cleaning up resources. This method also emits an 'abort' event upon completion. ```APIDOC ## abort() ### Description Aborts the download process, closing all streams and cleaning up resources. Emits an 'abort' event. ### Returns - void ``` -------------------------------- ### Constructor Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/EventEmitterLike.md Initializes a new instance of the EventEmitterLike class. This constructor overrides the default EventTarget constructor. ```APIDOC ## Constructor ### Description Initializes a new instance of the EventEmitterLike class. ### Signature ```typescript new EventEmitterLike(): EventEmitterLike ``` ### Returns An instance of EventEmitterLike. ### Overrides `EventTarget.constructor` ``` -------------------------------- ### Method: onReloadPlayerResponse Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Handles server requests to reload the player with new parameters. This is useful for dynamic updates to the player's state or content. ```APIDOC ## Method: onReloadPlayerResponse ### Description Handles server requests to reload the player with new parameters. This is useful for dynamic updates to the player's state or content. ### Parameters #### cb - **cb** (OnReloadPlayerResponseCb) - Required - The callback function to handle the player response reload. ### Returns - void ``` -------------------------------- ### LiveMetadata Properties Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/LiveMetadata.md The LiveMetadata interface contains several optional properties that provide metadata about a live video stream. These include identifiers like broadcastId and videoId, timing information such as wallTimeMs and headTimeMs, sequence numbers, seekable time ranges, and a flag for post-live DVR functionality. ```APIDOC ## Interface: LiveMetadata ### Description Provides optional metadata for live video streams. ### Properties - **broadcastId** (`string`): Optional. The identifier for the broadcast. - **headSequenceNumber** (`number`): Optional. The sequence number of the current head of the stream. - **headTimeMs** (`number`): Optional. The timestamp in milliseconds of the current head of the stream. - **wallTimeMs** (`number`): Optional. The wall clock time in milliseconds when the metadata was generated. - **videoId** (`string`): Optional. The identifier for the video. - **postLiveDvr** (`boolean`): Optional. Indicates if post-live DVR functionality is enabled. - **headm** (`number`): Optional. Unknown purpose, likely related to stream head metadata. - **minSeekableTimeTicks** (`number`): Optional. The minimum seekable time in ticks. - **maxSeekableTimeTicks** (`number`): Optional. The maximum seekable time in ticks. - **minSeekableTimescale** (`number`): Optional. The timescale for the minimum seekable time. - **maxSeekableTimescale** (`number`): Optional. The timescale for the maximum seekable time. ``` -------------------------------- ### setPoToken() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Sets the Proof of Origin (PO) token. This token is typically a base64-encoded string. ```APIDOC ## setPoToken() ### Description Sets the Proof of Origin (PO) token. ### Method `setPoToken` ### Parameters #### poToken - **poToken** (string) - Required - The base64-encoded token string. ### Returns `void` ``` -------------------------------- ### FormatInitializationMetadata Interface Properties Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/FormatInitializationMetadata.md This snippet details the properties of the FormatInitializationMetadata interface. Each property is optional and has a specified type. ```APIDOC ## Interface: FormatInitializationMetadata ### Description This interface defines the metadata required for initializing video streaming formats. It includes various optional properties to specify details about the video, format, and timing. ### Properties - **videoId** (string) - Optional - The unique identifier for the video. - **formatId** (FormatId) - Optional - The identifier for the specific format. - **endTimeMs** (number) - Optional - The end time of the segment in milliseconds. - **endSegmentNumber** (number) - Optional - The ending segment number. - **mimeType** (string) - Optional - The MIME type of the format. - **initRange** (Range) - Optional - The range for initialization data. - **indexRange** (Range) - Optional - The range for the index data. - **durationUnits** (number) - Optional - The units for duration. - **durationTimescale** (number) - Optional - The timescale for duration. - **field8** (number) - Optional - An unspecified field, likely for future use or internal purposes. ``` -------------------------------- ### Method: setStreamingURL Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Sets the initial server abr streaming URL. This is the primary URL used by the adapter to initiate streaming. ```APIDOC ## Method: setStreamingURL ### Description Sets the initial server abr streaming URL. This is the primary URL used by the adapter to initiate streaming. ### Parameters #### url? - **url** (string) - Optional - The streaming URL to set. ### Returns - void ### Throws - SabrAdapterError - if the adapter has been disposed. ``` -------------------------------- ### setUstreamerConfig() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Sets the ustreamer configuration for SABR requests. This method configures the adapter with specific ustreamer settings, which are used for subsequent SABR requests. It can throw an error if the adapter has already been disposed. ```APIDOC ## setUstreamerConfig() ### Description Sets the ustreamer configuration for SABR requests. This method configures the adapter with specific ustreamer settings, which are used for subsequent SABR requests. It can throw an error if the adapter has already been disposed. ### Method (Not specified, likely a class method) ### Parameters #### ustreamerConfig? - **ustreamerConfig** (string) - Optional - The ustreamer configuration string. ### Returns `void` ### Throws SabrAdapterError if the adapter has been disposed. ``` -------------------------------- ### dispose() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/interfaces/SabrPlayerAdapter.md Cleans up resources and deactivates the adapter. ```APIDOC ## dispose() ### Description Cleans up resources and deactivates the adapter. ### Method dispose ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (void) This method does not return a value. #### Response Example None ``` -------------------------------- ### once Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/EventEmitterLike.md Adds an event listener that will be called at most once for the specified event type. ```APIDOC ## once ### Description Adds an event listener that will be called at most once for the specified event type. ### Signature ```typescript once(type: string, listener: (...args) => void): void ``` ### Parameters #### type - **type** (string) - The type of the event to listen for. #### listener - **listener** ((...args) => void) - The function to call when the event is dispatched. ### Returns `void` ``` -------------------------------- ### PlaybackAuthorization Interface Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/PlaybackAuthorization.md This snippet details the PlaybackAuthorization interface, outlining its properties: authorizedFormats and sabrLicenseConstraint. ```APIDOC ## Interface: PlaybackAuthorization ### Description Defines properties related to playback authorization. ### Properties #### authorizedFormats - **authorizedFormats** (`AuthorizedFormat`[]): An array of authorized formats for playback. #### sabrLicenseConstraint - **sabrLicenseConstraint** (`Uint8Array` | `ArrayBufferLike`): An optional SABR license constraint. ``` -------------------------------- ### setUstreamerConfig() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Sets the Ustreamer configuration string. This configuration is used for Ustreamer-specific settings. ```APIDOC ## setUstreamerConfig() ### Description Sets the Ustreamer configuration string. ### Method `setUstreamerConfig` ### Parameters #### config - **config** (string) - Required - The Ustreamer configuration. ### Returns `void` ``` -------------------------------- ### setInitSegment() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/CacheManager.md Stores an initialized segment in the cache with the given key and data. ```APIDOC ## setInitSegment ### Description Stores an initialized segment in the cache. ### Parameters #### key - **key** (string) - Required - The key for the initialized segment. #### data - **data** (Uint8Array) - Required - The data of the initialized segment. ### Returns - `void` ``` -------------------------------- ### videoQuality Option Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/interfaces/SabrPlaybackOptions.md Allows specifying the preferred video quality for Sabr streams. This option is optional and can be set to various quality strings. ```APIDOC ## videoQuality ### Description Preferred video quality (e.g., "1080p", "720p"). ### Type `string` ### Optional `true` ### Defined in `src/types/sabrStreamTypes.ts:64` ``` -------------------------------- ### RequestSegment Interface Methods Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/interfaces/RequestSegment.md This snippet details the methods available on the RequestSegment interface. ```APIDOC ## Interface: RequestSegment ### Description Represents a segment of a request, providing methods to access its properties. ### Methods #### getStartTime() - **Description**: Retrieves the start time of the segment. - **Returns**: `null` or `number` - The start time if available, otherwise null. #### isInit() - **Description**: Checks if the segment has been initialized. - **Returns**: `boolean` - True if the segment is initialized, false otherwise. ``` -------------------------------- ### on() - reloadPlayerResponse Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Fired when the server directs the client to reload the player, usually indicating the current session is invalid. ```APIDOC ## on() - reloadPlayerResponse ### Description Fired when the server directs the client to reload the player, usually indicating the current session is invalid. ### Method `on` ### Parameters #### event - **event** (`"reloadPlayerResponse"`) - Required - The event name. #### listener - **listener** (`reloadPlaybackContext`) => `void` - Required - The callback function. ### Returns `void` ``` -------------------------------- ### setServerAbrFormats() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Sets the available server Adaptive Bitrate (ABR) formats. This is an array of SabrFormat objects. ```APIDOC ## setServerAbrFormats() ### Description Sets the available server ABR formats. ### Method `setServerAbrFormats` ### Parameters #### formats - **formats** (SabrFormat[]) - Required - An array of available SabrFormat objects. ### Returns `void` ``` -------------------------------- ### once(event, listener) Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-stream/classes/SabrStream.md Attaches a one-time event listener that will be invoked only the next time the event is fired. ```APIDOC ## once(event, listener) ### Description Attaches a one-time event listener that will be invoked only the next time the event is fired. ### Method POST (conceptual) ### Parameters #### Path Parameters - **event** (string) - Required - The name of the event to listen for. - **listener** ((...args) => void) - Required - The callback function to execute when the event is fired. ### Returns `void` ### Overrides `EventEmitterLike.once` ### Supported Events - `"formatInitialization"` - `"streamProtectionStatusUpdate"` - `"reloadPlayerResponse"` - `"finish"` - `"abort"` ``` -------------------------------- ### getActiveTrackFormats() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/interfaces/SabrPlayerAdapter.md Determines the active audio and video track formats based on the current active format and available SABR formats. ```APIDOC ## getActiveTrackFormats() ### Description Determines the active audio and video track formats based on the current active format and available SABR formats. ### Method getActiveTrackFormats ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **activeFormat** ([`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md)) - Required - The currently active format. * **sabrFormats** ([`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md)[]) - Required - An array of available SABR formats. ### Request Example ```json { "activeFormat": { "bitrate": 1000000, "codecs": "avc1.640028", "width": 1920, "height": 1080, "frameRate": 30 }, "sabrFormats": [ { "bitrate": 1000000, "codecs": "avc1.640028", "width": 1920, "height": 1080, "frameRate": 30 }, { "bitrate": 500000, "codecs": "avc1.4d401e", "width": 1280, "height": 720, "frameRate": 30 } ] } ``` ### Response #### Success Response (object) * **audioFormat?** (`optional` [`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md)) - The active audio format, if available. * **videoFormat?** (`optional` [`SabrFormat`](../../../types/shared/interfaces/SabrFormat.md)) - The active video format, if available. #### Response Example ```json { "audioFormat": { "bitrate": 128000, "codecs": "mp4a.40.2" }, "videoFormat": { "bitrate": 1000000, "codecs": "avc1.640028", "width": 1920, "height": 1080, "frameRate": 30 } } ``` ``` -------------------------------- ### PlayerHttpResponse Interface Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/interfaces/PlayerHttpResponse.md This interface represents the structure of an HTTP response from a player. It includes properties for the response data, headers, the HTTP method used, and the URL. It also provides a `makeRequest` method to facilitate creating new requests based on this response. ```APIDOC ## Interface: PlayerHttpResponse ### Description Represents an HTTP response from a player, containing response details and a method to create new requests. ### Properties - **url** (string) - The URL of the response. - **method** (string) - The HTTP method used for the request. - **headers** (Record) - An object containing the response headers. - **data?** (ArrayBuffer | ArrayBufferView) - Optional. The response body data, which can be an ArrayBuffer or an ArrayBufferView. ### Methods #### makeRequest(url, headers) - **Description**: Creates a new request based on the current response. This is useful for following redirects or making subsequent requests. - **Parameters**: - **url** (string) - The URL for the new request. - **headers** (Record) - The headers to include in the new request. - **Returns**: A Promise that resolves to an object omitting the `makeRequest` method itself, representing the response of the new request. ``` -------------------------------- ### createSegmentCacheKey() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/namespaces/FormatKeyUtils/functions/createSegmentCacheKey.md Creates a segment cache key using media header and optional format information. ```APIDOC ## Function: createSegmentCacheKey() > **createSegmentCacheKey**(`mediaHeader`, `format?`): `string` Defined in: [codeberg/googlevideo/src/utils/formatKeyUtils.ts:47](https://github.com/LuanRT/googlevideo/blob/19854137cadaf49fd755394883dfd7fe5fdaba20/src/utils/formatKeyUtils.ts#L47) Creates a segment cache key. ## Parameters ### mediaHeader [`MediaHeader`](../../../../protos/interfaces/MediaHeader.md) The MediaHeader object. ### format? [`SabrFormat`](../../../../../types/shared/interfaces/SabrFormat.md) Format object (needed for init segments.) ## Returns `string` A string key for caching segments. ``` -------------------------------- ### getBandwidthEstimate() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/interfaces/SabrPlayerAdapter.md Retrieves the estimated network bandwidth available for streaming. ```APIDOC ## getBandwidthEstimate() ### Description Retrieves the estimated network bandwidth available for streaming. ### Method getBandwidthEstimate ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (number) * **return value** (number) - The estimated bandwidth in bits per second. #### Response Example ```json { "return_value": 5000000 } ``` ``` -------------------------------- ### write() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/ump/classes/UmpWriter.md Writes a part of data to the UMP buffer. This method takes the type of the part and the data as a Uint8Array, serializing it according to the UMP format. ```APIDOC ## write(partType, partData) ### Description Writes a part to the buffer. ### Parameters #### partType - **partType** (number) - Required - The type of the part. #### partData - **partData** (Uint8Array) - Required - The data of the part. ### Returns - **void** ``` -------------------------------- ### u8ToBase64() Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/functions/u8ToBase64.md Converts a Uint8Array to a Base64 string. This is a utility function for data encoding. ```APIDOC ## Function: u8ToBase64() > **u8ToBase64**(`u8`): `string` Converts a Uint8Array to a Base64 string. ### Parameters #### u8 - **u8** (`Uint8Array`) - Required - The byte array to convert. ### Returns - `string` - The Base64 encoded string. ``` -------------------------------- ### createKey Function Signature Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/namespaces/FormatKeyUtils/functions/createKey.md Generates a format key using the provided itag and xtags. The function accepts an optional itag (number) and optional xtags (string), returning a string representation of the format key. ```APIDOC ## Function: createKey() > **createKey**(`itag`, `xtags`): `string` Creates a format key based on itag and xtags. ### Parameters #### itag `undefined` | `number` #### xtags `undefined` | `string` ### Returns `string` A string format key. ``` -------------------------------- ### Method: setServerAbrFormats Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/sabr-streaming-adapter/classes/SabrStreamingAdapter.md Sets the available SABR formats for streaming. This method is used to inform the adapter about the different quality levels or formats available for adaptive streaming. ```APIDOC ## Method: setServerAbrFormats ### Description Sets the available SABR formats for streaming. This method is used to inform the adapter about the different quality levels or formats available for adaptive streaming. ### Parameters #### sabrFormats - **sabrFormats** (SabrFormat[]) - Required - An array of SabrFormat objects representing the available adaptive streaming formats. ### Returns - void ### Throws - SabrAdapterError - if the adapter has been disposed. ``` -------------------------------- ### VideoPlaybackAbrRequest Interface Properties Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/VideoPlaybackAbrRequest.md This snippet details the properties of the VideoPlaybackAbrRequest interface, including their types and whether they are optional. ```APIDOC ## Interface: VideoPlaybackAbrRequest ### Properties #### bufferedRanges - **Type**: `BufferedRange[]` - **Description**: Represents the buffered ranges of the video. #### clientAbrState (optional) - **Type**: `ClientAbrState` - **Description**: Optional client-side Adaptive Bitrate (ABR) state. #### field1000 - **Type**: `UnknownMessage3[]` - **Description**: An array of UnknownMessage3 types. #### field21 (optional) - **Type**: `UnknownMessage2` - **Description**: An optional field of type UnknownMessage2. #### field22 (optional) - **Type**: `number` - **Description**: An optional numeric field. #### field23 (optional) - **Type**: `number` - **Description**: An optional numeric field. #### field6 (optional) - **Type**: `UnknownMessage1` - **Description**: An optional field of type UnknownMessage1. #### playerTimeMs (optional) - **Type**: `number` - **Description**: Optional player time in milliseconds. Used as the 'osts' (Onesie Start Time Seconds) parameter on Onesie requests. #### preferredAudioFormatIds - **Type**: `FormatId[]` - **Description**: An array of preferred audio format IDs. Corresponds to the 'pai' (Preferred Audio Itags) parameter on Onesie requests. #### preferredSubtitleFormatIds - **Type**: `FormatId[]` - **Description**: An array of preferred subtitle format IDs. #### preferredVideoFormatIds - **Type**: `FormatId[]` - **Description**: An array of preferred video format IDs. Corresponds to the 'pvi' (Preferred Video Itags) parameter on Onesie requests. #### selectedFormatIds - **Type**: `FormatId[]` - **Description**: An array of selected format IDs. #### streamerContext (optional) - **Type**: `StreamerContext` - **Description**: Optional streamer context information. ``` -------------------------------- ### PlaybackCookie Interface Properties Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/protos/interfaces/PlaybackCookie.md This snippet details the properties available within the PlaybackCookie interface. ```APIDOC ## Interface: PlaybackCookie ### Description Defines optional properties for storing playback-related information, such as audio and video formats, and resolution settings. ### Properties #### audioFmt - **audioFmt** (`FormatId`) - Optional - Represents the audio format ID. #### field2 - **field2** (`number`) - Optional - A secondary numerical field. #### resolution - **resolution** (`number`) - Optional - Represents the video resolution. Typically set to 999999 when manually set or when the auto-selected resolution is the maximum available. #### videoFmt - **videoFmt** (`FormatId`) - Optional - Represents the video format ID. ``` -------------------------------- ### setLogLevels(...levels) Source: https://github.com/luanrt/googlevideo/blob/main/docs/api/exports/utils/classes/Logger.md Sets the active log levels for the logger. Call with LogLevel.NONE or no arguments to turn off all logging. Use LogLevel.ALL to enable all levels. ```APIDOC ## Method: setLogLevels(...levels) > **setLogLevels**(...`levels`): `void` Sets the active log levels. Call with LogLevel.NONE or no arguments to turn off all logging. Otherwise, specify one or more log levels to be active. Use LogLevel.ALL to enable all log levels. #### Parameters ##### levels ...[`LogLevel`](../enumerations/LogLevel.md)[] #### Returns `void` ```