style: format and refactor code

This commit is contained in:
LuanRT
2022-03-03 02:21:32 -03:00
parent 254588da81
commit 61028a2ab9
5 changed files with 33 additions and 19 deletions

View File

@@ -8,7 +8,8 @@ const UserAgent = require('user-agents');
/**
* Returns a random user agent.
*
* @param {string} type mobile | desktop
* @param {string} type - mobile | desktop
* @returns {object}
*/
function getRandomUserAgent(type) {
switch (type) {
@@ -23,7 +24,8 @@ function getRandomUserAgent(type) {
/**
* Generates an authentication token from a cookies' sid.
*
* @param {string} sid Sid extracted from cookies
* @param {string} sid - Sid extracted from cookies
* @returns {string}
*/
function generateSidAuth(sid) {
const youtube = 'https://www.youtube.com';
@@ -40,9 +42,9 @@ function generateSidAuth(sid) {
/**
* Gets a string between two delimiters.
*
* @param {string} data The data.
* @param {string} start_string Start string.
* @param {string} end_string End string.
* @param {string} data - The data.
* @param {string} start_string - Start string.
* @param {string} end_string - End string.
*/
function getStringBetweenStrings(data, start_string, end_string) {
const regex = new RegExp(`${escapeStringRegexp(start_string)}(.*?)${escapeStringRegexp(end_string)}`, "s");
@@ -58,7 +60,7 @@ function escapeStringRegexp(string) {
* Converts time (h:m:s) to seconds.
*
* @param {string} time
* @returns {string} seconds
* @returns {number} seconds
*/
function timeToSeconds(time) {
let params = time.split(':');
@@ -73,6 +75,7 @@ function timeToSeconds(time) {
* Converts strings in camelCase to snake_case.
*
* @param {string} string The string in camelCase.
* @returns {string}
*/
function camelToSnake(string) {
return string[0].toLowerCase() + string.slice(1, string.length).replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
@@ -83,6 +86,7 @@ function camelToSnake(string) {
*
* @param {string} channel_id
* @param {string} index
* @returns {string}
*/
function encodeNotificationPref(channel_id, index) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
@@ -104,6 +108,7 @@ function encodeNotificationPref(channel_id, index) {
*
* @param {string} channel_id
* @param {string} video_id
* @returns {string}
*/
function encodeMessageParams(channel_id, video_id) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
@@ -126,6 +131,7 @@ function encodeMessageParams(channel_id, video_id) {
* Encodes comment params protobuf.
*
* @param {string} video_id
* @returns {string}
*/
function encodeCommentParams(video_id) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
@@ -144,9 +150,10 @@ function encodeCommentParams(video_id) {
/**
* Encodes search filter protobuf
*
* @param {string} period Period in which a video is uploaded: any | hour | day | week | month | year
* @param {string} duration The duration of a video: any | short | long
* @param {string} order The order of the search results: relevance | rating | age | views
* @param {string} period - Period in which a video is uploaded: any | hour | day | week | month | year
* @param {string} duration - The duration of a video: any | short | long
* @param {string} order - The order of the search results: relevance | rating | age | views
* @returns {string}
*/
function encodeFilter(period, duration, order) {
const youtube_proto = Proto(Fs.readFileSync(`${__dirname}/proto/youtube.proto`));
@@ -171,6 +178,7 @@ function encodeFilter(period, duration, order) {
* Turns the ntoken transform data into a valid json array
*
* @param {string} data
* @returns {string}
*/
function refineNTokenData(data) {
return data