mirror of
https://github.com/LuanRT/googlevideo.git
synced 2026-07-03 09:35:00 +00:00
chore: clean up
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { UMP } from './UMP.js';
|
||||
import { EventEmitterLike, PART, base64ToU8, getFormatKey } from '../utils/index.js';
|
||||
import { ChunkedDataBuffer } from './ChunkedDataBuffer.js';
|
||||
import { EventEmitterLike, PART, QUALITY, base64ToU8, getFormatKey } from '../utils/index.js';
|
||||
|
||||
import { MediaInfo_MediaType } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
import { MediaInfo_MediaType } from '../../protos/generated/video_streaming/media_info.js';
|
||||
import { VideoPlaybackAbrRequest } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
import { MediaHeader } from '../../protos/generated/video_streaming/media_header.js';
|
||||
import { NextRequestPolicy } from '../../protos/generated/video_streaming/next_request_policy.js';
|
||||
@@ -12,11 +13,10 @@ import { StreamProtectionStatus } from '../../protos/generated/video_streaming/s
|
||||
import { PlaybackCookie } from '../../protos/generated/video_streaming/playback_cookie.js';
|
||||
|
||||
import type { FormatId } from '../../protos/generated/misc/common.js';
|
||||
import type { MediaInfo } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
import type { MediaInfo } from '../../protos/generated/video_streaming/media_info.js';
|
||||
import type { FetchFunction, InitializedFormat, InitOptions, MediaArgs, ServerAbrResponse, ServerAbrStreamOptions } from '../utils/types.js';
|
||||
import { ChunkedDataBuffer } from './ChunkedDataBuffer.js';
|
||||
|
||||
const DEFAULT_VIDEO_WIDTH = 720;
|
||||
const DEFAULT_QUALITY = QUALITY.HD720;
|
||||
|
||||
export class ServerAbrStream extends EventEmitterLike {
|
||||
private fetchFunction: FetchFunction;
|
||||
@@ -65,8 +65,8 @@ export class ServerAbrStream extends EventEmitterLike {
|
||||
const mediaInfo: MediaInfo = {
|
||||
lastManualDirection: 0,
|
||||
timeSinceLastManualFormatSelectionMs: 0,
|
||||
quality: videoFormats.length === 1 ? firstVideoFormat?.width : DEFAULT_VIDEO_WIDTH,
|
||||
iea: videoFormats.length === 1 ? firstVideoFormat?.width : DEFAULT_VIDEO_WIDTH,
|
||||
quality: videoFormats.length === 1 ? firstVideoFormat?.width : DEFAULT_QUALITY,
|
||||
iea: videoFormats.length === 1 ? firstVideoFormat?.width : DEFAULT_QUALITY,
|
||||
startTimeMs: 0,
|
||||
visibility: 0,
|
||||
mediaType: MediaInfo_MediaType.MEDIA_TYPE_DEFAULT,
|
||||
@@ -130,7 +130,7 @@ export class ServerAbrStream extends EventEmitterLike {
|
||||
audioFormatIds: audioFormatIds,
|
||||
videoFormatIds: videoFormatIds,
|
||||
videoPlaybackUstreamerConfig: base64ToU8(this.videoPlaybackUstreamerConfig),
|
||||
sc: {
|
||||
streamerContext: {
|
||||
field5: [],
|
||||
field6: [],
|
||||
poToken: this.poToken ? base64ToU8(this.poToken) : undefined,
|
||||
@@ -216,8 +216,29 @@ export class ServerAbrStream extends EventEmitterLike {
|
||||
|
||||
const formatKey = getFormatKey(mediaHeader.formatId);
|
||||
|
||||
const currentFormat = this.formatsByKey.get(formatKey);
|
||||
if (!currentFormat) return;
|
||||
let currentFormat = this.formatsByKey.get(formatKey);
|
||||
if (!currentFormat) {
|
||||
this.initializedFormats.push({
|
||||
formatId: mediaHeader.formatId,
|
||||
formatKey,
|
||||
durationMs: mediaHeader.durationMs,
|
||||
mimeType: undefined,
|
||||
sequenceCount: undefined,
|
||||
sequenceList: [],
|
||||
mediaChunks: [],
|
||||
_state: {
|
||||
formatId: mediaHeader.formatId,
|
||||
startTimeMs: 0,
|
||||
durationMs: 0,
|
||||
field4: 1,
|
||||
sequenceNumber: 0
|
||||
}
|
||||
});
|
||||
|
||||
this.formatsByKey.set(formatKey, this.initializedFormats[this.initializedFormats.length - 1]);
|
||||
|
||||
currentFormat = this.formatsByKey.get(formatKey)!;
|
||||
}
|
||||
|
||||
// FIXME: This is a hacky workaround to prevent duplicate sequences from being added. This should be fixed in the future (preferably by figuring out how to make the server not send duplicates).
|
||||
if (mediaHeader.sequenceNumber !== undefined && this.previousSequences.get(formatKey)?.includes(mediaHeader.sequenceNumber))
|
||||
|
||||
@@ -7,4 +7,15 @@ export { RequestCancellationPolicy } from '../../protos/generated/video_streamin
|
||||
export { SabrError } from '../../protos/generated/video_streaming/sabr_error.js';
|
||||
export { SabrRedirect } from '../../protos/generated/video_streaming/sabr_redirect.js';
|
||||
export { StreamProtectionStatus } from '../../protos/generated/video_streaming/stream_protection_status.js';
|
||||
export { VideoPlaybackAbrRequest } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
export { VideoPlaybackAbrRequest } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
export { OnesieRequest } from '../../protos/generated/video_streaming/onesie_request.js';
|
||||
export { EncryptedRequest } from '../../protos/generated/video_streaming/encrypted_request.js';
|
||||
export { OnesieHeader } from '../../protos/generated/video_streaming/onesie_header.js';
|
||||
export { OnesieHeaderType } from '../../protos/generated/video_streaming/onesie_header_type.js';
|
||||
export { OnesieInnertubeRequest } from '../../protos/generated/video_streaming/onesie_innertube_request.js';
|
||||
export { OnesieInnertubeResponse } from '../../protos/generated/video_streaming/onesie_innertube_response.js';
|
||||
export { MediaInfo } from '../../protos/generated/video_streaming/media_info.js';
|
||||
export { StreamerContext } from '../../protos/generated/video_streaming/streamer_context.js';
|
||||
export { ProxyStatus } from '../../protos/generated/video_streaming/proxy_status.js';
|
||||
export { MediaCapabilities } from '../../protos/generated/video_streaming/media_capabilities.js';
|
||||
export { CryptoParams } from '../../protos/generated/video_streaming/crypto_params.js';
|
||||
@@ -1,19 +1,20 @@
|
||||
import type { FormatId } from '../../protos/generated/misc/common.js';
|
||||
|
||||
export const qualities = {
|
||||
auto: 0,
|
||||
tiny: 144,
|
||||
small: 240,
|
||||
medium: 360,
|
||||
light: 144,
|
||||
large: 480,
|
||||
hd720: 720,
|
||||
hd1080: 1080,
|
||||
hd1440: 1440,
|
||||
hd2160: 2160,
|
||||
hd2880: 2880,
|
||||
highres: 4320
|
||||
};
|
||||
export enum QUALITY {
|
||||
AUTO = 0,
|
||||
TINY = 144,
|
||||
SMALL = 240,
|
||||
MEDIUM = 360,
|
||||
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
||||
LIGHT = 144,
|
||||
LARGE = 480,
|
||||
HD720 = 720,
|
||||
HD1080 = 1080,
|
||||
HD1440 = 1440,
|
||||
HD2160 = 2160,
|
||||
HD2880 = 2880,
|
||||
HIGHRES= 4320
|
||||
}
|
||||
|
||||
export enum PART {
|
||||
ONESIE_HEADER = 10,
|
||||
@@ -55,7 +56,7 @@ export enum PART {
|
||||
PREWARM_CONNECTION = 65
|
||||
}
|
||||
|
||||
export { MediaInfo_MediaType as MediaType } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
export { MediaInfo_MediaType as MediaType } from '../../protos/generated/video_streaming/media_info.js';
|
||||
|
||||
export function u8ToBase64(u8: Uint8Array): string {
|
||||
return btoa(String.fromCharCode.apply(null, Array.from(u8)));
|
||||
|
||||
@@ -3,7 +3,8 @@ import type { SabrError } from '../../protos/generated/video_streaming/sabr_erro
|
||||
import type { SabrRedirect } from '../../protos/generated/video_streaming/sabr_redirect.js';
|
||||
import type { StreamProtectionStatus } from '../../protos/generated/video_streaming/stream_protection_status.js';
|
||||
import type { TimeRange } from '../../protos/generated/video_streaming/time_range.js';
|
||||
import type { Zpa, MediaInfo } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
import type { Zpa } from '../../protos/generated/video_streaming/video_playback_abr_request.js';
|
||||
import type { MediaInfo } from '../../protos/generated/video_streaming/media_info.js';
|
||||
import type { ChunkedDataBuffer } from '../core/index.js';
|
||||
|
||||
export type Part = {
|
||||
|
||||
Reference in New Issue
Block a user