publishport-opencli 1.0.62 → 1.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/clis/douyin/draft.js +82 -30
- package/clis/douyin/publish.js +9 -9
- package/clis/wechat-channels/publish.js +63 -33
- package/clis/xiaohongshu/publish.js +20 -39
- package/dist/src/browser/extract.d.ts +7 -0
- package/dist/src/browser/extract.js +7 -5
- package/dist/src/cli.js +12 -12
- package/package.json +1 -1
- package/skills/opencli-browser/SKILL.md +2 -1
package/clis/douyin/draft.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettings as h}from"./_shared/publish-settings.js";import*as
|
|
1
|
+
import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettings as h}from"./_shared/publish-settings.js";import*as m from"node:fs";import*as s from"node:path";import{cli as A,Strategy as x}from"@jackwener/opencli/registry";import{ArgumentError as c,CommandExecutionError as a}from"@jackwener/opencli/errors";import{setInputFiles as p}from"../_shared/file-inject.js";const b={public:"公开",friends:"好友可见",private:"仅自己可见"},T="https://creator.douyin.com/creator-micro/content/upload",k=120,S=20,g=20,C=60,E=200;async function y(t){await t.evaluate(`() => {
|
|
2
2
|
const targets = ['我知道了', '知道了', '关闭'];
|
|
3
3
|
for (const text of targets) {
|
|
4
4
|
const btn = Array.from(document.querySelectorAll('button,[role="button"]'))
|
|
5
5
|
.find((el) => (el.textContent || '').trim() === text);
|
|
6
6
|
if (btn instanceof HTMLElement) btn.click();
|
|
7
7
|
}
|
|
8
|
-
}`)}async function
|
|
8
|
+
}`)}async function I(t){let e={href:"",ready:!1,bodyText:""};for(let n=0;n<k;n+=1){e=await t.evaluate(`() => ({
|
|
9
9
|
href: location.href,
|
|
10
10
|
ready: !!Array.from(document.querySelectorAll('input')).find(
|
|
11
11
|
(el) => (el.placeholder || '').includes('填写作品标题')
|
|
@@ -13,7 +13,7 @@ import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettin
|
|
|
13
13
|
(el) => (el.textContent || '').includes('暂存离开')
|
|
14
14
|
),
|
|
15
15
|
bodyText: document.body?.innerText || ''
|
|
16
|
-
})`);if(
|
|
16
|
+
})`);if(e.ready)return;await t.wait({time:0.5})}throw new a("等待抖音草稿编辑页超时",`当前页面: ${e.href||"unknown"}`)}async function _(t,e){for(let n=0;n<E;n+=1){const o=await t.evaluate(`() => {
|
|
17
17
|
const text = document.body?.innerText || '';
|
|
18
18
|
const uploading = /上传中|上传\\s*\\d+%|视频上传中|处理中/.test(text);
|
|
19
19
|
const saveBtn = Array.from(document.querySelectorAll('button')).find(
|
|
@@ -24,10 +24,10 @@ import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettin
|
|
|
24
24
|
: false;
|
|
25
25
|
const hasCaptionEditor = !!document.querySelector('[contenteditable="true"]');
|
|
26
26
|
const hasVisibility = !!Array.from(document.querySelectorAll('label')).find(
|
|
27
|
-
(el) => (el.textContent || '').includes(${JSON.stringify(
|
|
27
|
+
(el) => (el.textContent || '').includes(${JSON.stringify(e)})
|
|
28
28
|
);
|
|
29
29
|
return { uploading, saveEnabled, hasSaveBtn: !!saveBtn, hasCaptionEditor, hasVisibility };
|
|
30
|
-
}`);if(
|
|
30
|
+
}`);if(o.hasSaveBtn&&o.saveEnabled&&o.hasCaptionEditor&&o.hasVisibility&&!o.uploading)return;await t.wait({time:0.5})}}async function q(t,e){const n=60;let o=!1;for(let r=0;r<n;r+=1){o=await t.evaluate(`() => {
|
|
31
31
|
const titleInput = Array.from(document.querySelectorAll('input')).find(
|
|
32
32
|
(el) => (el.placeholder || '').includes('填写作品标题')
|
|
33
33
|
);
|
|
@@ -36,12 +36,12 @@ import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettin
|
|
|
36
36
|
const props = propKey ? titleInput[propKey] : null;
|
|
37
37
|
if (props?.onChange) {
|
|
38
38
|
props.onChange({
|
|
39
|
-
target: { value: ${JSON.stringify(
|
|
40
|
-
currentTarget: { value: ${JSON.stringify(
|
|
39
|
+
target: { value: ${JSON.stringify(e.title)} },
|
|
40
|
+
currentTarget: { value: ${JSON.stringify(e.title)} },
|
|
41
41
|
});
|
|
42
42
|
} else {
|
|
43
43
|
titleInput.focus();
|
|
44
|
-
titleInput.value = ${JSON.stringify(
|
|
44
|
+
titleInput.value = ${JSON.stringify(e.title)};
|
|
45
45
|
titleInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
46
46
|
titleInput.dispatchEvent(new Event('change', { bubbles: true }));
|
|
47
47
|
}
|
|
@@ -55,44 +55,96 @@ import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettin
|
|
|
55
55
|
titleInput.dispatchEvent(new Event('blur', { bubbles: true }));
|
|
56
56
|
}
|
|
57
57
|
return true;
|
|
58
|
-
}`);if(
|
|
58
|
+
}`);if(o)break;await t.wait({time:0.5})}if(!o)throw new a("填写抖音草稿表单失败: title-input-missing");if(e.caption){let r=!1;for(let l=0;l<n;l+=1){r=await t.evaluate(`() => {
|
|
59
59
|
const editor = document.querySelector('[contenteditable="true"]');
|
|
60
60
|
if (!(editor instanceof HTMLElement)) return false;
|
|
61
61
|
editor.focus();
|
|
62
62
|
editor.textContent = '';
|
|
63
63
|
document.execCommand('selectAll', false);
|
|
64
|
-
document.execCommand('insertText', false, ${JSON.stringify(
|
|
64
|
+
document.execCommand('insertText', false, ${JSON.stringify(e.caption)});
|
|
65
65
|
editor.dispatchEvent(new Event('input', { bubbles: true }));
|
|
66
66
|
return true;
|
|
67
|
-
}`);if(
|
|
67
|
+
}`);if(r)break;await t.wait({time:0.5})}if(!r)throw new a("填写抖音草稿表单失败: caption-editor-missing")}let i=!1;for(let r=0;r<n;r+=1){i=await t.evaluate(`() => {
|
|
68
68
|
const visibility = Array.from(document.querySelectorAll('label')).find(
|
|
69
|
-
(el) => (el.textContent || '').includes(${JSON.stringify(
|
|
69
|
+
(el) => (el.textContent || '').includes(${JSON.stringify(e.visibilityLabel)})
|
|
70
70
|
);
|
|
71
71
|
if (!(visibility instanceof HTMLElement)) return false;
|
|
72
72
|
visibility.click();
|
|
73
73
|
return true;
|
|
74
|
-
}`);if(
|
|
74
|
+
}`);if(i)break;await t.wait({time:0.5})}if(!i)throw new a("填写抖音草稿表单失败: visibility-missing")}async function L(t){let e="cover-input-missing";const n=await t.evaluate(`() => Array.from(document.querySelectorAll('input[type="file"]')).length`);for(let o=0;o<S;o+=1){const i=await t.evaluate(`() => {
|
|
75
|
+
const visible = (el) => { const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0; };
|
|
76
|
+
const mark = (target) => {
|
|
77
|
+
document
|
|
78
|
+
.querySelectorAll('[data-opencli-cover-input="1"]')
|
|
79
|
+
.forEach((el) => el.removeAttribute('data-opencli-cover-input'));
|
|
80
|
+
target.setAttribute('data-opencli-cover-input', '1');
|
|
81
|
+
return '[data-opencli-cover-input="1"]';
|
|
82
|
+
};
|
|
83
|
+
// 新版页面里仍留着一个不可见的「上传新封面」label,点它不会出新输入框:只认可见的。
|
|
75
84
|
const coverLabel = Array.from(document.querySelectorAll('label')).find(
|
|
76
|
-
(el) => (el.textContent || '').includes('上传新封面')
|
|
85
|
+
(el) => (el.textContent || '').includes('上传新封面') && visible(el)
|
|
77
86
|
);
|
|
78
87
|
if (coverLabel instanceof HTMLElement) {
|
|
79
88
|
coverLabel.click();
|
|
89
|
+
const inputs = Array.from(document.querySelectorAll('input[type="file"]'));
|
|
90
|
+
const target = inputs
|
|
91
|
+
.slice(${JSON.stringify(n)})
|
|
92
|
+
.find((el) => el instanceof HTMLInputElement && !el.disabled);
|
|
93
|
+
if (!(target instanceof HTMLInputElement)) {
|
|
94
|
+
return { ok: false, reason: 'cover-input-pending' };
|
|
95
|
+
}
|
|
96
|
+
return { ok: true, selector: mark(target), mode: 'label' };
|
|
80
97
|
}
|
|
81
98
|
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
return { ok: false, reason: 'cover-
|
|
99
|
+
const modal = Array.from(document.querySelectorAll('.dy-creator-content-modal, [role="dialog"]'))
|
|
100
|
+
.find((el) => visible(el) && (el.textContent || '').includes('上传封面'));
|
|
101
|
+
if (!modal) {
|
|
102
|
+
const slots = Array.from(document.querySelectorAll('[class*="coverControl"]')).filter(visible);
|
|
103
|
+
const slot = slots.find((el) => (el.textContent || '').includes('竖封面')) || slots[0];
|
|
104
|
+
if (!slot) return { ok: false, reason: 'cover-slot-missing' };
|
|
105
|
+
const entry = Array.from(slot.querySelectorAll('div')).find((el) => (el.textContent || '').trim() === '选择封面' && visible(el)) || slot;
|
|
106
|
+
entry.click();
|
|
107
|
+
return { ok: false, reason: 'cover-modal-opening' };
|
|
88
108
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
const zone = Array.from(modal.querySelectorAll('input[type="file"]')).find((el) => {
|
|
110
|
+
if (!(el instanceof HTMLInputElement) || el.disabled || /replace/.test(el.className || '')) return false;
|
|
111
|
+
const box = el.closest('.semi-upload') || el.parentElement;
|
|
112
|
+
return !!box && (box.textContent || '').includes('点击上传');
|
|
113
|
+
});
|
|
114
|
+
if (!(zone instanceof HTMLInputElement)) {
|
|
115
|
+
return { ok: false, reason: 'cover-modal-input-missing' };
|
|
116
|
+
}
|
|
117
|
+
return { ok: true, selector: mark(zone), mode: 'modal' };
|
|
118
|
+
}`);if(i?.ok&&i.selector)return{selector:i.selector,mode:i.mode||"label"};e=i?.reason||e;await t.wait({time:0.5})}throw new a(`准备抖音自定义封面输入框失败: ${e}`)}async function M(t){let e=null;for(let o=0;o<C;o+=1){e=await t.evaluate(`() => {
|
|
119
|
+
const visible = (el) => { const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0; };
|
|
120
|
+
const dialogs = Array.from(document.querySelectorAll('.dy-creator-content-modal, [role="dialog"]')).filter(visible);
|
|
121
|
+
// 点「完成」后若只设了竖封面,会再弹「设置横封面获更多流量」:选「暂不设置」。
|
|
122
|
+
for (const d of dialogs) {
|
|
123
|
+
const skip = Array.from(d.querySelectorAll('button')).find((b) => (b.textContent || '').trim() === '暂不设置' && visible(b));
|
|
124
|
+
if (skip) {
|
|
125
|
+
skip.click();
|
|
126
|
+
return { closed: false, clicked: true, skippedHorizontal: true, text: (d.innerText || '').replace(/\\s+/g, ' ').slice(0, 200) };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const modal = dialogs.find((el) => /设置竖封面|设置横封面|上传封面/.test(el.textContent || ''));
|
|
130
|
+
if (!modal) return { closed: true };
|
|
131
|
+
const text = (modal.innerText || '').replace(/\\s+/g, ' ');
|
|
132
|
+
const uploading = /上传中|检测中|处理中/.test(text);
|
|
133
|
+
// 「上传封面」格子在图片读入后多出一张 data: / blob: 背景缩略图;拖放区文字始终都在,不能作信号。
|
|
134
|
+
// 上传后页面会重建 input(打的标记随之消失),按「上传封面」文字找格子。
|
|
135
|
+
const tiles = Array.from(modal.querySelectorAll('.semi-upload'))
|
|
136
|
+
.map((el) => el.parentElement)
|
|
137
|
+
.filter((el) => el && (el.textContent || '').includes('上传封面'));
|
|
138
|
+
const pending = !tiles.some((tile) => Array.from(tile.querySelectorAll('[style*="background-image"]'))
|
|
139
|
+
.some((el) => /data:|blob:/.test(el.style.backgroundImage || '')));
|
|
140
|
+
const done = Array.from(modal.querySelectorAll('button')).find((b) => (b.textContent || '').trim() === '完成' && visible(b));
|
|
141
|
+
const disabled = !done || done.disabled || done.getAttribute('aria-disabled') === 'true' || /disabled/.test(done.className || '');
|
|
142
|
+
if (uploading || pending || disabled) {
|
|
143
|
+
return { closed: false, clicked: false, uploading, pending, disabled, text: text.slice(0, 200) };
|
|
144
|
+
}
|
|
145
|
+
done.click();
|
|
146
|
+
return { closed: false, clicked: true, text: text.slice(0, 200) };
|
|
147
|
+
}`);if(e?.closed)return;await t.wait({time:e?.clicked?1:0.5})}const n=!e?"unknown":e.clicked?"已点「完成」,弹窗未关闭":e.uploading?"封面仍在上传或检测":e.pending?"「上传封面」格子里没有出现上传的图片":"「完成」按钮不可点击";throw new a(`抖音封面弹窗未完成:${n}`,e?.text?`弹窗文字: ${e.text}`:"unknown")}export function buildCoverCheckPanelTextJs(){return`() => {
|
|
96
148
|
const normalize = (value) => (value || '').replace(/\\s+/g, ' ').trim();
|
|
97
149
|
const stateTexts = ['检测', '检测中', '封面检测中', '重新检测', '横/竖双封面缺失'];
|
|
98
150
|
const marker = Array.from(document.querySelectorAll('div,span,p,button')).find(
|
|
@@ -110,7 +162,7 @@ import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettin
|
|
|
110
162
|
root = root.parentElement;
|
|
111
163
|
}
|
|
112
164
|
return '';
|
|
113
|
-
}`}async function O(t){return await t.evaluate(buildCoverCheckPanelTextJs())||""}async function
|
|
165
|
+
}`}async function O(t){return await t.evaluate(buildCoverCheckPanelTextJs())||""}async function P(t){let e="",n=!1;for(let o=0;o<g;o+=1){const i=await O(t),r=i.includes("检测中"),l=i.includes("重新检测")||i.includes("横/竖双封面缺失");if(r)n=!0;if(n&&l&&!r)return;e=i;await t.wait({time:0.5})}throw new a("等待抖音封面处理完成超时",e||"unknown")}async function B(t){const e=60;let n=null;for(let o=0;o<e;o+=1){n=await t.evaluate(`() => {
|
|
114
166
|
const extractCreationId = () => {
|
|
115
167
|
const titleInput = Array.from(document.querySelectorAll('input')).find(
|
|
116
168
|
(el) => (el.placeholder || '').includes('填写作品标题')
|
|
@@ -160,7 +212,7 @@ import{DOUYIN_VIDEO_ARGS as w,validateDouyinSettings as v,setDouyinPublishSettin
|
|
|
160
212
|
text: (btn.textContent || '').trim(),
|
|
161
213
|
creationId,
|
|
162
214
|
};
|
|
163
|
-
}`);if(
|
|
215
|
+
}`);if(n?.ok)break;await t.wait({time:0.5})}if(!n?.ok)throw new a(`点击草稿按钮失败: ${n?.reason||"unknown"}`);if(!n.creationId)throw new a("点击草稿按钮失败: creation-id-missing");return{text:n.text||"暂存离开",creationId:n.creationId}}async function D(t,e){let n={href:"",bodyText:""};for(let o=0;o<40;o+=1){n=await t.evaluate(`() => ({
|
|
164
216
|
href: location.href,
|
|
165
217
|
bodyText: document.body?.innerText || ''
|
|
166
|
-
})`);const
|
|
218
|
+
})`);const i=n.href||"",r=n.bodyText||"",l=i.includes("/creator-micro/content/upload")&&/继续编辑/.test(r),u=/草稿保存成功|已保存到草稿|存草稿成功|保存成功/.test(r),d=/\/creator-micro\/content\/(manage|drafts|works)/.test(i)||/创作中心/.test(r)&&!i.includes("/content/upload");if(l||u||d)return e;await t.wait({time:1})}throw new a("未检测到抖音草稿保存确认",`当前页面: ${n.href||"unknown"}`)}A({site:"douyin",name:"draft",access:"write",description:"上传视频并保存为草稿",domain:"creator.douyin.com",strategy:x.COOKIE,navigateBefore:!1,defaultWindowMode:"foreground",args:[{name:"video",required:!0,positional:!0,help:"视频文件路径"},{name:"title",required:!0,help:"视频标题(≤30字)"},{name:"caption",fromFile:!0,default:"",help:"正文内容(≤1000字,支持 #话题)"},{name:"cover",default:"",help:"封面图片路径"},{name:"visibility",default:"public",choices:["public","friends","private"]},{name:"timeout",type:"int",default:180,help:"命令超时(秒),视频上传/转码慢时可调大"},{name:"ai-generated",type:"boolean",help:"声明内容由 AI 生成(发布和草稿均支持;设置失败时停止提交)"},...w],columns:["status","draft_id"],func:async(t,e)=>{v(e);const n=s.resolve(e.video);if(!m.existsSync(n))throw new c(`视频文件不存在: ${n}`);const o=s.extname(n).toLowerCase();if(![".mp4",".mov",".avi",".webm"].includes(o))throw new c(`不支持的视频格式: ${o}(支持 mp4/mov/avi/webm)`);const i=e.title;if(i.length>30)throw new c("标题不能超过 30 字");const r=e.caption||"";if(r.length>1000)throw new c("正文不能超过 1000 字");const l=e.cover;if(l){if(!m.existsSync(s.resolve(l)))throw new c(`封面文件不存在: ${s.resolve(l)}`)}const u=b[e.visibility]??b.public;await t.goto(T);await t.wait({selector:'input[type="file"]',timeout:20});await y(t);await p(t,'input[type="file"]',[n]);await I(t);await _(t,u);await y(t);if(l){const f=await L(t);await p(t,f.selector,[s.resolve(l)]);if(f.mode==="modal")await M(t);else await P(t)}await q(t,{title:i,caption:r,visibilityLabel:u});await t.wait({time:1});await h(t,{...e,visibility:void 0});const d=await B(t);return[{status:"✅ 草稿已保存,可在创作中心继续编辑",draft_id:await D(t,d.creationId)}]}});
|
package/clis/douyin/publish.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{DOUYIN_DECLARATION_ARGS as Z,douyinDeclarationInfo as j}from"./_shared/publish-settings.js";import*as T from"node:fs";import*as
|
|
1
|
+
import{DOUYIN_DECLARATION_ARGS as Z,douyinDeclarationInfo as j}from"./_shared/publish-settings.js";import*as T from"node:fs";import*as y from"node:path";import{cli as Q,Strategy as k}from"@jackwener/opencli/registry";import{ArgumentError as l,CliError as ee,CommandExecutionError as w}from"@jackwener/opencli/errors";import{getUploadAuthV5Credentials as te,applyVideoUploadInner as ie,commitVideoUploadInner as oe}from"./_shared/vod-upload.js";import{tosUpload as ne}from"./_shared/tos-upload.js";import{imagexUpload as se}from"./_shared/imagex-upload.js";import{browserFetch as V}from"./_shared/browser-fetch.js";import{generateCreationId as re}from"./_shared/creation-id.js";import{validateTiming as ae,toUnixSeconds as ce}from"./_shared/timing.js";import{parseTextExtra as le,extractHashtagNames as z}from"./_shared/text-extra.js";const de={public:0,friends:2,private:1},me="aid=1128&cookie_enabled=true&screen_width=1512&screen_height=982&browser_language=zh-CN&browser_platform=MacIntel&browser_name=Mozilla&browser_online=true&timezone_name=Asia%2FTokyo&support_h265=1",pe=JSON.stringify({video_cover_source:2,cover_timestamp:0,recommend_timestamp:0,is_cover_edit:0,is_cover_template:0,cover_template_id:"",is_text_template:0,text_template_id:"",text_template_content:"",is_text:0,text_num:0,text_content:"",is_use_sticker:0,sticker_id:"",is_use_filter:0,filter_id:"",is_cover_modify:0,to_status:0,cover_type:0,initial_cover_uri:"",cut_coordinate:""});function _e(i){const e=i instanceof Error?i.message:String(i);return e.includes("post_assistant/fast_detect")&&(e.includes("Empty response")||e.includes("404")||e.includes("Not Found")||e.includes("Timeout")||e.includes("timed out")||e.includes("Failed to fetch"))}function E(i){return new Promise((e)=>setTimeout(e,i))}async function L(i,e,o,n){let c;for(let d=1;d<=3;d+=1)try{return{ok:!0,value:await V(i,e,o,n)}}catch(s){if(!_e(s))throw s;c=s;if(d<3)await E(500*d)}return{ok:!1,error:c}}const A=5;export async function inStage(i,e){try{return await e()}catch(o){if(o instanceof ee)throw o;const n=o instanceof Error?o.message:String(o),c=o?.name==="TimeoutError"?`请求超时(${n})`:n;throw new w(`抖音发布停在「${i}」:${c}`,"这一步在提交发布之前,作品尚未创建,可以直接重试;反复超时多为本机到抖音上传服务的网络慢,可换网络或压缩视频 / 封面后再试。")}}Q({site:"douyin",name:"publish",access:"write",description:"发布视频到抖音(指定 --schedule 定时,或显式 --immediate 立即发布)",domain:"creator.douyin.com",strategy:k.COOKIE,defaultWindowMode:"foreground",args:[{name:"video",required:!0,positional:!0,help:"视频文件路径"},{name:"title",required:!0,help:"视频标题(≤30字)"},{name:"schedule",help:"定时发布时间(ISO8601 或 Unix 秒,2h ~ 14天后),与 --immediate 二选一"},{name:"immediate",type:"boolean",help:"立即发布(必须显式指定,不能与 --schedule 同用)"},{name:"caption",fromFile:!0,default:"",help:"正文内容(≤1000字,支持 #话题)"},{name:"cover",default:"",help:"封面图片路径(不提供时使用视频截帧)"},{name:"visibility",default:"public",choices:["public","friends","private"]},{name:"allow_download",type:"bool",default:!1,help:"允许下载"},{name:"collection",default:"",help:"合集 ID"},{name:"activity",default:"",help:"活动 ID"},{name:"poi_id",default:"",help:"地理位置 ID"},{name:"poi_name",default:"",help:"地理位置名称"},{name:"hotspot",default:"",help:"关联热点词"},{name:"no_safety_check",type:"bool",default:!1,help:"跳过内容安全检测"},{name:"sync_toutiao",type:"bool",default:!1,help:"同步发布到头条"},{name:"ai-generated",type:"boolean",help:"声明内容由 AI 生成(可选,随定时发布请求提交)"},...Z],columns:["status","aweme_id","url","publish_time"],func:async(i,e)=>{const o=j(e);if(!!e.immediate===!!e.schedule)throw new l("必须指定 --schedule 或 --immediate,且只能选择一个");const n=y.resolve(e.video);if(!T.existsSync(n))throw new l(`视频文件不存在: ${n}`);const c=y.extname(n).toLowerCase();if(![".mp4",".mov",".avi",".webm"].includes(c))throw new l(`不支持的视频格式: ${c}(支持 mp4/mov/avi/webm)`);const d=T.statSync(n).size,s=e.title;if(s.length>30)throw new l("标题不能超过 30 字");const a=e.caption||"";if(a.length>1000)throw new l("正文不能超过 1000 字");const U=z(a);if(U.length>A)throw new l(`正文里有 ${U.length} 个 #话题,抖音最多 ${A} 个;删到 ${A} 个以内再发`);const I=e.immediate?0:ce(e.schedule);if(!e.immediate)ae(I);const H=de[e.visibility]??0,g=e.cover;if(g){if(!T.existsSync(y.resolve(g)))throw new l(`封面文件不存在: ${y.resolve(g)}`)}const v=await inStage("获取上传凭证",()=>te(i)),C=await inStage("申请视频上传地址",()=>ie(d,v));let m="",p=720,_=1280;await inStage("上传视频",()=>ne({filePath:n,uploadInfo:C,credentials:v,onProgress:(t,r)=>{const h=Math.round(t/r*100);process.stderr.write(`\r 上传进度: ${h}%`)}}));process.stderr.write(`
|
|
2
2
|
`);process.stderr.write(` 提交上传...
|
|
3
|
-
`);const
|
|
4
|
-
`);
|
|
5
|
-
`);const t=await se(
|
|
6
|
-
`)}if(!e.no_safety_check){const t="https://creator.douyin.com/aweme/v1/post_assistant/fast_detect/pre_check",
|
|
7
|
-
`);const K="https://creator.douyin.com/aweme/v1/post_assistant/fast_detect/poll",X=Date.now()+30000;let M=!1,
|
|
8
|
-
`);else throw new
|
|
3
|
+
`);const u=await inStage("确认视频上传",()=>oe(C,v)),O=u.video_id;process.stderr.write(` 上传已提交: ${O}
|
|
4
|
+
`);p=u.width||p;_=u.height||_;if(!m&&u.poster_uri)m=u.poster_uri;if(e.cover){process.stderr.write(` 上传封面...
|
|
5
|
+
`);const t=await inStage("上传封面",()=>se(y.resolve(e.cover),v));m=t.uri;p=t.width||p;_=t.height||_;process.stderr.write(` 封面已上传: ${m}
|
|
6
|
+
`)}if(!e.no_safety_check){const t="https://creator.douyin.com/aweme/v1/post_assistant/fast_detect/pre_check",r={video_id:O,title:s,desc:a},h=await L(i,"POST",t,{body:r});if(!h.ok)process.stderr.write(` 内容安全预检接口无响应,继续轮询检测结果。
|
|
7
|
+
`);const K="https://creator.douyin.com/aweme/v1/post_assistant/fast_detect/poll",X=Date.now()+30000;let M=!1,S=0;while(Date.now()<X){const R=await L(i,"POST",K,{body:r});if(!R.ok){S+=1;if(!h.ok&&S>=3)break;await E(2000);continue}S=0;const f=R.value;if(f.status===0||f.has_done===!0&&f.detect_result?.reason_code===0&&(f.detect_list?.length??0)===0){M=!0;break}if(f.status===1)throw new w("内容安全检测不通过,请修改后重试","使用 --no_safety_check 跳过");await E(2000)}if(!M)if(!h.ok&&S>=3)process.stderr.write(` 内容安全预检持续无响应,跳过本地预检,交由 create_v2 后的平台审核。
|
|
8
|
+
`);else throw new w("内容安全检测超时(30s),请稍后重试","如确认要跳过本地预检,可使用 --no_safety_check;提交后仍会走抖音平台审核")}const J=z(a),N=[];let D=0;for(const t of J){const r=a.indexOf(`#${t}`,D);if(r===-1)continue;N.push({name:t,id:0,start:r,end:r+t.length+1});D=r+t.length+1}const F=a?`${s} ${a}`:s,P=a?s.length+1:0,B=le(F,N.map((t)=>({...t,start:t.start+P,end:t.end+P}))),q={item:{common:{text:F,caption:a,item_title:s,activity:JSON.stringify(e.activity?[e.activity]:[]),text_extra:JSON.stringify(B),challenges:"[]",mentions:"[]",hashtag_source:"",hot_sentence:e.hotspot||"",interaction_stickers:"[]",visibility_type:H,download:e.allow_download?1:0,timing:I,creation_id:re(),media_type:4,video_id:O,music_source:0,music_id:null,...e.poi_id?{poi_id:e.poi_id,poi_name:e.poi_name}:{}},cover:{poster:m,custom_cover_image_height:_,custom_cover_image_width:p,poster_delay:0,cover_tools_info:pe,cover_tools_extend_info:"{}"},mix:e.collection?{mix_id:e.collection,mix_order:0}:{},chapter:{chapter:JSON.stringify({chapter_abstract:"",chapter_details:[],chapter_type:0})},anchor:{},sync:{should_sync:!1,sync_to_toutiao:e.sync_toutiao?1:0},open_platform:{},assistant:{is_preview:0,is_post_assistant:1},declare:{user_declare_info:o}}},G=`https://creator.douyin.com/web/api/media/aweme/create_v2/?read_aid=2906&${me}`;process.stderr.write(e.immediate?` 创建发布...
|
|
9
9
|
`:` 创建定时发布...
|
|
10
|
-
`);let
|
|
11
|
-
`);return[{status:e.immediate?"✅ 发布请求已提交":"✅ 定时发布成功!",aweme_id:
|
|
10
|
+
`);let b;try{b=await V(i,"POST",G,{body:q})}catch(t){if((t instanceof Error?t.message:String(t)).includes("Failed to fetch"))throw new w("提交发布请求被浏览器侧拦截(疑似字节安全组件 secsdk)","不要直接重试:先用 `ppcli douyin videos` / 创作者中心确认作品是否已创建,避免重复投稿。"+"确认未创建后,用 `--window foreground` 前台窗口重试(视频已上传成功的部分无需重传)。");throw t}const x=b.aweme_id??b.item_id;if(!x)throw new w(`发布成功但未返回 aweme_id/item_id: ${JSON.stringify(b)}`);const W=`https://www.douyin.com/video/${x}`,Y=e.immediate?"立即发布":new Date(I*1000).toLocaleString("zh-CN",{timeZone:"Asia/Shanghai"});if(!e.immediate)process.stderr.write(` 定时稿已创建,到点前作品链接不可访问。核对:ppcli douyin videos --status scheduled(应能看到 ${x} 及计划时间)。
|
|
11
|
+
`);return[{status:e.immediate?"✅ 发布请求已提交":"✅ 定时发布成功!",aweme_id:x,url:W,publish_time:Y}]}});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy as le}from"@jackwener/opencli/registry";import{ArgumentError as f,AuthRequiredError as se,CommandExecutionError as c}from"@jackwener/opencli/errors";import{injectInputFiles as ue}from"../_shared/file-inject.js";const I="https://channels.weixin.qq.com/platform/post/create",ce=[".post-short-title-wrap input",'input[placeholder*="短标题"]','input[placeholder*="填写短标题"]','input.weui-desktop-form__input[placeholder*="短标题"]',"input.weui-desktop-form__input"],de=[".post-desc-box .input-editor",'div[contenteditable][data-placeholder="添加描述"]','div.input-editor[contenteditable=""][data-placeholder="添加描述"]','div[data-placeholder*="描述"][contenteditable]',"div.input-editor[contenteditable]"],fe=["span.add-icon.weui-icon-outlined-add","div.upload-content",".finder-video-upload-btn"],pe=new Set([".mp4",".mov",".avi",".webm"]),me=['.post-upload-wrap input[type="file"]','input[type="file"][accept*="video"]','input[type="file"]'],T="https://channels.weixin.qq.com/platform/post/list",j=/^[\u2103\u4E00-\u9FA5A-Za-z0-9《》""“”::+??%\s]+$/,F=16,L=6;function Q(e){if(!e)return;if(e.length>F)throw new f(`短标题超过 ${F} 字限制(当前 ${e.length} 字)`);if(e.length<L)throw new f(`短标题至少 ${L} 个字(当前 ${e.length} 字)`);if(!j.test(e)){const t=Array.from(new Set(Array.from(e).filter((i)=>!j.test(i)))).join(" ");throw new f(`短标题包含平台不接受的字符: ${t}`,"短标题只能用中文、英文字母、数字、空格,符号仅支持书名号、引号、冒号、加号、问号、百分号、摄氏度;逗号请改用空格")}}function he(e){if(e&&typeof e==="object"&&"data"in e&&"session"in e)return e.data;return e}async function d(e,t){return he(await e.evaluate(t))}function B(e,t,i){const
|
|
1
|
+
import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy as le}from"@jackwener/opencli/registry";import{ArgumentError as f,AuthRequiredError as se,CommandExecutionError as c}from"@jackwener/opencli/errors";import{injectInputFiles as ue}from"../_shared/file-inject.js";const I="https://channels.weixin.qq.com/platform/post/create",ce=[".post-short-title-wrap input",'input[placeholder*="短标题"]','input[placeholder*="填写短标题"]','input.weui-desktop-form__input[placeholder*="短标题"]',"input.weui-desktop-form__input"],de=[".post-desc-box .input-editor",'div[contenteditable][data-placeholder="添加描述"]','div.input-editor[contenteditable=""][data-placeholder="添加描述"]','div[data-placeholder*="描述"][contenteditable]',"div.input-editor[contenteditable]"],fe=["span.add-icon.weui-icon-outlined-add","div.upload-content",".finder-video-upload-btn"],pe=new Set([".mp4",".mov",".avi",".webm"]),me=['.post-upload-wrap input[type="file"]','input[type="file"][accept*="video"]','input[type="file"]'],T="https://channels.weixin.qq.com/platform/post/list",j=/^[\u2103\u4E00-\u9FA5A-Za-z0-9《》""“”::+??%\s]+$/,F=16,L=6;function Q(e){if(!e)return;if(e.length>F)throw new f(`短标题超过 ${F} 字限制(当前 ${e.length} 字)`);if(e.length<L)throw new f(`短标题至少 ${L} 个字(当前 ${e.length} 字)`);if(!j.test(e)){const t=Array.from(new Set(Array.from(e).filter((i)=>!j.test(i)))).join(" ");throw new f(`短标题包含平台不接受的字符: ${t}`,"短标题只能用中文、英文字母、数字、空格,符号仅支持书名号、引号、冒号、加号、问号、百分号、摄氏度;逗号请改用空格")}}function he(e){if(e&&typeof e==="object"&&"data"in e&&"session"in e)return e.data;return e}async function d(e,t){return he(await e.evaluate(t))}function B(e,t,i){const r=C.resolve(String(e));let n;try{n=ae.statSync(r)}catch{throw new f(`${t}文件不存在: ${r}`)}if(!n.isFile())throw new f(`${t}路径不是文件: ${r}`);const a=C.extname(r).toLowerCase();if(!i.has(a))throw new f(`不支持的${t}格式: ${a}(支持 ${Array.from(i).join("/")})`);return r}function G(e){const t=e==null||e===""?600:Number(e);if(!Number.isInteger(t)||t<30)throw new f("--timeout must be an integer >= 30 seconds");return t}function H(e){if(!e)return null;const t=typeof e==="number"?new Date(e<1000000000000?e*1000:e):new Date(String(e));if(Number.isNaN(t.getTime()))throw new f(`无法解析定时时间: ${e}`);if(t.getTime()<=Date.now())throw new f("定时时间必须晚于当前时间");t.setSeconds(0,0);return t}function D(e){return e===!0||e==="true"||e==="1"||e===1}function we(e,t){const i=e-Date.now();if(i<=0)throw new c(`${t}超时,请增加 --timeout 后重试`);return i}function U({isDraft:e,finalUrl:t,successMsg:i}){const r=String(i||"");if(e)return/已保存|暂存成功|保存成功/.test(r);if(/已发表|发布成功|发表成功|审核中/.test(r))return!0;const n=String(t||"");return/\/platform\/post\/list\b/.test(n)}const p=`
|
|
2
2
|
function wujieRoot() {
|
|
3
3
|
var w = document.querySelector('wujie-app');
|
|
4
4
|
return (w && w.shadowRoot) || null;
|
|
@@ -45,7 +45,7 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
45
45
|
}
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
-
`,
|
|
48
|
+
`,O=`
|
|
49
49
|
function vmOf(el) {
|
|
50
50
|
while (el) {
|
|
51
51
|
if (el.__vue__) return el.__vue__;
|
|
@@ -110,7 +110,7 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
110
110
|
titleError: titleErrEl ? (titleErrEl.innerText || titleErrEl.textContent || '').trim() : '',
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
`;async function
|
|
113
|
+
`;async function N(e){return d(e,`(() => { ${p} ${V} ${O} return readFormState(); })()`)}function J(e){if(!e)return{known:!1,seconds:null};const t=e.effectiveTime,i=t===null||typeof t==="number",r=i&&t?t:null,n=e.schedule,a=!!n&&Number.isFinite(n.time);let o=null;if(a&&n.checked&&n.time){const l=Number.isFinite(n.minTime)?Math.max(n.time,n.minTime):n.time;o=Math.floor(l/1000)}if(i&&a&&r!==o)return{known:!0,conflict:!0,seconds:r??o,formSeconds:r,pickerSeconds:o};if(i)return{known:!0,seconds:r};if(a)return{known:!0,seconds:o};return{known:!1,seconds:null}}function _(e){const t=new Date(e*1000),i=(r)=>String(r).padStart(2,"0");return`${t.getFullYear()}-${i(t.getMonth()+1)}-${i(t.getDate())} ${i(t.getHours())}:${i(t.getMinutes())}`}function q(e,{targetSeconds:t,isDraft:i}){if(e?.titleError)return`平台拒绝了短标题: ${e.titleError}`;if(Array.isArray(e?.files)){if(e.files.length===0)return"视频上传失败:上传区是空的,文件没有进入页面的上传队列";if(e.files.some((a)=>a.status==="error"))return"视频上传失败:页面把文件标记为上传出错";const n=e.files.filter((a)=>a.status!=="done");if(n.length)return`视频还没上传完成(状态 ${n.map((a)=>`${a.status||"未知"} ${a.percent}%`).join(", ")})`}const r=J(e);if(r.conflict){const n=(a)=>a?_(a):"不定时";return`表单内部的定时值互相矛盾(表单 ${n(r.formSeconds)} / 时间选择器 ${n(r.pickerSeconds)}),为避免错时发布已中止`}if(t){if(!r.known)return"无法回读表单里的定时发表时间,为避免错时发布已中止";if(r.seconds!==t)return`表单里的定时发表时间与目标不一致:目标 ${_(t)},表单实际 ${r.seconds?_(r.seconds):"不定时"},为避免错时发布已中止`;if(e.isEffectiveTimeValid===!1)return"页面判定定时发表时间不合法,已中止"}else if(r.known&&r.seconds)return`表单处于定时发表状态(${_(r.seconds)}),但本次没有指定 --schedule,已中止`;if(i&&e?.isPostByTime)return"定时发表状态下平台不允许保存草稿";return null}async function be(e){return await d(e,`
|
|
114
114
|
(() => {
|
|
115
115
|
${p}
|
|
116
116
|
var sels = ${JSON.stringify(fe)};
|
|
@@ -123,7 +123,7 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
123
123
|
}
|
|
124
124
|
return { ok: false };
|
|
125
125
|
})()
|
|
126
|
-
`)}async function
|
|
126
|
+
`)}async function ve(e,t=15000){const i=500,r=Math.max(1,Math.ceil(t/i));for(let n=0;n<r;n++){if(await d(e,`
|
|
127
127
|
(() => {
|
|
128
128
|
${p}
|
|
129
129
|
var inputSels = ['input[type="file"][accept*="video"]', 'input[type="file"]'];
|
|
@@ -132,7 +132,7 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
132
132
|
}
|
|
133
133
|
return false;
|
|
134
134
|
})()
|
|
135
|
-
`))return!0;if(r
|
|
135
|
+
`))return!0;if(n<r-1)await e.wait({time:i/1000})}return!1}const Y=`((sel) => {
|
|
136
136
|
${p}
|
|
137
137
|
var real = deepQuery(sel);
|
|
138
138
|
if (!real) return null;
|
|
@@ -162,11 +162,11 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
162
162
|
return real.dispatchEvent(new win.Event(ev.type, { bubbles: true }));
|
|
163
163
|
},
|
|
164
164
|
};
|
|
165
|
-
})`;async function ge(e,t){await
|
|
166
|
-
截图已保存到 /tmp/wechat-channels_publish_upload_debug.png`)}function W(e){if(!Array.isArray(e))return"unknown";if(e.length===0)return"empty";if(e.some((t)=>t.status==="error"))return"error";return e.every((t)=>t.status==="done")?"done":"pending"}async function _e(e,t,i=180000){const
|
|
165
|
+
})`;async function ge(e,t){await be(e);await e.wait({time:1});await ve(e);let i;for(const r of me)try{await ue(e,r,[t],{findInputJs:Y});const n=await d(e,"(() => { var r = window.__ppWxInject || null; delete window.__ppWxInject; return r; })()");if(!n||n.error||n.count!==1||!n.realm)throw new c(`文件没能交给页面的上传控件: ${n?.error||`count=${n?.count??"未知"} realm=${n?.realm??"未知"}`}`);return}catch(n){i=n;if(!(n instanceof Error?n.message:String(n)).includes("未找到文件上传输入框"))break}await e.screenshot({path:"/tmp/wechat-channels_publish_upload_debug.png"});throw new c(`视频文件注入失败: ${i instanceof Error?i.message:String(i)}
|
|
166
|
+
截图已保存到 /tmp/wechat-channels_publish_upload_debug.png`)}function W(e){if(!Array.isArray(e))return"unknown";if(e.length===0)return"empty";if(e.some((t)=>t.status==="error"))return"error";return e.every((t)=>t.status==="done")?"done":"pending"}async function _e(e,t,i=180000){const r=3000,n=Math.ceil(i/r),a=Math.ceil(20000/r);let o=0;for(let l=0;l<n;l++){let s;try{s=await d(e,`
|
|
167
167
|
((fileName) => {
|
|
168
168
|
${p}
|
|
169
|
-
${
|
|
169
|
+
${O}
|
|
170
170
|
var files = readFormState().files;
|
|
171
171
|
if (Array.isArray(files)) return { files: files };
|
|
172
172
|
|
|
@@ -185,8 +185,8 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
185
185
|
var hasFileEvidence = fileName && bodyText.indexOf(fileName) >= 0;
|
|
186
186
|
return { done: !uploading && (preview || hasFileEvidence), failed: false };
|
|
187
187
|
})(${JSON.stringify(t)})
|
|
188
|
-
`)}catch(u){const h=u instanceof Error?u.message:String(u);if(h.includes("ECONNRESET")||h.includes("fetch failed")){process.stderr.write(` [retry] bridge reconnecting after page re-render (${l+1}/${
|
|
189
|
-
`);await e.wait({time:
|
|
188
|
+
`)}catch(u){const h=u instanceof Error?u.message:String(u);if(h.includes("ECONNRESET")||h.includes("fetch failed")){process.stderr.write(` [retry] bridge reconnecting after page re-render (${l+1}/${n})...
|
|
189
|
+
`);await e.wait({time:r/1000});continue}throw u}const m=W(s?.files);if(m==="error"||s?.failed){await e.screenshot({path:"/tmp/wechat-channels_publish_upload_debug.png"});throw new c("视频上传失败:页面把文件标记为上传出错,请检查文件格式和网络连接","截图: /tmp/wechat-channels_publish_upload_debug.png。本次没有提交任何内容,可以直接重试")}if(m==="done"||m==="unknown"&&s?.done)return;if(m==="empty"){o+=1;if(o>=a){await e.screenshot({path:"/tmp/wechat-channels_publish_upload_debug.png"});throw new c("视频上传失败:文件已注入但页面上传区仍为空,页面没有收下这个文件","截图: /tmp/wechat-channels_publish_upload_debug.png。本次没有提交任何内容,可以直接重试;反复出现说明视频号上传控件改版")}}else o=0;await e.wait({time:r/1000})}throw new c(`视频上传/转码超时(${Math.ceil(i/1000)}秒),请检查网络或稍后重试`)}async function K(e,t,i,r){const n=30;let a;for(let o=0;o<n;o++){a=await d(e,`
|
|
190
190
|
(function(selectors, text) {
|
|
191
191
|
${p}
|
|
192
192
|
|
|
@@ -233,10 +233,10 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
233
233
|
el.blur();
|
|
234
234
|
return { ok: actual.indexOf(text) >= 0, sel: foundSel, actual: actual };
|
|
235
235
|
})(${JSON.stringify(t)}, ${JSON.stringify(i)})
|
|
236
|
-
`);if(a?.ok)break;if(o<
|
|
236
|
+
`);if(a?.ok)break;if(o<n-1)await e.wait({time:0.5})}if(!a?.ok){await e.screenshot({path:`/tmp/wechat-channels_publish_${r}_debug.png`});throw new c(`找不到 ${r} 输入框,截图已保存到 /tmp/wechat-channels_publish_${r}_debug.png`)}}const X=`
|
|
237
237
|
(async function(TY, TM, TD, TH, TMin, TARGET_MS) {
|
|
238
238
|
${p}
|
|
239
|
-
${
|
|
239
|
+
${O}
|
|
240
240
|
function sleep(ms) { return new Promise(function(r) { setTimeout(r, ms); }); }
|
|
241
241
|
function click(el) {
|
|
242
242
|
el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window }));
|
|
@@ -385,7 +385,7 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
385
385
|
var inp = dateDl.querySelector('dt input') || deepQuery('input[placeholder*="发表时间"]');
|
|
386
386
|
return { ok: true, value: inp ? inp.value : null, pick: pickOf(), commit: commit.join('+'), state: readFormState() };
|
|
387
387
|
})
|
|
388
|
-
`;async function ye(e,t){const i=t.getFullYear(),
|
|
388
|
+
`;async function ye(e,t){const i=t.getFullYear(),r=t.getMonth()+1,n=t.getDate(),a=t.getHours(),o=t.getMinutes(),l=(y)=>String(y).padStart(2,"0"),s=t.getTime(),m=Math.floor(s/1000),u=await d(e,`${X}(${i}, ${r}, ${n}, ${a}, ${o}, ${s})`);if(!u?.ok){await e.screenshot({path:"/tmp/wechat-channels_schedule_debug.png"});const y=u?.reason?String(u.reason):"empty picker result";if(y==="timezone-mismatch")throw new c("定时设置失败:浏览器与命令行所在时区不一致,无法按钟点可靠地选中目标时刻,已中止");throw new c(`定时设置失败 (${y}),截图: /tmp/wechat-channels_schedule_debug.png`)}const h=`${i}-${l(r)}-${l(n)} ${l(a)}:${l(o)}`,w=[];if(!String(u.value||"").includes(h))w.push(`显示框=${u.value||"空"}`);if(u.pick!=null&&Math.floor(u.pick/1000)!==m)w.push(`时间选择器选中=${_(Math.floor(u.pick/1000))}`);const k=q({...u.state,files:null,titleError:""},{targetSeconds:m,isDraft:!1});if(k)w.push(k);if(w.length){await e.screenshot({path:"/tmp/wechat-channels_schedule_debug.png"});throw new c(`定时设置未验证成功: 目标=${h};${w.join(";")}`,"本次没有提交任何内容。截图: /tmp/wechat-channels_schedule_debug.png")}process.stderr.write(` 定时设置完成: ${u.value||h}(表单回读一致)
|
|
389
389
|
`)}const z=`
|
|
390
390
|
(function(isDraft, labels) {
|
|
391
391
|
${p}
|
|
@@ -443,25 +443,47 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
443
443
|
el.dispatchEvent(new MouseEvent('click', opts));
|
|
444
444
|
}
|
|
445
445
|
function btnDisabled(b) {
|
|
446
|
-
|
|
446
|
+
if (b.disabled || b.getAttribute('disabled') !== null || b.getAttribute('aria-disabled') === 'true') return true;
|
|
447
|
+
if (/disabled/.test(b.className || '')) return true;
|
|
448
|
+
try { return getComputedStyle(b).pointerEvents === 'none'; } catch (e) { return false; }
|
|
447
449
|
}
|
|
448
450
|
// 须知勾选框:优先 .original-proto-wrapper;没有这层时取框内文案像「须知 / 条款 / 同意」的勾选框,
|
|
449
|
-
//
|
|
451
|
+
// 绝不碰「不再提醒」那个(勾了会改账号设置)。勾选框不一定是原生 input:ant / weui 的自绘勾选框
|
|
452
|
+
// 只有 span / i,按 role 与类名一起找,每组只取最外层的包装元素。
|
|
450
453
|
function termsBoxes(dialog) {
|
|
451
454
|
var scope = dialog.querySelector('.original-proto-wrapper');
|
|
452
|
-
var
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
455
|
+
var root = scope || dialog;
|
|
456
|
+
var cands = Array.prototype.slice.call(root.querySelectorAll(
|
|
457
|
+
'input[type="checkbox"], [role="checkbox"], label, [class*="checkbox"]'));
|
|
458
|
+
var wraps = [];
|
|
459
|
+
cands.forEach(function (el) {
|
|
460
|
+
if (el.tagName === 'LABEL' && !el.querySelector('input[type="checkbox"], [role="checkbox"], [class*="checkbox"]')) return;
|
|
461
|
+
if (/checkbox-group/.test(String(el.className || ''))) return;
|
|
462
|
+
if (wraps.some(function (w) { return w === el || w.contains(el); })) return;
|
|
463
|
+
wraps.push(el);
|
|
464
|
+
});
|
|
465
|
+
return wraps.map(function (wrap) {
|
|
466
|
+
var input = wrap.matches('input[type="checkbox"]') ? wrap : wrap.querySelector('input[type="checkbox"]');
|
|
467
|
+
// 文案优先取包装元素自己的;自绘勾选框自身无字时才看父节点(父节点同时含「不再提醒」则不认)。
|
|
468
|
+
var own = oTextOf(wrap);
|
|
469
|
+
var text = own || oTextOf(wrap.parentNode || wrap);
|
|
470
|
+
return { input: input, wrap: wrap, text: text, own: !!own };
|
|
456
471
|
}).filter(function (b) {
|
|
457
|
-
if (b.text.indexOf('不再提醒') >= 0 && !scope) return false;
|
|
472
|
+
if (b.text.indexOf('不再提醒') >= 0 && (b.own || !scope)) return false;
|
|
458
473
|
return scope ? true : /须知|条款|同意|阅读|权益/.test(b.text);
|
|
459
474
|
});
|
|
460
475
|
}
|
|
461
476
|
function boxChecked(b) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
477
|
+
if (b.input && b.input.checked) return true;
|
|
478
|
+
var nodes = [b.wrap].concat(Array.prototype.slice.call(b.wrap.querySelectorAll('*')));
|
|
479
|
+
return nodes.some(function (n) {
|
|
480
|
+
if (n.getAttribute && n.getAttribute('aria-checked') === 'true') return true;
|
|
481
|
+
return /(^|[\\s_-])(is-)?checked(\\s|$)/.test(String(n.className && n.className.baseVal !== undefined ? n.className.baseVal : n.className || ''));
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function clickTarget(b) {
|
|
485
|
+
if (b.input && b.input.getBoundingClientRect().width) return b.input;
|
|
486
|
+
return b.wrap.querySelector('[class*="checkbox"]:not([class*="wrapper"])') || b.wrap;
|
|
465
487
|
}
|
|
466
488
|
var dialog = findOriginalDialog();
|
|
467
489
|
if (!dialog) return { ok: false, reason: 'dialog-not-found' };
|
|
@@ -470,12 +492,16 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
470
492
|
var terms = [];
|
|
471
493
|
if (choice === 'original') {
|
|
472
494
|
terms = termsBoxes(dialog);
|
|
495
|
+
// 弹窗写着「须知」却一个勾选框都没认出来:不点灰着的「声明原创」,直接报错。
|
|
496
|
+
if (!terms.length && /须知/.test(dialogText)) {
|
|
497
|
+
return { ok: false, reason: 'terms-not-found', dialogText: dialogText };
|
|
498
|
+
}
|
|
473
499
|
for (var t = 0; t < terms.length; t++) {
|
|
474
|
-
if (!boxChecked(terms[t])) fire(
|
|
500
|
+
if (!boxChecked(terms[t])) fire(clickTarget(terms[t]));
|
|
475
501
|
}
|
|
476
502
|
for (var w = 0; w < 15 && terms.some(function (b) { return !boxChecked(b); }); w++) await sleep(200);
|
|
477
503
|
if (terms.some(function (b) { return !boxChecked(b); })) {
|
|
478
|
-
return { ok: false, reason: 'terms-unchecked', dialogText: dialogText };
|
|
504
|
+
return { ok: false, reason: 'terms-unchecked', termsCount: terms.length, dialogText: dialogText };
|
|
479
505
|
}
|
|
480
506
|
}
|
|
481
507
|
var btn = null;
|
|
@@ -487,26 +513,30 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
487
513
|
if (!btn) return { ok: false, reason: 'button-not-found', label: label, dialogText: dialogText };
|
|
488
514
|
if (btnDisabled(btn)) return { ok: false, reason: 'button-disabled', label: label, termsCount: terms.length, dialogText: dialogText };
|
|
489
515
|
fire(btn);
|
|
516
|
+
// 以这一个弹窗节点本身是否消失为准;重新按「直接发表」按钮找弹窗会在弹窗换了一屏内容时误判为已关闭。
|
|
517
|
+
function dialogGone() {
|
|
518
|
+
return !dialog.isConnected || !isVisible(dialog) || !oButtons(dialog, label).length;
|
|
519
|
+
}
|
|
490
520
|
for (var c = 0; c < 25; c++) {
|
|
491
521
|
await sleep(200);
|
|
492
|
-
if (
|
|
522
|
+
if (dialogGone()) return { ok: true, label: label, termsCount: terms.length };
|
|
493
523
|
}
|
|
494
|
-
return { ok: false, reason: 'dialog-still-open', label: label, termsCount: terms.length, dialogText:
|
|
524
|
+
return { ok: false, reason: 'dialog-still-open', label: label, termsCount: terms.length, dialogText: oTextOf(dialog).slice(0, 200) };
|
|
495
525
|
})
|
|
496
|
-
`,ke={"dialog-not-found":"页面状态显示被原创确认框拦下,但没找到含「直接发表 / 声明原创」按钮的弹窗(平台可能改版)","terms-unchecked":"勾选原创权益须知后回读仍未勾上","button-not-found":"确认框里没有找到对应按钮","button-disabled":"确认框里的按钮一直是禁用状态(--original 时多半是须知没勾上,或账号当前不能声明原创)","dialog-still-open":"点了按钮后确认框没有关闭"};async function Te(e,t){const
|
|
497
|
-
`);return
|
|
526
|
+
`,ke={"dialog-not-found":"页面状态显示被原创确认框拦下,但没找到含「直接发表 / 声明原创」按钮的弹窗(平台可能改版)","terms-not-found":"弹窗里有原创权益须知,但没认出它的勾选框,未点击「声明原创」","terms-unchecked":"勾选原创权益须知后回读仍未勾上","button-not-found":"确认框里没有找到对应按钮","button-disabled":"确认框里的按钮一直是禁用状态(--original 时多半是须知没勾上,或账号当前不能声明原创)","dialog-still-open":"点了按钮后确认框没有关闭"};async function Te(e,t){const r=await d(e,`${Z}(${JSON.stringify(t?"original":"direct")})`);if(!r?.ok){await e.screenshot({path:"/tmp/wechat-channels_publish_result_debug.png"});const a=ke[r?.reason]||`确认框响应异常: ${JSON.stringify(r)}`;throw new c(`发表被平台的原创声明确认框拦下,自动选择「${t?"声明原创":"直接发表"}」失败:${a},作品尚未发出`,`先到 ${T} 确认作品列表里没有这条再重试;也可以换 ${t?"不带 --original(直接发表)":"--original(声明原创)"} 重试,`+"或加 --manual --site-session persistent 后在浏览器里手动选择。截图: /tmp/wechat-channels_publish_result_debug.png"+(r?.dialogText?`;弹窗文字: ${r.dialogText}`:""))}const n=!t?"":r.termsCount?`(须知勾选框 ${r.termsCount} 个,已回读勾上)`:"(弹窗没有须知勾选框)";process.stderr.write(` 原创确认框: 已选择「${r.label}」${n},弹窗已关闭
|
|
527
|
+
`);return r}async function Se(e,t){const i=t?["保存草稿","存草稿","草稿"]:["发表","发布"],r=t?"保存草稿":"发表",n=30;let a;for(let o=0;o<n;o++){a=await d(e,`${z}(${JSON.stringify(t)}, ${JSON.stringify(i)})`);if(a?.ok)break;if(o<n-1)await e.wait({time:0.5})}if(!a?.ok){await e.screenshot({path:"/tmp/wechat-channels_publish_submit_debug.png"});const o=await N(e).catch(()=>null),l=a?.found?`「${r}」按钮一直是禁用状态${o?.disabledTip?`,页面给出的原因: ${o.disabledTip}`:""}`:`页面上没有「${r}」按钮`;throw new c(`${l}。本次没有提交任何内容`,"截图: /tmp/wechat-channels_publish_submit_debug.png")}return a}oe({site:"wechat-channels",name:"publish",access:"write",description:"发布视频到视频号",domain:"channels.weixin.qq.com",strategy:le.COOKIE,browser:!0,navigateBefore:!1,args:[{name:"video",required:!0,positional:!0,help:"视频文件路径 (.mp4/.mov/.avi/.webm)"},{name:"title",required:!1,help:"短标题(6-16 字;只能用中文/字母/数字/空格和 《》“”:+?% ℃,逗号请用空格代替)"},{name:"caption",fromFile:!0,required:!1,help:"描述内容,支持直接写 #话题(如:日常生活 #搞笑 #生活)"},{name:"schedule",required:!1,help:'定时发布时间(ISO8601 或 Unix 秒,如 "2026-05-20 10:00",精确到分钟;不能与 --draft 同用)'},{name:"draft",type:"bool",default:!1,help:"保存为草稿(平台不允许定时稿存草稿)"},{name:"manual",type:"bool",default:!1,help:"填完所有字段后不自动发布,由用户手动点击发表(务必同时传 --site-session persistent,否则表单页约 30 秒后会被重置为空白页)"},{name:"timeout",type:"int",required:!1,default:600,help:"命令整体超时秒数(含登录等待 + 上传转码,默认 600)"},{name:"original",type:"bool",default:!1,help:"创作分成计划账号发表时会弹「声明原创的视频有机会获得广告分成」确认框:默认自动点「直接发表」;传 --original 则勾选原创权益须知并点「声明原创」。不弹框的账号此参数无效果"}],columns:["status","title","detail","id","manage_url"],func:async(e,t)=>{if(!e)throw new c("需要浏览器页面");const i=G(t.timeout),r=Date.now()+i*1000,n=B(t.video,"视频",pe),a=String(t.title??"").trim(),o=String(t.caption??"").trim(),l=H(t.schedule||null),s=D(t.draft),m=D(t.manual),u=D(t.original);Q(a);if(u&&(s||m))throw new f("--original 只在自动发表时生效:原创确认框在点「发表」后才出现,不能与 --draft / --manual 同用");if(s&&l)throw new f("--draft 不能与 --schedule 同用:视频号在定时发表状态下禁用保存草稿");const h=l?Math.floor(l.getTime()/1000):0;await e.goto(I);await e.wait({time:4});{const b=(A)=>typeof A==="string"&&A.includes("/platform/post/create"),E=await d(e,"() => location.href");if(!b(E)){process.stderr.write(`
|
|
498
528
|
⚠️ 未登录视频号(已被重定向离开发布页)。请在 Chrome 中扫码登录...
|
|
499
529
|
`+" 当前地址: "+E+`
|
|
500
530
|
`+` 登录完成后将自动继续发布。
|
|
501
531
|
|
|
502
|
-
`);const
|
|
532
|
+
`);const A=Math.min(r,Date.now()+120000);let P=!1;while(Date.now()<A){await e.wait({time:3});await e.goto(I);await e.wait({time:2});const ie=await d(e,"() => location.href");if(b(ie)){P=!0;break}process.stderr.write(` 等待扫码中...
|
|
503
533
|
`)}if(!P)throw new se("channels.weixin.qq.com","登录超时(2分钟),请手动登录后重试");process.stderr.write(`✅ 登录成功,继续发布...
|
|
504
534
|
|
|
505
|
-
`);await e.wait({time:3});await e.goto(I);await e.wait({time:5})}}await ge(e,
|
|
535
|
+
`);await e.wait({time:3});await e.goto(I);await e.wait({time:5})}}await ge(e,n);await e.wait({time:2});await _e(e,C.basename(n),Math.min(180000,we(r,"视频上传/转码")));await e.wait({time:1});if(a){await K(e,ce,a,"title");await e.wait({time:0.5});const b=await N(e);if(b?.titleError)throw new c(`平台拒绝了短标题: ${b.titleError}`,"本次没有提交任何内容,修改 --title 后重试")}if(o){await K(e,de,o,"caption");await e.wait({time:0.5})}if(l){await ye(e,l);await e.wait({time:0.5})}if(m){process.stderr.write(`
|
|
506
536
|
ℹ️ 手动模式:表单已填好,请在浏览器中检查并点击「发表」。
|
|
507
537
|
`+` 若未加 --site-session persistent,此标签页约 30 秒后会被重置为空白页。
|
|
508
538
|
|
|
509
|
-
`);return[{status:"⏸️ 已填写完毕,请在浏览器中手动点击发表",title:a||"",detail:[l?`定时: ${_(h)}(已回读表单确认)`:null].filter(Boolean).join(" · ")||"表单已就绪",id:"",manage_url:T}]}const w=await
|
|
539
|
+
`);return[{status:"⏸️ 已填写完毕,请在浏览器中手动点击发表",title:a||"",detail:[l?`定时: ${_(h)}(已回读表单确认)`:null].filter(Boolean).join(" · ")||"表单已就绪",id:"",manage_url:T}]}const w=await N(e),k=q(w,{targetSeconds:h,isDraft:s});if(k){await e.screenshot({path:"/tmp/wechat-channels_publish_submit_debug.png"});throw new c(`${k}。本次没有提交任何内容`,"截图: /tmp/wechat-channels_publish_submit_debug.png")}await Se(e,s);await e.wait({time:s?1:4});const y=s?["已保存","暂存成功","保存成功"]:["已发表","发布成功","发表成功","审核中"];let M="",S="",x=!1,R="",v=null;const ee=w?.draftObjectId||"";let g=null;for(let b=0;b<30;b++){v=await N(e).catch(()=>null);if(s&&!ee&&v?.draftObjectId&&v.isCaching===!1){R=v.draftObjectId;x=!0;break}const E=g?v?.originalDialog:v?.originalIntercept||v?.originalDialog;if(!s&&E){if(g){await e.screenshot({path:"/tmp/wechat-channels_publish_result_debug.png"});throw new c(`已在原创确认框里选择「${g.label}」,但确认框再次出现,作品尚未发出`,`先到 ${T} 确认作品列表里没有这条,再加 --manual --site-session persistent 后在浏览器里手动处理。截图: /tmp/wechat-channels_publish_result_debug.png`)}g=await Te(e,u);await e.wait({time:1});continue}M=await d(e,"() => location.href");S=await d(e,`
|
|
510
540
|
(function(markers) {
|
|
511
541
|
${p}
|
|
512
542
|
var all = deepQueryAll('*');
|
|
@@ -521,4 +551,4 @@ import*as ae from"node:fs";import*as C from"node:path";import{cli as oe,Strategy
|
|
|
521
551
|
}
|
|
522
552
|
return '';
|
|
523
553
|
})(${JSON.stringify(y)})
|
|
524
|
-
`);x=
|
|
554
|
+
`);x=U({isDraft:s,finalUrl:M,successMsg:S});if(x)break;await e.wait({time:0.5})}if(!x){await e.screenshot({path:"/tmp/wechat-channels_publish_result_debug.png"});throw new c(`已点击${s?"保存草稿":"发表"},但未能确认是否成功(结果未知)`,`不要直接重试,先到 ${T} 核对${s?"草稿箱":"作品列表"}里是否已有这条,避免重复发布。`+`截图: /tmp/wechat-channels_publish_result_debug.png;url=${M||""} message=${S||""}`)}const te=s?"草稿已保存":l?"定时发表已提交":"发布成功",re=[l?`定时: ${_(h)}(已回读表单确认)`:null,g?`原创确认框: 已选「${g.label}」`:null,u&&!g?"平台未弹原创确认框,未声明原创(账号可能不在创作分成计划内)":null,S||null,s?"草稿不公开,到管理页的草稿箱继续编辑":l?"定时稿到点前没有公开链接,到管理页核对计划时间":"平台提交后不返回作品链接,到管理页查看"].filter(Boolean),ne=[{status:`✅ ${te}`,title:a||"",detail:re.join(" · "),id:R,manage_url:T}];await e.goto("https://channels.weixin.qq.com/platform/post/list",{waitUntil:"none"}).catch(()=>{});return ne}});export const __test__={parseTimeoutSeconds:G,parseScheduleDate:H,parseBooleanFlag:D,requireFilePath:B,submitSucceeded:U,validateShortTitle:Q,submittedScheduleSeconds:J,preSubmitBlocker:q,uploadProgress:W,DEEP_QUERY_FN:p,FORM_STATE_FN:O,REALM_FILE_INPUT_JS:Y,SCHEDULE_PICK_JS:X,SUBMIT_CLICK_JS:z,ORIGINAL_DIALOG_FN:V,ORIGINAL_ANSWER_JS:Z};
|