Skip to main content

A set of utilities for working with Google Video APIs.

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
70%
Published
4 months ago (2.0.0)

What Is This?

This is a collection of utilities for working with Google Video APIs, with a primary focus on UMP.

The protobuf definitions were extracted from YouTube's Android and iOS clients, and the UMP parser and buffer manager are based on the implementation currently found on youtube.com.

Usage examples can be found here.

Installation

npm install googlevideo

Basic Usage

import GoogleVideo, { PART, Protos } from 'googlevideo';

const streamingUrl = 'https://abcd--a.googlevideo.com/videoplayback?...';

const response = await fetch(streamingUrl, { method: 'POST' });

const arrayBuffer = await response.arrayBuffer();

const dataBuffer = new GoogleVideo.ChunkedDataBuffer();
dataBuffer.append(new Uint8Array(arrayBuffer));

const googUmp = new GoogleVideo.UMP(dataBuffer);

googUmp.parse((part) => {
  switch (part.type) {
    case PART.MEDIA_HEADER: {
      console.log('[MediaHeader]:', Protos.MediaHeader.decode(part.data.chunks[0]));
      break;
    }
    case PART.MEDIA: {
      const headerId = part.data.getUint8(0);
      const streamData = part.data.split(1).remainingBuffer;
      console.log('[Media]:', `Header ID: ${headerId}`, `length: ${streamData.getLength()}`);
      break;
    }
    case PART.MEDIA_END: {
      const headerId = part.data.getUint8(0);
      console.log('[MediaEnd]:', `Header ID: ${headerId}`);
      break;
    }
    default:
      console.log('Unhandled part:', part.type);
      break;
  }
});

For more advanced examples, including scenarios beyond just parsing responses, check out the examples.

License

Distributed under the MIT License.

(back to top)

Add Package

deno add jsr:@luanrt/googlevideo

Import symbol

import * as googlevideo from "@luanrt/googlevideo";

---- OR ----

Import directly with a jsr specifier

import * as googlevideo from "jsr:@luanrt/googlevideo";

Add Package

npx jsr add @luanrt/googlevideo

Import symbol

import * as googlevideo from "@luanrt/googlevideo";

Add Package

yarn dlx jsr add @luanrt/googlevideo

Import symbol

import * as googlevideo from "@luanrt/googlevideo";

Add Package

pnpm dlx jsr add @luanrt/googlevideo

Import symbol

import * as googlevideo from "@luanrt/googlevideo";

Add Package

bunx jsr add @luanrt/googlevideo

Import symbol

import * as googlevideo from "@luanrt/googlevideo";