mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-25 07:42:11 +00:00
feat: finalize protobuf encoder for comment translations
This commit is contained in:
@@ -96,10 +96,21 @@ class Actions {
|
||||
data.commentText = args.text;
|
||||
break;
|
||||
case 'comment/perform_comment_action':
|
||||
const params = {
|
||||
video_id: args.video_id,
|
||||
comment_id: args.comment_id
|
||||
};
|
||||
|
||||
const target_action = ({
|
||||
like: () => Proto.encodeCommentActionParams(5, args.comment_id, args.video_id),
|
||||
dislike: () => Proto.encodeCommentActionParams(4, args.comment_id, args.video_id),
|
||||
like: () => Proto.encodeCommentActionParams(5, params),
|
||||
dislike: () => Proto.encodeCommentActionParams(4, params),
|
||||
translate: () => {
|
||||
params.text = args.text;
|
||||
params.target_language = args.target_language;
|
||||
return Proto.encodeCommentActionParams(22, params);
|
||||
}
|
||||
})[args.comment_action]();
|
||||
|
||||
data.actions = [ target_action ];
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -142,19 +142,36 @@ class Proto {
|
||||
* @param {string} type
|
||||
* @param {string} comment_id
|
||||
* @param {string} video_id
|
||||
* @param {string} [text]
|
||||
* @param {string} [target_language]
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
static encodeCommentActionParams(type, comment_id, video_id) {
|
||||
const buf = messages.PeformCommentActionParams.encode({
|
||||
type, comment_id, video_id,
|
||||
static encodeCommentActionParams(type, args = {}) {
|
||||
const data = {
|
||||
type,
|
||||
comment_id: args.comment_id,
|
||||
video_id: args.video_id,
|
||||
|
||||
/* Maybe these can be safely removed? */
|
||||
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,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (args.hasOwnProperty('text')) {
|
||||
data.translate_comment_params = {
|
||||
params: {
|
||||
comment: {
|
||||
text: args.text
|
||||
}
|
||||
},
|
||||
comment_id: args.comment_id,
|
||||
target_language: args.target_language
|
||||
}
|
||||
}
|
||||
|
||||
const buf = messages.PeformCommentActionParams.encode(data);
|
||||
return encodeURIComponent(Buffer.from(buf).toString('base64'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user