js逆向方法api调用(快手、抖音、wx、hnw、xhs)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

135 lines
3.6 KiB

const fs = require('fs');
const url = "https://crawl-files.pontoaplus.com/upload";
//const url = "http://172.18.1.113:8080/upload"
/**
* 视频流解密操作
**/
function I(t, e, decryptor_array) {
for (var r = new Uint8Array(t), n = 0; n < t.byteLength && e + n < decryptor_array.length; n++)
r[n] ^= decryptor_array[n];
return r
}
function toArrayBuffer(buffer) {
const arrayBuffer = new ArrayBuffer(buffer.length);
const view = new Uint8Array(arrayBuffer);
for (let i = 0; i < buffer.length; i++) {
view[i] = buffer[i];
}
return arrayBuffer;
}
/**
*
* 视频下载
**/
async function download(url, decode, decryptor_array){
let response = await fetch(url, {
headers:{
"Cache-Control": "no-cache"
}
});
if(response.status == 200){
let arrayBuffer = await response["arrayBuffer"]();
let m = I(arrayBuffer, 0, decryptor_array); // 进行计算
return m;
}
console.log("下载失败:", decode, ":", url);
return undefined;
}
/**
* 视频上传
**/
async function upload(arrayBuffer, file_name){
const formData = new FormData();
const videoBlob = new Blob([arrayBuffer], { type: 'video/mp4' });
formData.append('file', videoBlob, file_name);
try{
let response = await fetch(url, {
method: 'POST',
body: formData,
timeout: 20000 // 设置超时
});
if(response.status == 200){
let data = await response.text();
return data;
}
console.log("[wx] 视频上传失败")
}catch(e){
console.log("[wx] 视频上传异常", e)
}
return undefined;
}
/**
* 保存文件到本地
**/
function saveUint8ArrayToFile(uint8Array, filePath) {
const buffer = Buffer.from(uint8Array);
fs.writeFile(filePath, buffer, error => {
if (error) {
console.error('Failed to save file:', error);
} else {
console.log('File saved successfully.');
}
});
return filePath;
}
/**
*
* 视频整体处理流程
**/
async function main(local_path, url, decode, decryptor_array){
console.log(url);
let arrayBuffer = await download(url, decode, decryptor_array);
let file_name = decode.concat(".mp4");
let upload_file = arrayBuffer !== undefined ? await upload(arrayBuffer, file_name):undefined;
let filePath = upload_file !== undefined ? upload_file:saveUint8ArrayToFile(arrayBuffer, local_path);
return filePath == undefined ? {"status": 500, "filePath": filePath, "msg": "下载失败"}:
(filePath != local_path ? {"status": 200, "filePath": filePath, "msg": "上传成功"}:{"status": 203, "filePath": filePath, "msg": "上传失败"});
}
async function main1(local_path, buffer, decode, decryptor_array){
let arrayBuffer = toArrayBuffer(buffer);
let file_name = decode.concat(".mp4");
let m = I(arrayBuffer, 0, decryptor_array); // 进行计算
let upload_file = m !== undefined ? await upload(m, file_name):undefined;
let filePath = upload_file !== undefined ? upload_file:saveUint8ArrayToFile(m, local_path);
return filePath == undefined ? {"status": 500, "filePath": filePath, "msg": "视频流传输失败"}:
(filePath != local_path ? {"status": 200, "filePath": filePath, "msg": "上传成功"}:{"status": 203, "filePath": filePath, "msg": "上传失败"});
}
async function main2(local_path, buffer, decode, decryptor_array){
let arrayBuffer = toArrayBuffer(buffer);
let m = I(arrayBuffer, 0, decryptor_array); // 进行计算
return m;
}
module.exports = {main, main1, main2};