Skip to content

Commit

Permalink
fix(proto): Update Context message
Browse files Browse the repository at this point in the history
Closes #681
  • Loading branch information
LuanRT committed Jul 10, 2024
1 parent 142a7d0 commit 62ac2f6
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,35 @@ import {

export declare namespace $.youtube.InnertubePayload.Context {
export type Client = {
unkparam: number;
deviceMake: string;
deviceModel: string;
nameId: number;
clientVersion: string;
clientName: string;
osName: string;
osVersion: string;
acceptLanguage: string;
acceptRegion: string;
androidSdkVersion: number;
windowWidthPoints: number;
windowHeightPoints: number;
}
}

export type Type = $.youtube.InnertubePayload.Context.Client;

export function getDefaultValue(): $.youtube.InnertubePayload.Context.Client {
return {
unkparam: 0,
deviceMake: "",
deviceModel: "",
nameId: 0,
clientVersion: "",
clientName: "",
osName: "",
osVersion: "",
acceptLanguage: "",
acceptRegion: "",
androidSdkVersion: 0,
windowWidthPoints: 0,
windowHeightPoints: 0,
};
}

Expand All @@ -43,24 +59,52 @@ export function createValue(partialValue: Partial<$.youtube.InnertubePayload.Con

export function encodeJson(value: $.youtube.InnertubePayload.Context.Client): unknown {
const result: any = {};
if (value.unkparam !== undefined) result.unkparam = tsValueToJsonValueFns.int32(value.unkparam);
if (value.deviceMake !== undefined) result.deviceMake = tsValueToJsonValueFns.string(value.deviceMake);
if (value.deviceModel !== undefined) result.deviceModel = tsValueToJsonValueFns.string(value.deviceModel);
if (value.nameId !== undefined) result.nameId = tsValueToJsonValueFns.int32(value.nameId);
if (value.clientVersion !== undefined) result.clientVersion = tsValueToJsonValueFns.string(value.clientVersion);
if (value.clientName !== undefined) result.clientName = tsValueToJsonValueFns.string(value.clientName);
if (value.osName !== undefined) result.osName = tsValueToJsonValueFns.string(value.osName);
if (value.osVersion !== undefined) result.osVersion = tsValueToJsonValueFns.string(value.osVersion);
if (value.acceptLanguage !== undefined) result.acceptLanguage = tsValueToJsonValueFns.string(value.acceptLanguage);
if (value.acceptRegion !== undefined) result.acceptRegion = tsValueToJsonValueFns.string(value.acceptRegion);
if (value.androidSdkVersion !== undefined) result.androidSdkVersion = tsValueToJsonValueFns.int32(value.androidSdkVersion);
if (value.windowWidthPoints !== undefined) result.windowWidthPoints = tsValueToJsonValueFns.int32(value.windowWidthPoints);
if (value.windowHeightPoints !== undefined) result.windowHeightPoints = tsValueToJsonValueFns.int32(value.windowHeightPoints);
return result;
}

export function decodeJson(value: any): $.youtube.InnertubePayload.Context.Client {
const result = getDefaultValue();
if (value.unkparam !== undefined) result.unkparam = jsonValueToTsValueFns.int32(value.unkparam);
if (value.deviceMake !== undefined) result.deviceMake = jsonValueToTsValueFns.string(value.deviceMake);
if (value.deviceModel !== undefined) result.deviceModel = jsonValueToTsValueFns.string(value.deviceModel);
if (value.nameId !== undefined) result.nameId = jsonValueToTsValueFns.int32(value.nameId);
if (value.clientVersion !== undefined) result.clientVersion = jsonValueToTsValueFns.string(value.clientVersion);
if (value.clientName !== undefined) result.clientName = jsonValueToTsValueFns.string(value.clientName);
if (value.osName !== undefined) result.osName = jsonValueToTsValueFns.string(value.osName);
if (value.osVersion !== undefined) result.osVersion = jsonValueToTsValueFns.string(value.osVersion);
if (value.acceptLanguage !== undefined) result.acceptLanguage = jsonValueToTsValueFns.string(value.acceptLanguage);
if (value.acceptRegion !== undefined) result.acceptRegion = jsonValueToTsValueFns.string(value.acceptRegion);
if (value.androidSdkVersion !== undefined) result.androidSdkVersion = jsonValueToTsValueFns.int32(value.androidSdkVersion);
if (value.windowWidthPoints !== undefined) result.windowWidthPoints = jsonValueToTsValueFns.int32(value.windowWidthPoints);
if (value.windowHeightPoints !== undefined) result.windowHeightPoints = jsonValueToTsValueFns.int32(value.windowHeightPoints);
return result;
}

export function encodeBinary(value: $.youtube.InnertubePayload.Context.Client): Uint8Array {
const result: WireMessage = [];
if (value.unkparam !== undefined) {
const tsValue = value.unkparam;
if (value.deviceMake !== undefined) {
const tsValue = value.deviceMake;
result.push(
[12, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.deviceModel !== undefined) {
const tsValue = value.deviceModel;
result.push(
[13, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.nameId !== undefined) {
const tsValue = value.nameId;
result.push(
[16, tsValueToWireValueFns.int32(tsValue)],
);
Expand All @@ -71,25 +115,75 @@ export function encodeBinary(value: $.youtube.InnertubePayload.Context.Client):
[17, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.clientName !== undefined) {
const tsValue = value.clientName;
if (value.osName !== undefined) {
const tsValue = value.osName;
result.push(
[18, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.osVersion !== undefined) {
const tsValue = value.osVersion;
result.push(
[19, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.acceptLanguage !== undefined) {
const tsValue = value.acceptLanguage;
result.push(
[21, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.acceptRegion !== undefined) {
const tsValue = value.acceptRegion;
result.push(
[22, tsValueToWireValueFns.string(tsValue)],
);
}
if (value.androidSdkVersion !== undefined) {
const tsValue = value.androidSdkVersion;
result.push(
[34, tsValueToWireValueFns.int32(tsValue)],
);
}
if (value.windowWidthPoints !== undefined) {
const tsValue = value.windowWidthPoints;
result.push(
[37, tsValueToWireValueFns.int32(tsValue)],
);
}
if (value.windowHeightPoints !== undefined) {
const tsValue = value.windowHeightPoints;
result.push(
[38, tsValueToWireValueFns.int32(tsValue)],
);
}
return serialize(result);
}

export function decodeBinary(binary: Uint8Array): $.youtube.InnertubePayload.Context.Client {
const result = getDefaultValue();
const wireMessage = deserialize(binary);
const wireFields = new Map(wireMessage);
field: {
const wireValue = wireFields.get(12);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.deviceMake = value;
}
field: {
const wireValue = wireFields.get(13);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.deviceModel = value;
}
field: {
const wireValue = wireFields.get(16);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.int32(wireValue);
if (value === undefined) break field;
result.unkparam = value;
result.nameId = value;
}
field: {
const wireValue = wireFields.get(17);
Expand All @@ -103,7 +197,49 @@ export function decodeBinary(binary: Uint8Array): $.youtube.InnertubePayload.Con
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.clientName = value;
result.osName = value;
}
field: {
const wireValue = wireFields.get(19);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.osVersion = value;
}
field: {
const wireValue = wireFields.get(21);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.acceptLanguage = value;
}
field: {
const wireValue = wireFields.get(22);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.acceptRegion = value;
}
field: {
const wireValue = wireFields.get(34);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.int32(wireValue);
if (value === undefined) break field;
result.androidSdkVersion = value;
}
field: {
const wireValue = wireFields.get(37);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.int32(wireValue);
if (value === undefined) break field;
result.windowWidthPoints = value;
}
field: {
const wireValue = wireFields.get(38);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.int32(wireValue);
if (value === undefined) break field;
result.windowHeightPoints = value;
}
return result;
}
31 changes: 24 additions & 7 deletions src/proto/generated/messages/youtube/InnertubePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {
export declare namespace $.youtube {
export type InnertubePayload = {
context?: Context;
target?: string;
videoId?: string;
title?: Title;
description?: Description;
tags?: Tags;
Expand All @@ -100,6 +100,7 @@ export declare namespace $.youtube {
privacy?: Privacy;
madeForKids?: MadeForKids;
ageRestricted?: AgeRestricted;
field83?: number;
}
}

Expand All @@ -108,7 +109,7 @@ export type Type = $.youtube.InnertubePayload;
export function getDefaultValue(): $.youtube.InnertubePayload {
return {
context: undefined,
target: undefined,
videoId: undefined,
title: undefined,
description: undefined,
tags: undefined,
Expand All @@ -118,6 +119,7 @@ export function getDefaultValue(): $.youtube.InnertubePayload {
privacy: undefined,
madeForKids: undefined,
ageRestricted: undefined,
field83: undefined,
};
}

Expand All @@ -131,7 +133,7 @@ export function createValue(partialValue: Partial<$.youtube.InnertubePayload>):
export function encodeJson(value: $.youtube.InnertubePayload): unknown {
const result: any = {};
if (value.context !== undefined) result.context = encodeJson_1(value.context);
if (value.target !== undefined) result.target = tsValueToJsonValueFns.string(value.target);
if (value.videoId !== undefined) result.videoId = tsValueToJsonValueFns.string(value.videoId);
if (value.title !== undefined) result.title = encodeJson_2(value.title);
if (value.description !== undefined) result.description = encodeJson_3(value.description);
if (value.tags !== undefined) result.tags = encodeJson_4(value.tags);
Expand All @@ -141,13 +143,14 @@ export function encodeJson(value: $.youtube.InnertubePayload): unknown {
if (value.privacy !== undefined) result.privacy = encodeJson_8(value.privacy);
if (value.madeForKids !== undefined) result.madeForKids = encodeJson_9(value.madeForKids);
if (value.ageRestricted !== undefined) result.ageRestricted = encodeJson_10(value.ageRestricted);
if (value.field83 !== undefined) result.field83 = tsValueToJsonValueFns.int32(value.field83);
return result;
}

export function decodeJson(value: any): $.youtube.InnertubePayload {
const result = getDefaultValue();
if (value.context !== undefined) result.context = decodeJson_1(value.context);
if (value.target !== undefined) result.target = jsonValueToTsValueFns.string(value.target);
if (value.videoId !== undefined) result.videoId = jsonValueToTsValueFns.string(value.videoId);
if (value.title !== undefined) result.title = decodeJson_2(value.title);
if (value.description !== undefined) result.description = decodeJson_3(value.description);
if (value.tags !== undefined) result.tags = decodeJson_4(value.tags);
Expand All @@ -157,6 +160,7 @@ export function decodeJson(value: any): $.youtube.InnertubePayload {
if (value.privacy !== undefined) result.privacy = decodeJson_8(value.privacy);
if (value.madeForKids !== undefined) result.madeForKids = decodeJson_9(value.madeForKids);
if (value.ageRestricted !== undefined) result.ageRestricted = decodeJson_10(value.ageRestricted);
if (value.field83 !== undefined) result.field83 = jsonValueToTsValueFns.int32(value.field83);
return result;
}

Expand All @@ -168,8 +172,8 @@ export function encodeBinary(value: $.youtube.InnertubePayload): Uint8Array {
[1, { type: WireType.LengthDelimited as const, value: encodeBinary_1(tsValue) }],
);
}
if (value.target !== undefined) {
const tsValue = value.target;
if (value.videoId !== undefined) {
const tsValue = value.videoId;
result.push(
[2, tsValueToWireValueFns.string(tsValue)],
);
Expand Down Expand Up @@ -228,6 +232,12 @@ export function encodeBinary(value: $.youtube.InnertubePayload): Uint8Array {
[69, { type: WireType.LengthDelimited as const, value: encodeBinary_10(tsValue) }],
);
}
if (value.field83 !== undefined) {
const tsValue = value.field83;
result.push(
[83, tsValueToWireValueFns.int32(tsValue)],
);
}
return serialize(result);
}

Expand All @@ -247,7 +257,7 @@ export function decodeBinary(binary: Uint8Array): $.youtube.InnertubePayload {
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.string(wireValue);
if (value === undefined) break field;
result.target = value;
result.videoId = value;
}
field: {
const wireValue = wireFields.get(3);
Expand Down Expand Up @@ -312,5 +322,12 @@ export function decodeBinary(binary: Uint8Array): $.youtube.InnertubePayload {
if (value === undefined) break field;
result.ageRestricted = value;
}
field: {
const wireValue = wireFields.get(83);
if (wireValue === undefined) break field;
const value = wireValueToTsValueFns.int32(wireValue);
if (value === undefined) break field;
result.field83 = value;
}
return result;
}
32 changes: 24 additions & 8 deletions src/proto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,20 @@ export function encodeVideoMetadataPayload(video_id: string, metadata: UpdateVid
const data: InnertubePayload.Type = {
context: {
client: {
unkparam: 14,
clientName: CLIENTS.ANDROID.NAME,
clientVersion: CLIENTS.YTSTUDIO_ANDROID.VERSION
nameId: 3,
osName: 'Android',
androidSdkVersion: CLIENTS.ANDROID.SDK_VERSION,
osVersion: '13',
acceptLanguage: 'en-US',
acceptRegion: 'US',
deviceMake: 'Google',
deviceModel: 'sdk_gphone64_x86_64',
windowHeightPoints: 840,
windowWidthPoints: 432,
clientVersion: CLIENTS.ANDROID.VERSION
}
},
target: video_id
videoId: video_id
};

if (Reflect.has(metadata, 'title'))
Expand Down Expand Up @@ -302,12 +310,20 @@ export function encodeCustomThumbnailPayload(video_id: string, bytes: Uint8Array
const data: InnertubePayload.Type = {
context: {
client: {
unkparam: 14,
clientName: CLIENTS.ANDROID.NAME,
clientVersion: CLIENTS.YTSTUDIO_ANDROID.VERSION
nameId: 3,
osName: 'Android',
androidSdkVersion: CLIENTS.ANDROID.SDK_VERSION,
osVersion: '13',
acceptLanguage: 'en-US',
acceptRegion: 'US',
deviceMake: 'Google',
deviceModel: 'sdk_gphone64_x86_64',
windowHeightPoints: 840,
windowWidthPoints: 432,
clientVersion: CLIENTS.ANDROID.VERSION
}
},
target: video_id,
videoId: video_id,
videoThumbnail: {
type: 3,
thumbnail: {
Expand Down
Loading

0 comments on commit 62ac2f6

Please sign in to comment.