@aidarkezio/main-func
Version:
📦 It has my funcs
312 lines • 12.9 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.youtubedlv3 = exports.youtubedlv2 = exports.youtubedl = void 0;
const cheerio_1 = __importDefault(require("cheerio"));
const got_1 = __importDefault(require("got"));
const utils_js_1 = require("../utils.js");
const types_js_1 = require("./types.js");
const human_readable_1 = require("human-readable");
const toFormat = (0, human_readable_1.sizeFormatter)({
std: 'JEDEC',
decimalPlaces: 2,
keepTrailingZeroes: false,
render: (literal, symbol) => `${literal} ${symbol}B`
});
// TODO: Fix "Refresh to try again. (code 02)", example link have that error: https://youtu.be/JFC3tYYW_UI
// https://github.com/BochilGaming/games-wabot/blob/main/lib/y2mate.js
const servers = ['en163', 'id90', 'en172'];
async function youtubedl(url, server = 'en163') {
types_js_1.YoutubeDownloaderArgsSchema.parse(arguments);
if (!servers.includes(server))
server = servers[0];
const params = {
url: url,
q_auto: 0,
ajax: 1
};
const json = await got_1.default
.post(`https://www.y2mate.com/mates/${server}/analyze/ajax`, {
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
cookie: '_ga=GA1.2.1405332118.1641699259; _gid=GA1.2.70284915.1642387108; _gat_gtag_UA_84863187_23=1',
origin: 'https://www.y2mate.com'
},
form: params
})
.json();
const $ = cheerio_1.default.load(json.result);
const id = (/var k__id = "(.*?)"/.exec($.html()) || ['', ''])[1];
const v_id = (/var k_data_vid = "(.*?)"/.exec($.html()) || ['', ''])[1];
const thumbnail = $('.video-thumbnail > img').attr('src');
const title = $('div.caption > b').text().trim();
const video = {};
const audio = {};
$('#mp4 > table > tbody > tr').each(function () {
var _a, _b, _c;
const el = $(this).find('td');
const _quality = el.eq(0).find('a').text();
const quality = (_c = (_b = (_a = _quality.split('(')) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.toLowerCase();
const fileSizeH = el.eq(1).text();
const fileSize = parseFloat(fileSizeH) * (/MB$/.test(fileSizeH) ? 1000 : 1);
if (!/\.3gp/i.test(_quality)) {
video[quality] = {
quality,
fileSizeH,
fileSize: isNaN(fileSize) ? 0 : fileSize,
download: convert.bind(null, id, v_id, 'mp4', quality.replace(/p/i, ''))
};
}
});
$('#mp3 > table > tbody > tr').each(function () {
var _a, _b, _c, _d;
const el = $(this).find('td');
const _quality = el.eq(0).find('a').text();
const quality = (_d = (_c = (_b = (_a = _quality
.split('(')) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.replace(')', '')) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.toLowerCase();
const fileSizeH = el.eq(1).text();
const fileSize = parseFloat(fileSizeH) * (/MB$/.test(fileSizeH) ? 1000 : 1);
audio[quality] = {
quality,
fileSizeH,
fileSize: isNaN(fileSize) ? 0 : fileSize,
download: convert.bind(null, id, v_id, 'mp3', quality.replace(/kbps/i, ''))
};
});
const res = {
id,
v_id,
thumbnail,
title,
video,
audio
};
return types_js_1.YoutubeDonwloaderSchema.parse(res);
}
exports.youtubedl = youtubedl;
async function youtubedlv2(url) {
types_js_1.YoutubeDownloaderV2ArgsSchema.parse(arguments);
const html = await (0, got_1.default)('https://yt5s.com/en32').text();
const urlAjax = (/k_url_search="(.*?)"/.exec(html) || ['', ''])[1];
const urlConvert = (/k_url_convert="(.*?)"/.exec(html) || ['', ''])[1];
const params = {
q: url,
vt: 'home'
};
const json = await (0, got_1.default)(urlAjax, {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
cookie: '__cflb=04dToSoFRg9oqH9pYF2En9gKJK4fe8D9TcYtUD6tYu; _ga=GA1.2.1350132744.1641709803; _gid=GA1.2.1492233267.1641709803; _gat_gtag_UA_122831834_4=1',
origin: 'https://yt5s.com',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
},
searchParams: new URLSearchParams(Object.entries(params))
}).json();
const video = {};
Object.values(json.links.mp4).forEach(({ k, size }) => {
video[k] = {
quality: k,
fileSizeH: size,
fileSize: parseFloat(size) * (/MB$/.test(size) ? 1000 : 1),
// @ts-ignore
download: convertv2.bind(null, urlConvert, json.vid, 'mp4', k, json.token, parseInt(json.timeExpires), json.fn)
};
});
const audio = {};
Object.values(json.links.mp3).forEach(({ key, size }) => {
audio[key] = {
quality: key,
fileSizeH: size,
fileSize: parseFloat(size) * (/MB$/.test(size) ? 1000 : 1),
// @ts-ignore
download: convertv2.bind(null, urlConvert, json.vid, 'mp3', key.replace(/kbps/i, ''), json.token, parseInt(json.timeExpires), json.fn)
};
});
const res = {
id: json.vid,
title: json.title,
thumbnail: `https://i.ytimg.com/vi/${json.vid}/0.jpg`,
video,
audio
};
return types_js_1.YoutubeDonwloaderSchema.parse(res);
}
exports.youtubedlv2 = youtubedlv2;
async function youtubedlv3(Url) {
types_js_1.YoutubeDownloaderV3ArgsSchema.parse(arguments);
const payload = {
url: Url
};
const { id, meta, thumb, url } = await got_1.default
.post('https://api.onlinevideoconverter.pro/api/convert', {
headers: {
accept: 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
'content-type': 'application/json',
origin: 'https://onlinevideoconverter.pro',
referer: 'https://onlinevideoconverter.pro/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
},
body: JSON.stringify(payload)
}).json();
const video = {};
const audioArray = {};
url.forEach(({ url, info_url, attr, quality, audio, no_audio, filesize, ext }) => {
if (!no_audio && ext === 'mp4') {
video[quality] = {
quality,
fileSizeH: (filesize && toFormat(filesize)) || undefined,
fileSize: filesize,
download: async () => (url || info_url)
};
}
if (audio && !no_audio) {
audioArray[quality] = {
quality,
fileSizeH: (filesize && toFormat(filesize)) || undefined,
fileSize: filesize,
download: async () => (url || info_url)
};
}
});
const res = {
id,
title: meta.title,
thumbnail: thumb,
video,
audio: audioArray
};
return types_js_1.YoutubeDonwloaderV3Schema.parse(res);
}
exports.youtubedlv3 = youtubedlv3;
async function convert(_id, v_id, ftype, fquality) {
const params = {
type: 'youtube',
_id,
v_id,
ajax: '1',
token: '',
ftype,
fquality
};
const json = await (0, got_1.default)('https://www.y2mate.com/mates/convert', {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
cookie: '_ga=GA1.2.1405332118.1641699259; _gid=GA1.2.1117783105.1641699259; MarketGidStorage=%7B%220%22%3A%7B%7D%2C%22C702514%22%3A%7B%22page%22%3A2%2C%22time%22%3A1641701743540%7D%7D; _PN_SBSCRBR_FALLBACK_DENIED=1641701744162',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
},
form: params
}).json();
const $ = cheerio_1.default.load(json.result);
const link = $('a[href]').attr('href');
if (link === 'https://app.y2mate.com/download')
throw new utils_js_1.ScraperError(JSON.stringify({ link, json: json }, null, 2));
return link;
}
function convertv2(url, v_id, ftype, fquality, token, timeExpire, fname) {
return new Promise(async (resolve, reject) => {
const params = {
v_id,
ftype,
fquality,
token,
timeExpire,
client: 'yt5s.com'
};
const resServer = await (0, got_1.default)(url, {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
origin: 'https://yt5s.com',
referer: 'https://yt5s.com/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
'X-Requested-Key': 'de0cfuirtgf67a'
},
form: params
}).json();
const server = resServer.c_server;
if (!server && ftype === 'mp3')
return resolve(server || resServer.d_url || '');
const payload = {
v_id,
ftype,
fquality,
fname,
token,
timeExpire
};
const results = await (0, got_1.default)(`${server}/api/json/convert`, {
method: 'POST',
form: payload
}).json();
if (results.statusCode === 200)
return resolve(results.result);
else if (results.statusCode === 300) {
try {
// @ts-ignore
const WebSocket = (await Promise.resolve().then(() => __importStar(require('ws')))).default;
const Url = new URL(server);
const WSUrl = `${/https/i.test(Url.protocol) ? 'wss:' : 'ws:'}//${Url.host}/sub/${results.jobId}?fname=yt5s.com`;
const ws = new WebSocket(WSUrl, undefined, {
headers: {
'Accept-Encoding': 'gzip, deflate, br',
Host: Url.host,
Origin: 'https://yt5s.com',
'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
}
});
ws.on('message', function incoming(message) {
const msg = JSON.parse(message.toString());
if (msg.action === 'success') {
try {
ws.close();
}
catch (e) {
console.error(e);
}
ws.removeAllListeners('message');
return resolve(msg.url);
}
else if (msg.action === 'error')
return reject(msg);
});
}
catch (e) {
console.error(e);
return reject(e);
}
}
else
return reject(results);
});
}
//# sourceMappingURL=youtube.js.map