dev: encode with actual an actual protobuf lib instead of hard-coding stuff

This commit is contained in:
LuanRT
2021-10-22 04:32:51 -03:00
parent f54993e3b7
commit 27962242b7
4 changed files with 64 additions and 50 deletions

View File

@@ -1,5 +1,7 @@
'use strict';
const Fs = require('fs');
const Proto = require('protons');
const Crypto = require('crypto');
const UserAgent = require('user-agents');
@@ -39,32 +41,43 @@ function createFunction(input, raw_code) { // I hate this
return new Function(input, raw_code);
}
function encodeVideoId(id) {
return encodeURIComponent(`${Buffer.from(` ` + id + `*`).toString('base64').slice(0, -1)}BQBw==`);
function encodeNotificationPref(channel_id, index) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
const codes = ['\b\x02' /* ALL */ , '\b\x03' /* NONE */ , '\b\x03' /* PERSONALIZED */ ];
const buf = youtube_proto.NotificationPreferences.encode({
channel_id: channel_id,
pref_code: codes[index],
number_0: 0,
number_1: 4
});
return encodeURIComponent(Buffer.from(buf).toString('base64'));
}
function encodeChannelId(id, notification_pref) {
const buff_start = `
`;
const buff_end = [
``, // all
``, // none
``, // personalized
];
function generateMessageParams(channel_id, video_id) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
const ids = ["*'", '\n\x18', channel_id, '\x12\v', video_id].join('');
let encodedId = Buffer.from([buff_start, id, buff_end[notification_pref]].join('')).toString('base64');
return encodeURIComponent(`${encodedId}GAAgBA==`);
const buf = youtube_proto.LiveMessageParams.encode({
ids: ids,
number_0: 1,
number_1: 4
});
return Buffer.from(Buffer.from(buf).toString('base64')).toString('base64');
}
function encodeChannelIdWithVideoId(channel_id, video_id) {
const buff_start = `
)*'
`;
const buff_middle = ` `;
const buff_end = ``;
function generateCommentParams(video_id) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
let encodedIds = Buffer.from([buff_start, channel_id, buff_middle, video_id, buff_end].join('')).toString('base64');
return `${Buffer.from(encodedIds).toString('base64').slice(0, -4)}JTNE`;
const buf = youtube_proto.CreateCommentParams.encode({
video_id,
params: '\b\x00',
number: 7
});
return encodeURIComponent(Buffer.from(buf).toString('base64'));
}
module.exports = { getRandomUserAgent, generateSidAuth, getStringBetweenStrings, createFunction, encodeChannelIdWithVideoId, encodeVideoId, encodeChannelId };
module.exports = { getRandomUserAgent, generateSidAuth, getStringBetweenStrings, createFunction, generateMessageParams, generateCommentParams, encodeNotificationPref };