From 7635f49191d43ef26d552dc2196497dbfc38b42f Mon Sep 17 00:00:00 2001 From: "luan.lrt4@gmail.com" Date: Wed, 30 Mar 2022 14:33:22 -0300 Subject: [PATCH] chore: add comment reply/action prototbuf messages --- lib/proto/index.js | 43 ++++++++++++++- lib/proto/youtube.proto | 117 +++++++++++++++++++++++++--------------- 2 files changed, 116 insertions(+), 44 deletions(-) diff --git a/lib/proto/index.js b/lib/proto/index.js index 47ab888e..5a1580d3 100644 --- a/lib/proto/index.js +++ b/lib/proto/index.js @@ -69,6 +69,47 @@ function encodeCommentParams(video_id) { return encodeURIComponent(Buffer.from(buf).toString('base64')); } +/** + * Encodes comment reply parameters. + * + * @param {string} comment_id - The id of the comment. + * @param {string} video_id - The id of the video you're commenting on. + * @returns {string} + */ +function encodeCommentReplyParams(comment_id, video_id) { + const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/youtube.proto`)); + + const buf = youtube_proto.CreateCommentReplyParams.encode({ + video_id, comment_id, + params: { unk_num: 0 }, + unk_num: 7 + }); + + return encodeURIComponent(Buffer.from(buf).toString('base64')); +} + +/** + * Encodes comment action parameters (liking, disliking, reporting a comment etc). + * + * @param {string} type - Type of action. + * @param {string} comment_id - The id of the comment. + * @param {string} video_id - The id of the video you're commenting on. + * @param {string} channel_id - The id of the channel. + * @returns {string} + */ +function encodeCommentActionParams(type, comment_id, video_id, channel_id) { + const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/youtube.proto`)); + + const buf = youtube_proto.PeformCommentActionParams.encode({ + type, comment_id, channel_id, video_id, + unk_num: 2, unk_num_1: 0, unk_num_2: 0, + unk_num_3: "0", unk_num_4: 0, + unk_num_5: 12, unk_num_6: 0, + }); + + return encodeURIComponent(Buffer.from(buf).toString('base64')); +} + /** * Encodes notification preferences. * @@ -89,4 +130,4 @@ function encodeNotificationPref(channel_id, index) { return encodeURIComponent(Buffer.from(buf).toString('base64')); } -module.exports = { encodeMessageParams, encodeCommentParams, encodeNotificationPref, encodeSearchFilter }; \ No newline at end of file +module.exports = { encodeMessageParams, encodeCommentParams, encodeCommentReplyParams, encodeCommentActionParams, encodeNotificationPref, encodeSearchFilter }; \ No newline at end of file diff --git a/lib/proto/youtube.proto b/lib/proto/youtube.proto index c8fea572..522e7b30 100644 --- a/lib/proto/youtube.proto +++ b/lib/proto/youtube.proto @@ -1,44 +1,75 @@ -syntax = "proto2"; -package proto; - -message NotificationPreferences { - string channel_id = 1; - message Preference { - int32 index = 1; - } - Preference pref_id = 2; - int32 number_0 = 3; - int32 number_1 = 4; -} - -message LiveMessageParams { - message Params { - message Ids { - string channel_id = 1; - string video_id = 2; - } - Ids ids = 5; - } - Params params = 1; - int32 number_0 = 2; - int32 number_1 = 3; -} - -message CreateCommentParams { - string video_id = 2; - message Params { - int32 index = 1; - } - Params params = 5; - int32 number = 10; -} - -message SearchFilter { - int32 number = 1; - message Filter { - int32 param_0 = 1; - int32 param_1 = 2; - int32 param_2 = 3; - } - Filter filter = 2; +syntax = "proto2"; +package proto; + +message NotificationPreferences { + string channel_id = 1; + message Preference { + int32 index = 1; + } + Preference pref_id = 2; + int32 number_0 = 3; + int32 number_1 = 4; +} + +message LiveMessageParams { + message Params { + message Ids { + string channel_id = 1; + string video_id = 2; + } + Ids ids = 5; + } + Params params = 1; + int32 number_0 = 2; + int32 number_1 = 3; +} + +message CreateCommentParams { + string video_id = 2; + message Params { + int32 index = 1; + } + Params params = 5; + int32 number = 10; +} + +message CreateCommentReplyParams { + string video_id = 2; + string comment_id = 4; + + message UnknownParams { + int32 unk_num = 1; + } + UnknownParams params = 5; + + int32 unk_num = 10; +} + +message PeformCommentActionParams { + int32 type = 1; + int32 unk_num = 2; + + string comment_id = 3; + string video_id = 5; + + int32 unk_num_1 = 6; + int32 unk_num_2 = 7; + + string unk_num_3 = 9; + + int32 unk_num_4 = 10; + int32 unk_num_5 = 21; + + string channel_id = 23; + int32 unk_num_6 = 30; +} + +message SearchFilter { + int32 number = 1; + message Filter { + int32 param_0 = 1; + int32 param_1 = 2; + int32 param_2 = 3; + } + Filter filter = 2; } \ No newline at end of file