Optimizing bugs

This commit is contained in:
luochaolun 2024-01-07 08:59:51 +08:00
parent c4735ca994
commit fc32b8b862
6 changed files with 30 additions and 114 deletions

View File

@ -1,14 +1,14 @@
# 微信视频号下载器 # 微信视频号下载器
# 修改自https://github.com/lecepin/WeChatVideoDownloader 修改自https://github.com/lecepin/WeChatVideoDownloader
# 自己实现了“复制视频”、“解密视频”功能,并修改解密下载每次都要选择保存目录的不变之处,改为第一次选择保存目录,之后不用选择保存目录。 # 自己实现了“复制视频”、“解密视频”功能,并修改解密下载每次都要选择保存目录的不变之处,改为第一次选择保存目录,之后不用选择保存目录。
因为ai方面比较菜“复制视频”、“解密视频”点击都没有提示 因为ai方面比较菜“复制视频”、“解密视频”点击都没有提示
# 折腾好几天,终于可以了!运行后网络不通、捕获不了的看过来: 折腾好几天,终于可以了!运行后网络不通、捕获不了的看过来:
# 进入安装目录打开powershell从powershell命令行里运行wechatvideodownloader. exe就可以了。 进入安装目录打开powershell从powershell命令行里运行wechatvideodownloader. exe就可以了。
> 🔥🔥🔥 V2.x版本支持加密视频的下载可到 Release 中下载更新。 > 🔥🔥🔥 V2.x版本支持加密视频的下载可到 Release 中下载更新。

View File

@ -11,68 +11,10 @@ if (process.platform === 'win32') {
process.env.OPENSSL_CONF = CONFIG.OPEN_SSL_CNF_PATH; process.env.OPENSSL_CONF = CONFIG.OPEN_SSL_CNF_PATH;
} }
const WVDS_DEBUG = process.env.WVDS_DEBUG !== undefined; const my_injection_script = `
const injection_html = `
<script type="text/javascript" src="//res.wx.qq.com/t/wx_fed/finder/web/web-finder/res/js/wvds.inject.js"></script>
`;
// setTimeout to allow working in macOS
// in windows: H5ExtTransfer:ok
// in macOS: finderH5ExtTransfer:ok
const injection_script = `
setTimeout(() => {
if (window.wvds !== undefined) return;
${
WVDS_DEBUG
? `
document.body.style.border = "2px solid #0000FF";
let ele_app = document.getElementById("app");
let ele_btn1 = document.createElement("a");
let ele_btn2 = document.createElement("a");
let ele_debug = document.createElement("textarea");
`
: ''
}
function debug_wvds(msg) {
${WVDS_DEBUG ? `ele_debug.value += "\\n" + msg;` : ''}
}
${
WVDS_DEBUG
? `
ele_btn1.style = "position:absolute;top:3px;left:20px;width:80px;height:30px;cursor:pointer;";
ele_btn1.text = "Source";
ele_btn1.onclick = () => {
var source = "<html>";
source += document.getElementsByTagName('html')[0].innerHTML;
source += "</html>";
debug_wvds(source);
};
ele_app.appendChild(ele_btn1);
ele_btn2.style = "position:absolute;top:3px;left:120px;width:80px;height:30px;cursor:pointer;";
ele_btn2.text = "Test";
ele_btn2.onclick = () => {
debug_wvds("Hello WeChatVideo Downloader!");
};
ele_app.appendChild(ele_btn2);
ele_debug.setAttribute("rows", "60");
ele_debug.setAttribute("cols", "60");
ele_debug.style = "position:absolute;top:600px;left:20px;width:600px;height:300px;border:2px solid #FF00FF;";
ele_debug.value = "Debug:\\n";
ele_app.appendChild(ele_debug);
`
: ''
}
let receiver_url = "https://aaaa.com"; let receiver_url = "https://aaaa.com";
function send_response_if_is_video(response) { function send_response_if_is_video(response) {
if (response == undefined) return;
// debug_wvds(JSON.stringify(response));
debug_wvds("send 1: " + response["err_msg"]);
if (!response["err_msg"].includes("H5ExtTransfer:ok")) return;
let value = JSON.parse(response["jsapi_resp"]["resp_json"]); let value = JSON.parse(response["jsapi_resp"]["resp_json"]);
// debug_wvds("send 2: " + JSON.stringify(value)); // debug_wvds("send 2: " + JSON.stringify(value));
if (value["object"] == undefined || value["object"]["object_desc"] == undefined || value["object"]["object_desc"]["media"].length == 0) { if (value["object"] == undefined || value["object"]["object_desc"] == undefined || value["object"]["object_desc"]["media"].length == 0) {
@ -81,7 +23,7 @@ setTimeout(() => {
let media = value["object"]["object_desc"]["media"][0]; let media = value["object"]["object_desc"]["media"][0];
// debug_wvds("send 3: " + JSON.stringify(media)); // debug_wvds("send 3: " + JSON.stringify(media));
let description = value["object"]["object_desc"]["description"].trim(); let description = value["object"]["object_desc"]["description"].trim();
debug_wvds("send x decode key: " + media["decode_key"] + " for " + description);
let video_data = { let video_data = {
"decode_key": media["decode_key"], "decode_key": media["decode_key"],
"url": media["url"]+media["url_token"], "url": media["url"]+media["url_token"],
@ -89,12 +31,13 @@ setTimeout(() => {
"description": description, "description": description,
"uploader": value["object"]["nickname"] "uploader": value["object"]["nickname"]
}; };
fetch(receiver_url, { fetch(receiver_url, {
method: "POST", method: "POST",
mode: "no-cors", mode: "no-cors",
body: JSON.stringify(video_data), body: JSON.stringify(video_data),
}).then((resp) => { }).then((resp) => {
debug_wvds(\`video data for \${video_data["description"]} sent!\`); //alert(\`video data for \${video_data["description"]} sent!\`);
}); });
} }
@ -105,23 +48,18 @@ setTimeout(() => {
let original_callback = arguments[2]; let original_callback = arguments[2];
arguments[2] = async function () { arguments[2] = async function () {
if (arguments.length == 1) { if (arguments.length == 1) {
debug_wvds("wrapper 3: " + JSON.stringify(arguments[0]));
send_response_if_is_video(arguments[0]); send_response_if_is_video(arguments[0]);
} }
return await original_callback.apply(this, arguments); return await original_callback.apply(this, arguments);
} }
debug_wvds("wrapper 1: " + cmdName + ", " + typeof(arguments[1]) + ", " + typeof(arguments[2]));
} else {
debug_wvds("wrapper 2: " + cmdName + ", " + arguments.length + ", " + arguments[1] + ", " + typeof(arguments[2]));
} }
let result = origin.apply(this,arguments); let result = origin.apply(this,arguments);
return result; return result;
} }
} }
window.WeixinJSBridge.invoke = wrapper("WeixinJSBridge.invoke", window.WeixinJSBridge.invoke); window.WeixinJSBridge.invoke = wrapper("WeixinJSBridge.invoke", window.WeixinJSBridge.invoke);
window.wvds = true; window.wvds = true;`;
debug_wvds("Invoke WechatVideoDownloader Service!");
}, 1000);`;
export async function startServer({ win, setProxyErrorCallback = f => f }) { export async function startServer({ win, setProxyErrorCallback = f => f }) {
const port = await getPort(); const port = await getPort();
@ -167,41 +105,13 @@ export async function startServer({ win, setProxyErrorCallback = f => f }) {
as: 'string', as: 'string',
}, },
async (req, res) => { async (req, res) => {
if (req.url.includes('/web/pages/feed')) { if (req.url.includes('/web/pages/feed') || req.url.includes('/web/pages/home')) {
res.string = res.string.replace('</body>', injection_html + '\n</body>'); res.string = res.string.replace('</body>', '\n<script>' + my_injection_script + '</script>\n</body>');
res.statusCode = 200; res.statusCode = 200;
console.log('inject[channels.weixin.qq.com]:', req.url, res.string.length); console.log('inject[channels.weixin.qq.com]:', req.url, res.string.length);
} }
}, },
); );
proxy.intercept(
{
phase: 'response',
hostname: 'res.wx.qq.com',
as: 'string',
},
async (req, res) => {
if (req.url.includes('wvds.inject.js')) {
console.log('inject[res.wx.qq.com]:', req.url, res.string.length);
res.string = injection_script;
res.statusCode = 200;
}
},
);
proxy.intercept(
{
phase: 'response',
hostname: 'res.wx.qq.com',
as: 'string',
},
async (req, res) => {
if (req.url.includes('polyfills.publish')) {
res.string = res.string + '\n' + injection_script;
}
},
);
}); });
} }

View File

@ -1,4 +1,4 @@
import { get } from 'axios'; import {head, get, all, spread} from 'axios';
import {app, dialog, shell} from 'electron'; import {app, dialog, shell} from 'electron';
import semver from 'semver'; import semver from 'semver';
import fs from 'fs'; import fs from 'fs';

View File

@ -63,6 +63,7 @@
"pretty-bytes": "^6.0.0", "pretty-bytes": "^6.0.0",
"react": "^18.1.0", "react": "^18.1.0",
"react-dom": "^18.1.0", "react-dom": "^18.1.0",
"react-hot-toast": "^2.4.1",
"regedit": "5.0.0", "regedit": "5.0.0",
"semver": "^7.3.7", "semver": "^7.3.7",
"xstate": "^4.32.1" "xstate": "^4.32.1"

View File

@ -11,8 +11,9 @@ import {
RedoOutlined, RedoOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import fsm from './fsm'; import fsm from './fsm';
import './App.less'; import './App.less';
import { Toaster } from 'react-hot-toast';
function App() { function App() {
const [state, send] = useMachine(fsm); const [state, send] = useMachine(fsm);
const { captureList, currentUrl, downloadProgress } = state.context; const { captureList, currentUrl, downloadProgress } = state.context;
@ -29,6 +30,7 @@ function App() {
> >
清空 清空
</Button> </Button>
<Toaster/>
<Button <Button
className="App-inited-github" className="App-inited-github"
icon={<GithubOutlined />} icon={<GithubOutlined />}

View File

@ -3,6 +3,7 @@ import { ipcRenderer } from 'electron';
import prettyBytes from 'pretty-bytes'; import prettyBytes from 'pretty-bytes';
import { uniqBy } from 'lodash'; import { uniqBy } from 'lodash';
import { message } from 'antd'; import { message } from 'antd';
import toast from 'react-hot-toast';
export default createMachine( export default createMachine(
{ {
@ -229,7 +230,7 @@ export default createMachine(
url: currentUrl, url: currentUrl,
decodeKey, decodeKey,
description, description,
}).catch(() => {}).finally(() => send('e_关闭')); }).then(() => {toast.success('已复制');}).catch(() => {}).finally(() => send('e_关闭'));
}, },
invoke_选择文件位置: (context, event) => send => { invoke_选择文件位置: (context, event) => send => {
ipcRenderer ipcRenderer
@ -251,9 +252,11 @@ export default createMachine(
description, description,
}) })
.then(({ fullFileName }) => { .then(({ fullFileName }) => {
toast.success('解密完成');
send({ type: 'e_解密完成', fullFileName, currentUrl }); send({ type: 'e_解密完成', fullFileName, currentUrl });
}) })
.catch(() => { .catch(() => {
toast.error('解密失败');
send('e_解密失败'); send('e_解密失败');
}); });
}, },