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

7 months ago
  1. const fs = require('fs');
  2. const url = "https://crawl-files.pontoaplus.com/upload";
  3. //const url = "http://172.18.1.113:8080/upload"
  4. /**
  5. * 视频流解密操作
  6. **/
  7. function I(t, e, decryptor_array) {
  8. for (var r = new Uint8Array(t), n = 0; n < t.byteLength && e + n < decryptor_array.length; n++)
  9. r[n] ^= decryptor_array[n];
  10. return r
  11. }
  12. function toArrayBuffer(buffer) {
  13. const arrayBuffer = new ArrayBuffer(buffer.length);
  14. const view = new Uint8Array(arrayBuffer);
  15. for (let i = 0; i < buffer.length; i++) {
  16. view[i] = buffer[i];
  17. }
  18. return arrayBuffer;
  19. }
  20. /**
  21. *
  22. * 视频下载
  23. **/
  24. async function download(url, decode, decryptor_array){
  25. let response = await fetch(url, {
  26. headers:{
  27. "Cache-Control": "no-cache"
  28. }
  29. });
  30. if(response.status == 200){
  31. let arrayBuffer = await response["arrayBuffer"]();
  32. let m = I(arrayBuffer, 0, decryptor_array); // 进行计算
  33. return m;
  34. }
  35. console.log("下载失败:", decode, ":", url);
  36. return undefined;
  37. }
  38. /**
  39. * 视频上传
  40. **/
  41. async function upload(arrayBuffer, file_name){
  42. const formData = new FormData();
  43. const videoBlob = new Blob([arrayBuffer], { type: 'video/mp4' });
  44. formData.append('file', videoBlob, file_name);
  45. try{
  46. let response = await fetch(url, {
  47. method: 'POST',
  48. body: formData,
  49. timeout: 20000 // 设置超时
  50. });
  51. if(response.status == 200){
  52. let data = await response.text();
  53. return data;
  54. }
  55. console.log("[wx] 视频上传失败")
  56. }catch(e){
  57. console.log("[wx] 视频上传异常", e)
  58. }
  59. return undefined;
  60. }
  61. /**
  62. * 保存文件到本地
  63. **/
  64. function saveUint8ArrayToFile(uint8Array, filePath) {
  65. const buffer = Buffer.from(uint8Array);
  66. fs.writeFile(filePath, buffer, error => {
  67. if (error) {
  68. console.error('Failed to save file:', error);
  69. } else {
  70. console.log('File saved successfully.');
  71. }
  72. });
  73. return filePath;
  74. }
  75. /**
  76. *
  77. * 视频整体处理流程
  78. **/
  79. async function main(local_path, url, decode, decryptor_array){
  80. console.log(url);
  81. let arrayBuffer = await download(url, decode, decryptor_array);
  82. let file_name = decode.concat(".mp4");
  83. let upload_file = arrayBuffer !== undefined ? await upload(arrayBuffer, file_name):undefined;
  84. let filePath = upload_file !== undefined ? upload_file:saveUint8ArrayToFile(arrayBuffer, local_path);
  85. return filePath == undefined ? {"status": 500, "filePath": filePath, "msg": "下载失败"}:
  86. (filePath != local_path ? {"status": 200, "filePath": filePath, "msg": "上传成功"}:{"status": 203, "filePath": filePath, "msg": "上传失败"});
  87. }
  88. async function main1(local_path, buffer, decode, decryptor_array){
  89. let arrayBuffer = toArrayBuffer(buffer);
  90. let file_name = decode.concat(".mp4");
  91. let m = I(arrayBuffer, 0, decryptor_array); // 进行计算
  92. let upload_file = m !== undefined ? await upload(m, file_name):undefined;
  93. let filePath = upload_file !== undefined ? upload_file:saveUint8ArrayToFile(m, local_path);
  94. return filePath == undefined ? {"status": 500, "filePath": filePath, "msg": "视频流传输失败"}:
  95. (filePath != local_path ? {"status": 200, "filePath": filePath, "msg": "上传成功"}:{"status": 203, "filePath": filePath, "msg": "上传失败"});
  96. }
  97. async function main2(local_path, buffer, decode, decryptor_array){
  98. let arrayBuffer = toArrayBuffer(buffer);
  99. let m = I(arrayBuffer, 0, decryptor_array); // 进行计算
  100. return m;
  101. }
  102. module.exports = {main, main1, main2};