googlevideo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +66 -0
  3. package/bundle/index.cjs +7134 -0
  4. package/bundle/index.cjs.map +7 -0
  5. package/dist/protos/generated/misc/common.d.ts +47 -0
  6. package/dist/protos/generated/misc/common.js +365 -0
  7. package/dist/protos/generated/video_streaming/buffered_range.d.ts +50 -0
  8. package/dist/protos/generated/video_streaming/buffered_range.js +403 -0
  9. package/dist/protos/generated/video_streaming/client_abr_state.d.ts +69 -0
  10. package/dist/protos/generated/video_streaming/client_abr_state.js +647 -0
  11. package/dist/protos/generated/video_streaming/crypto_params.d.ts +35 -0
  12. package/dist/protos/generated/video_streaming/crypto_params.js +143 -0
  13. package/dist/protos/generated/video_streaming/encrypted_player_request.d.ts +35 -0
  14. package/dist/protos/generated/video_streaming/encrypted_player_request.js +219 -0
  15. package/dist/protos/generated/video_streaming/format_initialization_metadata.d.ts +35 -0
  16. package/dist/protos/generated/video_streaming/format_initialization_metadata.js +207 -0
  17. package/dist/protos/generated/video_streaming/media_capabilities.d.ts +43 -0
  18. package/dist/protos/generated/video_streaming/media_capabilities.js +315 -0
  19. package/dist/protos/generated/video_streaming/media_header.d.ts +49 -0
  20. package/dist/protos/generated/video_streaming/media_header.js +328 -0
  21. package/dist/protos/generated/video_streaming/next_request_policy.d.ts +30 -0
  22. package/dist/protos/generated/video_streaming/next_request_policy.js +132 -0
  23. package/dist/protos/generated/video_streaming/onesie_header.d.ts +45 -0
  24. package/dist/protos/generated/video_streaming/onesie_header.js +339 -0
  25. package/dist/protos/generated/video_streaming/onesie_header_type.d.ts +32 -0
  26. package/dist/protos/generated/video_streaming/onesie_header_type.js +182 -0
  27. package/dist/protos/generated/video_streaming/onesie_player_request.d.ts +31 -0
  28. package/dist/protos/generated/video_streaming/onesie_player_request.js +122 -0
  29. package/dist/protos/generated/video_streaming/onesie_player_response.d.ts +29 -0
  30. package/dist/protos/generated/video_streaming/onesie_player_response.js +121 -0
  31. package/dist/protos/generated/video_streaming/onesie_request.d.ts +36 -0
  32. package/dist/protos/generated/video_streaming/onesie_request.js +199 -0
  33. package/dist/protos/generated/video_streaming/playback_cookie.d.ts +30 -0
  34. package/dist/protos/generated/video_streaming/playback_cookie.js +110 -0
  35. package/dist/protos/generated/video_streaming/playback_start_policy.d.ts +31 -0
  36. package/dist/protos/generated/video_streaming/playback_start_policy.js +155 -0
  37. package/dist/protos/generated/video_streaming/proxy_status.d.ts +16 -0
  38. package/dist/protos/generated/video_streaming/proxy_status.js +86 -0
  39. package/dist/protos/generated/video_streaming/request_cancellation_policy.d.ts +33 -0
  40. package/dist/protos/generated/video_streaming/request_cancellation_policy.js +173 -0
  41. package/dist/protos/generated/video_streaming/sabr_error.d.ts +26 -0
  42. package/dist/protos/generated/video_streaming/sabr_error.js +77 -0
  43. package/dist/protos/generated/video_streaming/sabr_redirect.d.ts +25 -0
  44. package/dist/protos/generated/video_streaming/sabr_redirect.js +61 -0
  45. package/dist/protos/generated/video_streaming/stream_protection_status.d.ts +26 -0
  46. package/dist/protos/generated/video_streaming/stream_protection_status.js +77 -0
  47. package/dist/protos/generated/video_streaming/streamer_context.d.ts +89 -0
  48. package/dist/protos/generated/video_streaming/streamer_context.js +915 -0
  49. package/dist/protos/generated/video_streaming/time_range.d.ts +27 -0
  50. package/dist/protos/generated/video_streaming/time_range.js +101 -0
  51. package/dist/protos/generated/video_streaming/video_playback_abr_request.d.ts +69 -0
  52. package/dist/protos/generated/video_streaming/video_playback_abr_request.js +659 -0
  53. package/dist/src/core/ChunkedDataBuffer.d.ts +20 -0
  54. package/dist/src/core/ChunkedDataBuffer.js +82 -0
  55. package/dist/src/core/ServerAbrStream.d.ts +38 -0
  56. package/dist/src/core/ServerAbrStream.js +272 -0
  57. package/dist/src/core/UMP.d.ts +10 -0
  58. package/dist/src/core/UMP.js +110 -0
  59. package/dist/src/core/index.d.ts +3 -0
  60. package/dist/src/core/index.js +3 -0
  61. package/dist/src/index.d.ts +4 -0
  62. package/dist/src/index.js +4 -0
  63. package/dist/src/utils/EventEmitterLike.d.ts +8 -0
  64. package/dist/src/utils/EventEmitterLike.js +50 -0
  65. package/dist/src/utils/Protos.d.ts +23 -0
  66. package/dist/src/utils/Protos.js +23 -0
  67. package/dist/src/utils/helpers.d.ts +63 -0
  68. package/dist/src/utils/helpers.js +101 -0
  69. package/dist/src/utils/index.d.ts +4 -0
  70. package/dist/src/utils/index.js +3 -0
  71. package/dist/src/utils/types.d.ts +65 -0
  72. package/dist/src/utils/types.js +1 -0
  73. package/package.json +61 -0
@@ -0,0 +1,63 @@
1
+ import type { FormatId } from '../../protos/generated/misc/common.js';
2
+ export declare enum QUALITY {
3
+ AUTO = 0,
4
+ TINY = 144,
5
+ SMALL = 240,
6
+ MEDIUM = 360,
7
+ LIGHT = 144,
8
+ LARGE = 480,
9
+ HD720 = 720,
10
+ HD1080 = 1080,
11
+ HD1440 = 1440,
12
+ HD2160 = 2160,
13
+ HD2880 = 2880,
14
+ HIGHRES = 4320
15
+ }
16
+ export declare enum PART {
17
+ ONESIE_HEADER = 10,
18
+ ONESIE_DATA = 11,
19
+ MEDIA_HEADER = 20,
20
+ MEDIA = 21,
21
+ MEDIA_END = 22,
22
+ LIVE_METADATA = 31,
23
+ HOSTNAME_CHANGE_HINT = 32,
24
+ LIVE_METADATA_PROMISE = 33,
25
+ LIVE_METADATA_PROMISE_CANCELLATION = 34,
26
+ NEXT_REQUEST_POLICY = 35,
27
+ USTREAMER_VIDEO_AND_FORMAT_DATA = 36,
28
+ FORMAT_SELECTION_CONFIG = 37,
29
+ USTREAMER_SELECTED_MEDIA_STREAM = 38,
30
+ FORMAT_INITIALIZATION_METADATA = 42,
31
+ SABR_REDIRECT = 43,
32
+ SABR_ERROR = 44,
33
+ SABR_SEEK = 45,
34
+ RELOAD_PLAYER_RESPONSE = 46,
35
+ PLAYBACK_START_POLICY = 47,
36
+ ALLOWED_CACHED_FORMATS = 48,
37
+ START_BW_SAMPLING_HINT = 49,
38
+ PAUSE_BW_SAMPLING_HINT = 50,
39
+ SELECTABLE_FORMATS = 51,
40
+ REQUEST_IDENTIFIER = 52,
41
+ REQUEST_CANCELLATION_POLICY = 53,
42
+ ONESIE_PREFETCH_REJECTION = 54,
43
+ TIMELINE_CONTEXT = 55,
44
+ REQUEST_PIPELINING = 56,
45
+ SABR_CONTEXT_UPDATE = 57,
46
+ STREAM_PROTECTION_STATUS = 58,
47
+ SABR_CONTEXT_SENDING_POLICY = 59,
48
+ LAWNMOWER_POLICY = 60,
49
+ SABR_ACK = 61,
50
+ END_OF_TRACK = 62,
51
+ CACHE_LOAD_POLICY = 63,
52
+ LAWNMOWER_MESSAGING_POLICY = 64,
53
+ PREWARM_CONNECTION = 65
54
+ }
55
+ export declare function u8ToBase64(u8: Uint8Array): string;
56
+ export declare function base64ToU8(base64: string): Uint8Array;
57
+ export declare function getFormatKey(formatId: FormatId): string;
58
+ export declare function concatenateChunks(chunks: Uint8Array[]): Uint8Array;
59
+ export declare class CustomEvent extends Event {
60
+ #private;
61
+ constructor(type: string, options?: CustomEventInit<any[]>);
62
+ get detail(): any[] | null;
63
+ }
@@ -0,0 +1,101 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CustomEvent_detail;
13
+ export var QUALITY;
14
+ (function (QUALITY) {
15
+ QUALITY[QUALITY["AUTO"] = 0] = "AUTO";
16
+ QUALITY[QUALITY["TINY"] = 144] = "TINY";
17
+ QUALITY[QUALITY["SMALL"] = 240] = "SMALL";
18
+ QUALITY[QUALITY["MEDIUM"] = 360] = "MEDIUM";
19
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
20
+ QUALITY[QUALITY["LIGHT"] = 144] = "LIGHT";
21
+ QUALITY[QUALITY["LARGE"] = 480] = "LARGE";
22
+ QUALITY[QUALITY["HD720"] = 720] = "HD720";
23
+ QUALITY[QUALITY["HD1080"] = 1080] = "HD1080";
24
+ QUALITY[QUALITY["HD1440"] = 1440] = "HD1440";
25
+ QUALITY[QUALITY["HD2160"] = 2160] = "HD2160";
26
+ QUALITY[QUALITY["HD2880"] = 2880] = "HD2880";
27
+ QUALITY[QUALITY["HIGHRES"] = 4320] = "HIGHRES";
28
+ })(QUALITY || (QUALITY = {}));
29
+ export var PART;
30
+ (function (PART) {
31
+ PART[PART["ONESIE_HEADER"] = 10] = "ONESIE_HEADER";
32
+ PART[PART["ONESIE_DATA"] = 11] = "ONESIE_DATA";
33
+ PART[PART["MEDIA_HEADER"] = 20] = "MEDIA_HEADER";
34
+ PART[PART["MEDIA"] = 21] = "MEDIA";
35
+ PART[PART["MEDIA_END"] = 22] = "MEDIA_END";
36
+ PART[PART["LIVE_METADATA"] = 31] = "LIVE_METADATA";
37
+ PART[PART["HOSTNAME_CHANGE_HINT"] = 32] = "HOSTNAME_CHANGE_HINT";
38
+ PART[PART["LIVE_METADATA_PROMISE"] = 33] = "LIVE_METADATA_PROMISE";
39
+ PART[PART["LIVE_METADATA_PROMISE_CANCELLATION"] = 34] = "LIVE_METADATA_PROMISE_CANCELLATION";
40
+ PART[PART["NEXT_REQUEST_POLICY"] = 35] = "NEXT_REQUEST_POLICY";
41
+ PART[PART["USTREAMER_VIDEO_AND_FORMAT_DATA"] = 36] = "USTREAMER_VIDEO_AND_FORMAT_DATA";
42
+ PART[PART["FORMAT_SELECTION_CONFIG"] = 37] = "FORMAT_SELECTION_CONFIG";
43
+ PART[PART["USTREAMER_SELECTED_MEDIA_STREAM"] = 38] = "USTREAMER_SELECTED_MEDIA_STREAM";
44
+ PART[PART["FORMAT_INITIALIZATION_METADATA"] = 42] = "FORMAT_INITIALIZATION_METADATA";
45
+ PART[PART["SABR_REDIRECT"] = 43] = "SABR_REDIRECT";
46
+ PART[PART["SABR_ERROR"] = 44] = "SABR_ERROR";
47
+ PART[PART["SABR_SEEK"] = 45] = "SABR_SEEK";
48
+ PART[PART["RELOAD_PLAYER_RESPONSE"] = 46] = "RELOAD_PLAYER_RESPONSE";
49
+ PART[PART["PLAYBACK_START_POLICY"] = 47] = "PLAYBACK_START_POLICY";
50
+ PART[PART["ALLOWED_CACHED_FORMATS"] = 48] = "ALLOWED_CACHED_FORMATS";
51
+ PART[PART["START_BW_SAMPLING_HINT"] = 49] = "START_BW_SAMPLING_HINT";
52
+ PART[PART["PAUSE_BW_SAMPLING_HINT"] = 50] = "PAUSE_BW_SAMPLING_HINT";
53
+ PART[PART["SELECTABLE_FORMATS"] = 51] = "SELECTABLE_FORMATS";
54
+ PART[PART["REQUEST_IDENTIFIER"] = 52] = "REQUEST_IDENTIFIER";
55
+ PART[PART["REQUEST_CANCELLATION_POLICY"] = 53] = "REQUEST_CANCELLATION_POLICY";
56
+ PART[PART["ONESIE_PREFETCH_REJECTION"] = 54] = "ONESIE_PREFETCH_REJECTION";
57
+ PART[PART["TIMELINE_CONTEXT"] = 55] = "TIMELINE_CONTEXT";
58
+ PART[PART["REQUEST_PIPELINING"] = 56] = "REQUEST_PIPELINING";
59
+ PART[PART["SABR_CONTEXT_UPDATE"] = 57] = "SABR_CONTEXT_UPDATE";
60
+ PART[PART["STREAM_PROTECTION_STATUS"] = 58] = "STREAM_PROTECTION_STATUS";
61
+ PART[PART["SABR_CONTEXT_SENDING_POLICY"] = 59] = "SABR_CONTEXT_SENDING_POLICY";
62
+ PART[PART["LAWNMOWER_POLICY"] = 60] = "LAWNMOWER_POLICY";
63
+ PART[PART["SABR_ACK"] = 61] = "SABR_ACK";
64
+ PART[PART["END_OF_TRACK"] = 62] = "END_OF_TRACK";
65
+ PART[PART["CACHE_LOAD_POLICY"] = 63] = "CACHE_LOAD_POLICY";
66
+ PART[PART["LAWNMOWER_MESSAGING_POLICY"] = 64] = "LAWNMOWER_MESSAGING_POLICY";
67
+ PART[PART["PREWARM_CONNECTION"] = 65] = "PREWARM_CONNECTION";
68
+ })(PART || (PART = {}));
69
+ export function u8ToBase64(u8) {
70
+ return btoa(String.fromCharCode.apply(null, Array.from(u8)));
71
+ }
72
+ export function base64ToU8(base64) {
73
+ const standard_base64 = base64.replace(/-/g, '+').replace(/_/g, '/');
74
+ const padded_base64 = standard_base64.padEnd(standard_base64.length + (4 - standard_base64.length % 4) % 4, '=');
75
+ return new Uint8Array(atob(padded_base64).split('').map((char) => char.charCodeAt(0)));
76
+ }
77
+ export function getFormatKey(formatId) {
78
+ return `${formatId.itag};${formatId.lastModified};`;
79
+ }
80
+ export function concatenateChunks(chunks) {
81
+ const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
82
+ const result = new Uint8Array(totalLength);
83
+ let offset = 0;
84
+ for (const chunk of chunks) {
85
+ result.set(chunk, offset);
86
+ offset += chunk.length;
87
+ }
88
+ return result;
89
+ }
90
+ // See https://github.com/nodejs/node/issues/40678#issuecomment-1126944677
91
+ export class CustomEvent extends Event {
92
+ constructor(type, options) {
93
+ super(type, options);
94
+ _CustomEvent_detail.set(this, void 0);
95
+ __classPrivateFieldSet(this, _CustomEvent_detail, options?.detail ?? null, "f");
96
+ }
97
+ get detail() {
98
+ return __classPrivateFieldGet(this, _CustomEvent_detail, "f");
99
+ }
100
+ }
101
+ _CustomEvent_detail = new WeakMap();
@@ -0,0 +1,4 @@
1
+ export * from './helpers.js';
2
+ export * from './EventEmitterLike.js';
3
+ export * as Protos from './Protos.js';
4
+ export type * from './types.js';
@@ -0,0 +1,3 @@
1
+ export * from './helpers.js';
2
+ export * from './EventEmitterLike.js';
3
+ export * as Protos from './Protos.js';
@@ -0,0 +1,65 @@
1
+ import type { FormatId } from '../../protos/generated/misc/common.js';
2
+ import type { SabrError } from '../../protos/generated/video_streaming/sabr_error.js';
3
+ import type { SabrRedirect } from '../../protos/generated/video_streaming/sabr_redirect.js';
4
+ import type { StreamProtectionStatus } from '../../protos/generated/video_streaming/stream_protection_status.js';
5
+ import type { TimeRange } from '../../protos/generated/video_streaming/time_range.js';
6
+ import type { BufferedRange } from '../../protos/generated/video_streaming/buffered_range.js';
7
+ import type { ClientAbrState } from '../../protos/generated/video_streaming/client_abr_state.js';
8
+ import type { ChunkedDataBuffer } from '../core/index.js';
9
+ export type Part = {
10
+ type: number;
11
+ size: number;
12
+ data: ChunkedDataBuffer;
13
+ };
14
+ export type ServerAbrStreamOptions = {
15
+ fetch: FetchFunction;
16
+ serverAbrStreamingUrl: string;
17
+ videoPlaybackUstreamerConfig: string;
18
+ poToken?: string;
19
+ durationMs: number;
20
+ };
21
+ export type ServerAbrResponse = {
22
+ initializedFormats: InitializedFormat[];
23
+ streamProtectionStatus?: StreamProtectionStatus;
24
+ sabrRedirect?: SabrRedirect;
25
+ sabrError?: SabrError;
26
+ };
27
+ export type Sequence = {
28
+ itag?: number;
29
+ formatId?: FormatId;
30
+ isInitSegment?: boolean;
31
+ durationMs?: number;
32
+ startMs?: number;
33
+ startDataRange?: number;
34
+ sequenceNumber?: number;
35
+ contentLength?: number;
36
+ timeRange?: TimeRange;
37
+ };
38
+ export type InitializedFormat = {
39
+ formatId: FormatId;
40
+ formatKey: string;
41
+ durationMs?: number;
42
+ mimeType?: string;
43
+ sequenceCount?: number;
44
+ sequenceList: Sequence[];
45
+ mediaChunks: Uint8Array[];
46
+ _state: BufferedRange;
47
+ };
48
+ export type InitOptions = {
49
+ audioFormats: Format[];
50
+ videoFormats: Format[];
51
+ clientAbrState?: ClientAbrState;
52
+ };
53
+ export type MediaArgs = {
54
+ clientAbrState: ClientAbrState;
55
+ audioFormatIds: FormatId[];
56
+ videoFormatIds: FormatId[];
57
+ };
58
+ export type Format = {
59
+ itag: number;
60
+ width?: number;
61
+ height?: number;
62
+ lastModified: string;
63
+ xtags?: string;
64
+ };
65
+ export type FetchFunction = typeof fetch;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "googlevideo",
3
+ "version": "1.0.0",
4
+ "description": "A set of utilities for working with Google Video APIs.",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "types": "./dist/src/index.d.ts",
8
+ "module": "./dist/src/index.js",
9
+ "scripts": {
10
+ "lint": "npx eslint ./src/**/*.ts",
11
+ "lint:fix": "npx eslint --fix ./src/**/*.ts",
12
+ "clean": "npx rimraf ./dist ./bundle ./protos/generated",
13
+ "build": "npm run clean && npm run lint && npm run build:proto && npm run build:esm && npm run bundle:node",
14
+ "build:esm": "npx tsc",
15
+ "build:proto": "node ./dev-scripts/generate-proto.mjs",
16
+ "bundle:node": "npx esbuild ./dist/src/index.js --bundle --outfile=./bundle/index.cjs --platform=node --target=node16 --format=cjs --sourcemap --banner:js=\"/* eslint-disable */\"",
17
+ "prepare": "npm run build"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/LuanRT/GoogleVideo.git"
22
+ },
23
+ "keywords": [
24
+ "UMP",
25
+ "Google",
26
+ "YouTube"
27
+ ],
28
+ "author": "LuanRT <luan.lrt4@gmail.com> (https://github.com/LuanRT)",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/LuanRT/GoogleVideo/issues"
32
+ },
33
+ "homepage": "https://github.com/LuanRT/GoogleVideo#readme",
34
+ "funding": [
35
+ "https://github.com/sponsors/LuanRT"
36
+ ],
37
+ "devDependencies": {
38
+ "@eslint/js": "^9.9.0",
39
+ "@stylistic/eslint-plugin": "^2.6.4",
40
+ "@types/eslint__js": "^8.42.3",
41
+ "@types/xmldom": "^0.1.34",
42
+ "eslint": "^9.9.0",
43
+ "globals": "^15.9.0",
44
+ "ts-proto": "^2.2.0",
45
+ "typescript": "^5.5.4",
46
+ "typescript-eslint": "^8.2.0"
47
+ },
48
+ "exports": {
49
+ ".": {
50
+ "types": "./dist/src/index.d.ts",
51
+ "import": "./dist/src/index.js",
52
+ "require": "./bundle/index.cjs"
53
+ }
54
+ },
55
+ "dependencies": {
56
+ "@bufbuild/protobuf": "^2.0.0",
57
+ "dom-parser": "^1.1.5",
58
+ "xmldom": "^0.6.0",
59
+ "youtubei.js": "^10.5.0"
60
+ }
61
+ }