mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-03 09:35:05 +00:00
dev: encode with actual an actual protobuf lib instead of hard-coding stuff
This commit is contained in:
55
lib/Utils.js
55
lib/Utils.js
@@ -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 };
|
||||
Reference in New Issue
Block a user