googlevideo

repository·main·Indexed 41 days ago

https://github.com/luanrt/googlevideo

A collection of modules for working with YouTube's proprietary video streaming protocols, specifically UMP (YouTube Media Protocol) and SABR. Version 4.1.1 provides tools for building custom clients, integrating streaming data into media players like Shaka Player, and downloading videos via the SabrStream client. It includes protobuf definitions, UMP reader/writer utilities, and a SABR streaming adapter.

Tokens
45.3K
Snippets
158
Records
242
Agent score
52%

What's inside googlevideo

  1. Integrate YouTube's SABR streaming protocol

    main
    The exports/sabr-streaming-adapter module provides the core classes, types, and utilities necessary to integrate YouTube's SABR (Streaming Adaptive Bitrate) protocol into a media player. It includes components for managing streaming requests, processing UMP (Unified Media Protocol) data, and defining the interfaces required for player-to-adapter communication.
  2. Use the SabrStream client for video downloading

    main

    The exports/sabr-stream module provides the SabrStream class, which serves as a SABR client designed for downloading videos. This module is the primary entry point for interacting with SABR-based video streams within the googlevideo package.

    import { SabrStream } from 'googlevideo/exports/sabr-stream';
  3. Use the exports/ump module for UMP data

    main
    The exports/ump module provides specialized utilities for handling UMP (Unified Media Protocol) data. It is primarily used for reading and writing UMP-formatted data structures through dedicated reader and writer classes, and managing data streams using CompositeBuffer.
  4. Read and write UMP data with UmpReader and UmpWriter

    main

    To interact with UMP data, use the following classes:

    • UmpReader: Used for parsing and reading UMP data.
    • UmpWriter: Used for constructing and writing UMP data.
    • CompositeBuffer: A utility for managing buffers, likely used in conjunction with the reader and writer to handle data streams.
  5. Run the "Onesie" Request example

    main

    To run the "Onesie" request example, build the library, navigate to the specific example directory, install dependencies, and run the main script.

    # Build the library first
    npm run build
    
    # Run the onesie-request example
    cd examples/onesie-request
    npm install
    npx tsx main.ts
  6. Install googlevideo

    main

    You can install the googlevideo package using NPM, JSR/Deno, or directly from GitHub depending on your environment.

    # NPM
    npm install googlevideo
    
    # JSR / Deno
    npx jsr add @luanrt/googlevideo
    deno add jsr:@luanrt/googlevideo
    
    # GitHub
    npm install LuanRT/googlevideo
  7. Run the Downloader example

    main

    To run the downloader example, you must first build the library. Then, navigate to the downloader directory, install dependencies, and execute the main script or the ffmpeg-enabled script.

    # Build the library first
    npm run build
    
    # Run the standard downloader
    cd examples/downloader
    npm install
    npx tsx main.ts
    
    # Run the downloader with ffmpeg support
    npx tsx ffmpeg-example.ts
  8. Run the SABR + Shaka Player Example

    main

    This example demonstrates how to integrate Shaka Player with the SabrStreamingAdapter from the googlevideo library to play YouTube videos.

    To run the local development environment, follow these steps:

    1. Install dependencies using npm.
    2. Start the development server using the dev script.
    3. Access the application via the local URL provided by Vite (typically http://localhost:5173).

    Note: This is a minimal implementation. For a production-ready version with a full UI, DRM support, recommendation systems, and playback persistence, refer to the Kira project.

    npm install
    npm run dev
  9. Initialize the SabrStreamingAdapter

    main

    To use the SabrStreamingAdapter, instantiate it with a SabrOptions object. A playerAdapter (implementing SabrPlayerAdapter) is a required property in the options object. You can also configure caching behavior via enableCaching, maxCacheSizeMB, and maxCacheAgeSeconds.

    import { SabrStreamingAdapter } from './src/core/SabrStreamingAdapter.js';
    
    const adapter = new SabrStreamingAdapter({
      playerAdapter: myPlayerAdapter, // Must implement SabrPlayerAdapter
      enableCaching: true,
      maxCacheSizeMB: 5,
      maxCacheAgeSeconds: 600
    });