publishport-opencli 1.0.58 → 1.0.59
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/cli-manifest.json +19 -2
- package/clis/baijiahao/publish.js +60 -48
- package/package.json +1 -1
package/cli-manifest.json
CHANGED
|
@@ -3209,14 +3209,29 @@
|
|
|
3209
3209
|
"name": "title",
|
|
3210
3210
|
"type": "str",
|
|
3211
3211
|
"required": true,
|
|
3212
|
-
"help": "
|
|
3212
|
+
"help": "视频标题,即百家号「作品描述」(不足 8 字会自动补「你不知道的」,截断到 50 字)"
|
|
3213
|
+
},
|
|
3214
|
+
{
|
|
3215
|
+
"name": "declaration",
|
|
3216
|
+
"type": "str",
|
|
3217
|
+
"default": "none",
|
|
3218
|
+
"required": false,
|
|
3219
|
+
"help": "创作声明(百家号必选):none 无需声明 / ai 含AI生成内容 / reprint 转载 / fiction 虚构演绎 / marketing 营销信息 / opinion 个人观点",
|
|
3220
|
+
"choices": [
|
|
3221
|
+
"none",
|
|
3222
|
+
"ai",
|
|
3223
|
+
"reprint",
|
|
3224
|
+
"fiction",
|
|
3225
|
+
"marketing",
|
|
3226
|
+
"opinion"
|
|
3227
|
+
]
|
|
3213
3228
|
},
|
|
3214
3229
|
{
|
|
3215
3230
|
"name": "schedule",
|
|
3216
3231
|
"type": "str",
|
|
3217
3232
|
"default": "",
|
|
3218
3233
|
"required": false,
|
|
3219
|
-
"help": "定时发布时间(ISO8601 或 Unix
|
|
3234
|
+
"help": "定时发布时间(ISO8601 或 Unix 秒,须在当前时间后 1 小时至 7 天内,按北京时间选择;不填即立即发布)"
|
|
3220
3235
|
},
|
|
3221
3236
|
{
|
|
3222
3237
|
"name": "timeout",
|
|
@@ -3229,6 +3244,8 @@
|
|
|
3229
3244
|
"columns": [
|
|
3230
3245
|
"status",
|
|
3231
3246
|
"title",
|
|
3247
|
+
"article_id",
|
|
3248
|
+
"review_status",
|
|
3232
3249
|
"url"
|
|
3233
3250
|
],
|
|
3234
3251
|
"type": "js",
|
|
@@ -1,57 +1,69 @@
|
|
|
1
|
-
import{cli as
|
|
2
|
-
((
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
})(${JSON.stringify(
|
|
13
|
-
`)))
|
|
1
|
+
import{cli as j,Strategy as x}from"@jackwener/opencli/registry";import{ArgumentError as m,CommandExecutionError as o}from"@jackwener/opencli/errors";import{resolveVideoFile as q,setVideoInput as D,unwrap as l,currentUrl as E,parseScheduleDate as I,waitForUrlIncludes as J,waitForSelector as w,videoTimeoutArg as R}from"../_shared/video-publish.js";import{clickControl as U,verifyControl as f}from"../_shared/publish-controls.js";const M="https://baijiahao.baidu.com/builder/rc/edit?type=videoV2",k=["div[class^='video-main-container'] input","input[type='file']"],L=50,y='#formMain [data-lexical-editor="true"], #formMain [class*="contentEditable"][contenteditable="true"]';async function P(t,i){let e=i;if(e.length<=8)e+=" 你不知道的";e=Array.from(e).slice(0,L).join("");if(!await w(t,y,120000))throw new o("百家号发布停在「填写标题」:120 秒内未出现「作品描述」输入框,页面可能再次改版");if(!l(await t.evaluate(`
|
|
2
|
+
((sel) => {
|
|
3
|
+
const ed = document.querySelector(sel);
|
|
4
|
+
if (!ed) return false;
|
|
5
|
+
ed.focus();
|
|
6
|
+
const range = document.createRange();
|
|
7
|
+
range.selectNodeContents(ed);
|
|
8
|
+
const s = window.getSelection();
|
|
9
|
+
s.removeAllRanges();
|
|
10
|
+
s.addRange(range);
|
|
11
|
+
return document.activeElement === ed;
|
|
12
|
+
})(${JSON.stringify(y)})
|
|
13
|
+
`)))throw new o("百家号发布停在「填写标题」:「作品描述」输入框无法获得焦点");await t.insertText(e);await t.wait({time:1});const r=String(l(await t.evaluate(`
|
|
14
|
+
((sel) => { const ed = document.querySelector(sel); return ed ? ed.innerText.trim() : ''; })(${JSON.stringify(y)})
|
|
15
|
+
`))||"");if(r!==e)throw new o(`百家号发布停在「填写标题」:写入后回读不一致(期望「${e}」,实际「${r}」)`);return e}async function H(t,i){const e=Date.now()+i;while(Date.now()<e){const n=l(await t.evaluate(`
|
|
14
16
|
(() => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (has('上传中')) return 'uploading';
|
|
19
|
-
return 'done';
|
|
17
|
+
const overlays = Array.from(document.querySelectorAll('[class*="tabCoverOverlay"], [class*="tabCoverPrecent"]'));
|
|
18
|
+
if (overlays.some((el) => (el.innerText || el.textContent || '').includes('失败'))) return 'failed';
|
|
19
|
+
return overlays.length ? 'uploading' : 'done';
|
|
20
20
|
})()
|
|
21
|
-
`));if(
|
|
22
|
-
((
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
`)
|
|
29
|
-
(() => {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
})()
|
|
38
|
-
`);
|
|
39
|
-
(() => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
`));if(n==="failed")return"failed";if(n==="done")return"done";await t.wait({time:2})}return"timeout"}async function V(t){return String(l(await t.evaluate(`
|
|
22
|
+
(() => Array.from(document.querySelectorAll('.cheetah-message-notice, .cheetah-form-item-explain-error'))
|
|
23
|
+
.filter((el) => el.getClientRects().length)
|
|
24
|
+
.map((el) => (el.innerText || '').trim())
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(' | ')
|
|
27
|
+
.slice(0, 300))()
|
|
28
|
+
`))||"")}async function S(t,i){const e=l(await t.evaluate(`
|
|
29
|
+
(async (title) => {
|
|
30
|
+
const html = await (await fetch('https://baijiahao.baidu.com/builder/rc/edit', { credentials: 'include' })).text();
|
|
31
|
+
const m = html.match(/window\\.__BJH__INIT__AUTH__\\s*=\\s*['"]([^'"]+)['"]/);
|
|
32
|
+
if (!m) return { error: '取不到 token' };
|
|
33
|
+
const qs = new URLSearchParams({ currentPage: '1', pageSize: '20', search: title, type: '', collection: '', dynamic: '1' });
|
|
34
|
+
const j = await (await fetch('https://baijiahao.baidu.com/pcui/article/lists?' + qs, { credentials: 'include', headers: { token: m[1] } })).json();
|
|
35
|
+
if (!j || !j.data) return { error: (j && j.errmsg) || '列表接口无数据' };
|
|
36
|
+
return { rows: (j.data.list || []).filter((a) => a.title === title).map((a) => ({ id: String(a.article_id), status: a.status || '' })) };
|
|
37
|
+
})(${JSON.stringify(i)})
|
|
38
|
+
`));if(!e||e.error)throw new o(`百家号内容列表查询失败:${e?e.error:"无返回"}`);return e.rows}const b={none:"无需声明",ai:"含AI生成内容",reprint:"内容为转载",fiction:"含虚构演绎内容",marketing:"内容含营销信息",opinion:"个人观点,仅供参考"},C='input[placeholder="请选择创作声明"]';async function u(t,i,e,n){const r=l(await t.evaluate(`
|
|
39
|
+
((sel, text) => {
|
|
40
|
+
const hits = [...document.querySelectorAll(sel)]
|
|
41
|
+
.filter((e) => e.getClientRects().length && e.textContent.trim() === text);
|
|
42
|
+
if (hits.length !== 1) return '期望唯一控件「' + text + '」,找到 ' + hits.length;
|
|
43
|
+
if (hits[0].disabled || /disabled/.test(hits[0].className)) return '控件「' + text + '」不可用';
|
|
44
|
+
hits[0].click();
|
|
45
|
+
return 'ok';
|
|
46
|
+
})(${JSON.stringify(i)}, ${JSON.stringify(e)})
|
|
47
|
+
`));if(r!=="ok")throw new o(`百家号发布停在「${n}」:${r};已停止提交`)}async function B(t,i){const e=b[i],n=".cheetah-modal div.cursor-pointer";await U(t,C);await f(t,`[...document.querySelectorAll(${JSON.stringify(n)})].some(e => e.getClientRects().length && e.textContent.trim() === ${JSON.stringify(e)})`,"「创作声明」弹窗");await u(t,n,e,"创作声明");await f(t,`[...document.querySelectorAll(${JSON.stringify(n)})].some(e => e.getClientRects().length && e.textContent.trim() === ${JSON.stringify(e)} && e.querySelector('.cheetah-radio-wrapper-checked'))`,`创作声明「${e}」`);await u(t,".cheetah-modal .cheetah-btn-primary","确定","创作声明");await f(t,`(document.querySelector(${JSON.stringify(C)})?.value || '').includes(${JSON.stringify(e)})`,`创作声明「${e}」`)}const v=".cheetah-modal-confirm";function O(t){const i=new Date(t.getTime()+28800000);return[`${i.getUTCMonth()+1}月${i.getUTCDate()}日`,`${i.getUTCHours()}点`,`${i.getUTCMinutes()}分`]}async function F(t,i,e){const n=`${v} .cheetah-select-selector`;await t.evaluate(`document.querySelectorAll(${JSON.stringify(n)})[${i}]?.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }))`);for(let r=0;r<30;r++){await t.wait({time:0.3});const s=l(await t.evaluate(`
|
|
48
|
+
((label) => {
|
|
49
|
+
const dd = Array.from(document.querySelectorAll('.cheetah-select-dropdown'))
|
|
50
|
+
.filter((d) => d.getClientRects().length && !d.className.includes('hidden')).pop();
|
|
51
|
+
if (!dd) return 'no-dropdown';
|
|
52
|
+
const opt = Array.from(dd.querySelectorAll('.cheetah-select-item-option')).find((o) => o.textContent.trim() === label);
|
|
53
|
+
if (opt) {
|
|
54
|
+
if (opt.className.includes('disabled')) return 'disabled';
|
|
55
|
+
return 'visible';
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
const holder = dd.querySelector('.rc-virtual-list-holder');
|
|
58
|
+
if (!holder || holder.scrollTop + holder.clientHeight >= holder.scrollHeight) return 'missing';
|
|
59
|
+
holder.scrollTop += holder.clientHeight / 2;
|
|
60
|
+
return 'scrolled';
|
|
61
|
+
})(${JSON.stringify(e)})
|
|
62
|
+
`));if(s==="visible"){await u(t,".cheetah-select-dropdown .cheetah-select-item-option",e,"定时发布");let c="";for(let h=0;h<10;h++){await t.wait({time:0.3});c=String(l(await t.evaluate(`document.querySelectorAll(${JSON.stringify(n)})[${i}]?.textContent.trim() || ''`))||"");if(c===e)return}throw new o(`百家号发布停在「定时发布」:选择「${e}」后显示为「${c}」;已停止提交`)}if(s==="missing"||s==="disabled")throw new o(`百家号发布停在「定时发布」:可选时间里没有「${e}」(百家号只允许当前时间后 1 小时至 7 天)`)}throw new o(`百家号发布停在「定时发布」:时间下拉中未找到「${e}」`)}async function W(t,i){await u(t,"button.cheetah-btn","定时发布","定时发布");await f(t,`[...document.querySelectorAll(${JSON.stringify(v)})].some(e => e.getClientRects().length && e.textContent.includes('定时发文'))`,"「定时发文」弹窗");const e=O(i);for(let n=0;n<e.length;n++)await F(t,n,e[n]);await u(t,`${v} .cheetah-btn-primary`,"定时发布","定时发布")}j({site:"baijiahao",name:"publish",access:"write",description:"发布视频到百家号(一条命令完成上传+填写+发布;可选定时)",domain:"baijiahao.baidu.com",strategy:x.COOKIE,browser:!0,navigateBefore:!1,args:[{name:"video",required:!0,positional:!0,help:"视频文件路径"},{name:"title",required:!0,help:"视频标题,即百家号「作品描述」(不足 8 字会自动补「你不知道的」,截断到 50 字)"},{name:"declaration",default:"none",choices:Object.keys(b),help:"创作声明(百家号必选):none 无需声明 / ai 含AI生成内容 / reprint 转载 / fiction 虚构演绎 / marketing 营销信息 / opinion 个人观点"},{name:"schedule",default:"",help:"定时发布时间(ISO8601 或 Unix 秒,须在当前时间后 1 小时至 7 天内,按北京时间选择;不填即立即发布)"},R()],columns:["status","title","article_id","review_status","url"],func:async(t,i)=>{const e=String(i.title??"").trim();if(!e)throw new m("--title is required");const n=q(i.video),r=I(i.schedule);if(r&&(r.getTime()<Date.now()+3600000||r.getTime()>Date.now()+604800000))throw new m("百家号视频定时发布时间须在当前时间后 1 小时至 7 天内");const s=String(i.declaration||"none");if(!Object.hasOwn(b,s))throw new m(`不支持的 --declaration: ${s}`);await t.goto(M);if(!await J(t,"builder/rc/edit",60000))throw new o("未能进入百家号视频编辑页(登录态可能失效,请先 ppcli baijiahao login)");if(!await w(t,"div[class^='video-main-container'] input, input[type='file']",30000))throw new o("百家号视频上传输入框未出现");await D(t,k,[n]);if(!await w(t,"div#formMain",60000))throw new o("百家号发布停在「上传视频」:选择文件后 60 秒内未出现发布表单");const c=await P(t,e),h=Math.max(60,Number(i.timeout)||540)*1000,p=await H(t,h);if(p==="failed")throw new o(`百家号发布停在「上传视频」:平台提示上传失败(${n})`);if(p==="timeout")throw new o(`百家号发布停在「上传视频」:${h/1000} 秒内未上传完成`,"大视频可调大 --timeout;本次未提交,可直接重试");if(!await w(t,'#formMain [class*="coverWrapper"] img',120000))throw new o("百家号发布停在「封面」:上传完成后 120 秒内未生成封面");await B(t,s);const g=new Set((await S(t,c)).map((a)=>a.id));if(r)await W(t,r);else await u(t,'button[data-testid="publish-btn"]',"发布","点击发布");await t.wait({time:2});if(Boolean(l(await t.evaluate(`
|
|
51
63
|
(() => {
|
|
52
64
|
for (const el of document.querySelectorAll('div.passMod_dialog-container')) {
|
|
53
65
|
if (el.offsetParent !== null && (el.innerText || '').includes('百度安全验证')) return true;
|
|
54
66
|
}
|
|
55
67
|
return false;
|
|
56
68
|
})()
|
|
57
|
-
`))))throw new
|
|
69
|
+
`))))throw new o("百家号发布停在「点击发布」:出现百度安全验证,请在窗口内手动完成后重试");const T=new Set,A=Date.now()+90000;let d=null;while(Date.now()<A){const a=await V(t);if(a)T.add(a);const _=await E(t);if(/发布成功/.test(a)||_.includes("builder/rc/clue")||_.includes("builder/rc/content")){d=(await S(t,c)).find((N)=>!g.has(N.id))||null;if(d)break}await t.wait({time:2})}if(!d)d=(await S(t,c)).find((a)=>!g.has(a.id))||null;if(!d){const a=[...T].join(" | ");throw new o(`百家号发布停在「确认结果」:点击发布后 90 秒内容列表中未出现该作品${a?`,页面提示:${a}`:""}`,"先用 ppcli baijiahao lists --search <标题> 回查,再决定是否重发")}return[{status:r?`✅ 定时发布已提交(北京时间 ${O(r).join(" ")})`:"✅ 发布成功",title:c,article_id:d.id,review_status:d.status,url:"https://baijiahao.baidu.com/builder/rc/content"}]}});
|