publishport-opencli 1.0.57 → 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
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"}]}});
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import{readChapters as v,setXhsChapters as x}from"./publish-editors.js";import*as s from"node:fs";import*as a from"node:path";import{setInputFiles as f}from"../../_shared/file-inject.js";import{ArgumentError as l,CommandExecutionError as m}from"@jackwener/opencli/errors";import{clickControl as c,control as w,fillControl as u,verifyControl as r,publicationTime as q,resolveDeclaration as b}from"../../_shared/publish-controls.js";async function y(t,e){const o=await w(t,".d-select",e);await t.evaluate(`(() => {const el=document.querySelectorAll('.d-select')[${o.nth}].closest('.d-select-wrapper'); el.focus();return true;})()`);await t.wait({time:0.2})}async function h(t,e,o){const n=await w(t,e,o);await t.evaluate(`(() => {document.querySelectorAll(${JSON.stringify(e)})[${n.nth}].click();return true;})()`);await t.wait({time:0.2})}export const XHS_DECLARATIONS={ai:"笔记含AI合成内容",fiction:"虚构演绎,仅供娱乐",marketing:"内容包含营销广告",reprint:"来源转载","self-shot":"自主拍摄"};const d={public:"公开可见",private:"仅自己可见",friends:"仅互关好友可见",include:"只给谁看",exclude:"不给谁看"};export const XHS_PUBLISH_ARGS=[{name:"declaration",choices:Object.keys(XHS_DECLARATIONS),help:"内容声明:ai / fiction / marketing / reprint / self-shot"},{name:"source",help:"转载来源媒体名称(declaration=reprint 必填)"},{name:"shot-location",help:"自主拍摄地点(使用平台候选地点的完整名称)"},{name:"shot-date",help:"自主拍摄日期 YYYY-MM-DD"},{name:"original",type:"boolean",help:"声明原创;true 同意平台原创声明须知,false 取消"},{name:"visibility",choices:Object.keys(d),help:"可见范围;include/exclude 需同时指定 --audience"},{name:"audience",help:"定向可见用户昵称,逗号分隔(最多200人,须在平台可选列表中)"},{name:"schedule",help:"北京时间 YYYY-MM-DD HH:mm / 带时区 ISO8601 / Unix秒;1小时至14天后"},{name:"allow-duet",type:"boolean",help:"允许合拍(true/false,不传保留平台默认)"},{name:"allow-copy",type:"boolean",help:"允许正文复制(true/false,不传保留平台默认)"},{name:"location",help:"地点完整名称,按平台搜索结果精确选择"},{name:"location-address",help:"地点完整地址,使用 xiaohongshu location 返回的地址区分重名"},{name:"activity",help:"关联活动完整名称(平台会自动添加活动话题)"},{name:"quote-note",help:"引用笔记链接(小红书完整链接,包含访问所需参数)"},{name:"quote-title",help:"引用自己已发布笔记的完整标题,与 --quote-note 二选一"},{name:"attachment",help:"文件附件路径:pdf/doc/docx/ppt/pptx,最多100MB"}],XHS_VIDEO_ARGS=[...XHS_PUBLISH_ARGS.filter((t)=>!["allow-duet","allow-copy","attachment"].includes(t.name)),{name:"chapters",help:"章节 JSON 文件路径:[{time:整数秒,title:章节名,description:描述}],视频须至少15秒"},{name:"summary",help:"视频内容总结(最多100字)"},{name:"cover",help:"自定义视频封面图片路径(jpg/png/webp)"},{name:"cover-ratio",choices:["original","1:1","3:4","4:3"],help:"封面裁剪比例,需同时提供 --cover"}];export function validateXhsSettings(t){if(t["location-address"]&&!t.location)throw new l("--location-address 需要 --location");const e=v(t.chapters);if(t.summary!==void 0&&[...String(t.summary)].length>100)throw new l("--summary 最多100字");if(t["cover-ratio"]&&!t.cover)throw new l("--cover-ratio 需要 --cover");if(t.cover){const i=a.resolve(t.cover);if(!s.existsSync(i)||!s.statSync(i).isFile()||![".jpg",".jpeg",".png",".webp"].includes(a.extname(i).toLowerCase()))throw new l("封面需为存在的 jpg/png/webp 文件")}if(t["quote-note"]&&t["quote-title"])throw new l("--quote-note 与 --quote-title 二选一");if(t["quote-note"]){let i;try{i=new URL(t["quote-note"])}catch{throw new l("--quote-note 需要完整的小红书笔记链接")}if(i.protocol!=="https:"||!["xiaohongshu.com","www.xiaohongshu.com","xhslink.com"].includes(i.hostname))throw new l("--quote-note 需要 HTTPS 小红书笔记链接")}if(t.attachment){const i=a.resolve(t.attachment);if(!s.existsSync(i)||!s.statSync(i).isFile())throw new l("附件文件不存在: "+i);if(![".pdf",".doc",".docx",".ppt",".pptx"].includes(a.extname(i).toLowerCase())||s.statSync(i).size>104857600)throw new l("附件需为100MB以内的 pdf/doc/docx/ppt/pptx")}const o=b(t,XHS_DECLARATIONS);if(o==="reprint"&&!String(t.source||"").trim())throw new l("--declaration reprint 需要 --source 媒体名称");if(t.source&&o!=="reprint")throw new l("--source 仅用于 --declaration reprint");if(o==="reprint"&&t.original)throw new l("转载来源声明不能与 --original true 同时使用");if(o==="self-shot"&&(!t["shot-location"]||!/^\d{4}-\d{2}-\d{2}$/.test(t["shot-date"]||"")))throw new l("自主拍摄需 --shot-location 和 --shot-date YYYY-MM-DD");if((t["shot-date"]||t["shot-location"])&&o!=="self-shot")throw new l("拍摄地点和日期仅用于 --declaration self-shot");if(t.visibility!==void 0&&!Object.hasOwn(d,t.visibility))throw new l("不支持的 --visibility");const n=String(t.audience||"").split(",").map((i)=>i.trim()).filter(Boolean);if(["include","exclude"].includes(t.visibility)&&(!n.length||n.length>200||new Set(n).size!==n.length))throw new l("定向可见需要1至200个不重复的 --audience 用户");if(n.length&&!["include","exclude"].includes(t.visibility))throw new l("--audience 仅用于 include/exclude 可见范围");return{declaration:o,schedule:q(t.schedule,1),audience:n,chapters:e}}async function p(t,e,o){return t.evaluate(`([...document.querySelectorAll(${JSON.stringify(e)})].filter(e=>e.getClientRects().length && e.textContent.trim()===${JSON.stringify(o)}).length === 1)`)}export async function xhsSwitch(t,e,o){const i=await(()=>t.evaluate(`((label)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);if(rows.length!==1)return null; const input=rows[0].querySelector('input[type="checkbox"]');return input ? {checked:input.checked,nth:[...document.querySelectorAll('.custom-switch-card .d-switch')].indexOf(rows[0].querySelector('.d-switch'))}:null;})(${JSON.stringify(e)})`))();if(!i||i.nth<0)throw new m("未找到发布设置开关:"+e+";已停止提交");if(i?.checked===o)return;await t.click(".custom-switch-card .d-switch",{nth:i.nth});await t.wait({time:0.2});if(e==="原创声明"&&o&&await t.evaluate("!!document.querySelector('.originalContainer')")){await c(t,".originalContainer .d-checkbox");await c(t,".originalContainer button","声明原创")}await r(t,`((label,value)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);return rows.length===1 && rows[0].querySelector('input[type="checkbox"]')?.checked===value;})(${JSON.stringify(e)},${o})`,e)}async function C(t,e,o){const n=XHS_DECLARATIONS[o],i=await p(t,".d-select-description",n);if(i&&!["reprint","self-shot"].includes(o))return;await c(t,".d-select",i?n:"添加内容类型声明");if(o==="reprint"||o==="self-shot")await c(t,".declaration-drop-down .d-option-name","内容来源声明");await c(t,".d-popover .d-option-content",n);if(o==="reprint"){await u(t,'input[placeholder="请输入媒体名称"]',e.source);await c(t,".self-shooting-contain button","确认")}if(o==="self-shot"){await u(t,'input[placeholder="下拉选择地点"]',e["shot-location"],!1);await r(t,`!![...document.querySelectorAll('.el-autocomplete-suggestion .name')].find(e=>e.textContent.trim()===${JSON.stringify(e["shot-location"])})`,"拍摄地点候选");await c(t,".el-autocomplete-suggestion .name",e["shot-location"],!1);await u(t,".self-shooting-contain .d-datepicker-input-filter input",e["shot-date"]);await c(t,".self-shooting-contain button","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1) && !document.querySelector('.self-shooting-contain')`,n)}export async function setXhsPublishSettings(t,e){const o=validateXhsSettings(e);if(e.original!==void 0)await xhsSwitch(t,"原创声明",e.original);if(o.declaration)await C(t,e,o.declaration);if(e["allow-duet"]!==void 0)await xhsSwitch(t,"允许合拍",e["allow-duet"]);if(e["allow-copy"]!==void 0)await xhsSwitch(t,"允许正文复制",e["allow-copy"]);if(e.visibility){const n=d[e.visibility];if(!await p(t,".d-select-description",n)){const i=await t.evaluate(`([...document.querySelectorAll('.d-select-description')].filter(e=>${JSON.stringify(Object.values(d))}.includes(e.textContent.trim())).map(e=>e.textContent.trim()))`);if(i.length!==1)throw new m("无法确定当前可见范围;已停止提交");await y(t,i[0]);await h(t,".custom-option .name",n)}if(o.audience.length){for(const i of o.audience){await u(t,'.d-modal input[placeholder="搜索用户"]',i,!1);await r(t,`!![...document.querySelectorAll('.d-modal .left .user-list *')].find(e=>!e.children.length&&e.textContent.trim()===${JSON.stringify(i)})`,"可选用户 "+i);await c(t,".d-modal .left .user-list .user-name",i)}await c(t,".d-modal .confirm-btn","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1)`,"可见范围")}if(o.schedule){await xhsSwitch(t,"定时发布",!0);await u(t,".d-datepicker-input-filter input",o.schedule)}if(e.location){await y(t,"添加地点");await u(t,".d-select.focus input",e.location,!1);const n=`(({name,address})=>{const all=[...document.querySelectorAll('.d-popover .option-name')];const hits=all.filter(e=>e.getClientRects().length && e.textContent.trim()===name && (!address || e.parentElement.querySelector('.option-subname')?.textContent.trim()===address));return hits.length===1 ? all.indexOf(hits[0]) : -1;})(${JSON.stringify({name:e.location,address:e["location-address"]})})`;await r(t,`(${n})>=0`,"唯一地点(重名时指定 --location-address)");const i=await t.evaluate(n);if(i<0)throw new m("地点候选已变化,停止提交");await t.evaluate(`document.querySelectorAll('.d-popover .option-name')[${i}].click()`);await r(t,`!![...document.querySelectorAll('.d-select-description')].find(e=>e.textContent.trim()===${JSON.stringify(e.location)})`,"地点")}if(e["quote-note"]||e["quote-title"]){await c(t,".setting-card-text","引用笔记");if(e["quote-note"]){await c(t,".select-note-modal__tab","他人笔记");await u(t,'input[placeholder="请粘贴笔记链接 http://..."]',e["quote-note"],!1)}const n=e["quote-title"];await r(t,`([...document.querySelectorAll('.select-note-modal .note-card__title')].filter(e=>e.getClientRects().length ${n?"&& e.textContent.trim()==="+JSON.stringify(n):""}).length===1)`,"待引用笔记");const i=await w(t,".select-note-modal .note-card__title",n),S=await t.evaluate(`document.querySelectorAll('.select-note-modal .note-card__title')[${i.nth}].textContent.trim()`);await t.click(i.selector,{nth:i.nth});await c(t,".select-note-modal button","确认引用");await r(t,`!document.querySelector('.select-note-modal') && document.body.innerText.includes(${JSON.stringify("《")} + ${JSON.stringify(S)} + '》')`,"引用笔记")}if(e.activity){await h(t,".more","更多");const n=`((name)=>{const cards=[...document.querySelectorAll('.activity-card-drawer')].filter(e=>e.querySelector('.activity-name')?.textContent.trim()===name);return cards.length===1 ? {nth:[...document.querySelectorAll('.activity-card-drawer .activity-action')].indexOf(cards[0].querySelector('.activity-action')),selected:cards[0].querySelector('.activity-action')?.textContent.trim()==='取消关联'} : null;})(${JSON.stringify(e.activity)})`;await r(t,`!!(${n})`,"活动 "+e.activity);const i=await t.evaluate(n);if(!i.selected)await t.evaluate(`document.querySelectorAll('.activity-card-drawer .activity-action')[${i.nth}].click()`);await r(t,`(${n})?.selected === true`,"关联活动");await h(t,".d-drawer-close")}if(e.attachment){await f(t,'.file-relation-container input[type="file"]',[a.resolve(e.attachment)]);await r(t,`document.querySelector('.file-relation-container .setting-card-text')?.textContent.trim() === ${JSON.stringify(a.basename(e.attachment))} && !document.querySelector('.file-relation-container')?.textContent.includes('上传中')`,"附件上传",60000)}if(o.chapters||e.summary!==void 0)await x(t,o.chapters,e.summary);if(e.cover){const n=await t.evaluate("document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage");await c(t,".cover-plugin-preview > .cover > .default");await c(t,".cover-plugin-preview .cover-edit-entry");await c(t,".d-modal .d-tabs-header-label","上传封面");await f(t,'.d-modal input[type="file"]',[a.resolve(e.cover)]);await r(t,"!!document.querySelector('#upload-cover-containner .cropper-canvas img')?.getAttribute('src')","封面图片载入",30000);if(e["cover-ratio"]){const i=e["cover-ratio"]==="original"?"原始":e["cover-ratio"];await c(t,".d-modal .crop-ratio-item",i);await r(t,`document.querySelector('.d-modal .crop-ratio-item-active')?.textContent.trim()===${JSON.stringify(i)}`,"封面裁剪比例")}await c(t,".d-modal button","确定");await r(t,`!document.querySelector('#upload-cover-containner') && document.querySelector('.cover-plugin-preview')?.getAttribute('aria-busy')==='false' && document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage !== ${JSON.stringify(n)}`,"视频封面上传",60000)}}
|
|
1
|
+
import{readChapters as v,setXhsChapters as x}from"./publish-editors.js";import*as s from"node:fs";import*as a from"node:path";import{setInputFiles as f}from"../../_shared/file-inject.js";import{ArgumentError as c,CommandExecutionError as d}from"@jackwener/opencli/errors";import{clickControl as l,control as w,fillControl as u,verifyControl as r,publicationTime as q,resolveDeclaration as b}from"../../_shared/publish-controls.js";async function y(t,e){const o=await w(t,".d-select",e);await t.evaluate(`(() => {const el=document.querySelectorAll('.d-select')[${o.nth}].closest('.d-select-wrapper'); el.focus();return true;})()`);await t.wait({time:0.2})}async function h(t,e,o){const n=await w(t,e,o);await t.evaluate(`(() => {document.querySelectorAll(${JSON.stringify(e)})[${n.nth}].click();return true;})()`);await t.wait({time:0.2})}export const XHS_DECLARATIONS={ai:"笔记含AI合成内容",fiction:"虚构演绎,仅供娱乐",marketing:"内容包含营销广告",reprint:"来源转载","self-shot":"自主拍摄"};const m={public:"公开可见",private:"仅自己可见",friends:"仅互关好友可见",include:"只给谁看",exclude:"不给谁看"};export const XHS_PUBLISH_ARGS=[{name:"declaration",choices:Object.keys(XHS_DECLARATIONS),help:"内容声明:ai / fiction / marketing / reprint / self-shot"},{name:"source",help:"转载来源媒体名称(declaration=reprint 必填)"},{name:"shot-location",help:"自主拍摄地点(使用平台候选地点的完整名称)"},{name:"shot-date",help:"自主拍摄日期 YYYY-MM-DD"},{name:"original",type:"boolean",help:"声明原创;true 同意平台原创声明须知,false 取消"},{name:"visibility",choices:Object.keys(m),help:"可见范围;include/exclude 需同时指定 --audience"},{name:"audience",help:"定向可见用户昵称,逗号分隔(最多200人,须在平台可选列表中)"},{name:"schedule",help:"北京时间 YYYY-MM-DD HH:mm / 带时区 ISO8601 / Unix秒;1小时至14天后"},{name:"allow-duet",type:"boolean",help:"允许合拍(true/false,不传保留平台默认)"},{name:"allow-copy",type:"boolean",help:"允许正文复制(true/false,不传保留平台默认)"},{name:"location",help:"地点完整名称,按平台搜索结果精确选择"},{name:"location-address",help:"地点完整地址,使用 xiaohongshu location 返回的地址区分重名"},{name:"activity",help:"关联活动完整名称(平台会自动添加活动话题)"},{name:"quote-note",help:"引用笔记链接(小红书完整链接,包含访问所需参数)"},{name:"quote-title",help:"引用自己已发布笔记的完整标题,与 --quote-note 二选一"},{name:"attachment",help:"文件附件路径:pdf/doc/docx/ppt/pptx,最多100MB"}],XHS_VIDEO_ARGS=[...XHS_PUBLISH_ARGS.filter((t)=>!["allow-duet","allow-copy","attachment"].includes(t.name)),{name:"chapters",help:"章节 JSON 文件路径:[{time:整数秒,title:章节名,description:描述}],视频须至少15秒"},{name:"summary",help:"视频内容总结(最多100字)"},{name:"cover",help:"自定义视频封面图片路径(jpg/png/webp)"},{name:"cover-ratio",choices:["original","1:1","3:4","4:3"],help:"封面裁剪比例,需同时提供 --cover"}];export function validateXhsSettings(t){if(t["location-address"]&&!t.location)throw new c("--location-address 需要 --location");const e=v(t.chapters);if(t.summary!==void 0&&[...String(t.summary)].length>100)throw new c("--summary 最多100字");if(t["cover-ratio"]&&!t.cover)throw new c("--cover-ratio 需要 --cover");if(t.cover){const i=a.resolve(t.cover);if(!s.existsSync(i)||!s.statSync(i).isFile()||![".jpg",".jpeg",".png",".webp"].includes(a.extname(i).toLowerCase()))throw new c("封面需为存在的 jpg/png/webp 文件")}if(t["quote-note"]&&t["quote-title"])throw new c("--quote-note 与 --quote-title 二选一");if(t["quote-note"]){let i;try{i=new URL(t["quote-note"])}catch{throw new c("--quote-note 需要完整的小红书笔记链接")}if(i.protocol!=="https:"||!["xiaohongshu.com","www.xiaohongshu.com","xhslink.com"].includes(i.hostname))throw new c("--quote-note 需要 HTTPS 小红书笔记链接")}if(t.attachment){const i=a.resolve(t.attachment);if(!s.existsSync(i)||!s.statSync(i).isFile())throw new c("附件文件不存在: "+i);if(![".pdf",".doc",".docx",".ppt",".pptx"].includes(a.extname(i).toLowerCase())||s.statSync(i).size>104857600)throw new c("附件需为100MB以内的 pdf/doc/docx/ppt/pptx")}const o=b(t,XHS_DECLARATIONS);if(o==="reprint"&&!String(t.source||"").trim())throw new c("--declaration reprint 需要 --source 媒体名称");if(t.source&&o!=="reprint")throw new c("--source 仅用于 --declaration reprint");if(o==="reprint"&&t.original)throw new c("转载来源声明不能与 --original true 同时使用");if(o==="self-shot"&&(!t["shot-location"]||!/^\d{4}-\d{2}-\d{2}$/.test(t["shot-date"]||"")))throw new c("自主拍摄需 --shot-location 和 --shot-date YYYY-MM-DD");if((t["shot-date"]||t["shot-location"])&&o!=="self-shot")throw new c("拍摄地点和日期仅用于 --declaration self-shot");if(t.visibility!==void 0&&!Object.hasOwn(m,t.visibility))throw new c("不支持的 --visibility");const n=String(t.audience||"").split(",").map((i)=>i.trim()).filter(Boolean);if(["include","exclude"].includes(t.visibility)&&(!n.length||n.length>200||new Set(n).size!==n.length))throw new c("定向可见需要1至200个不重复的 --audience 用户");if(n.length&&!["include","exclude"].includes(t.visibility))throw new c("--audience 仅用于 include/exclude 可见范围");return{declaration:o,schedule:q(t.schedule,1),audience:n,chapters:e}}async function p(t,e,o){return t.evaluate(`([...document.querySelectorAll(${JSON.stringify(e)})].filter(e=>e.getClientRects().length && e.textContent.trim()===${JSON.stringify(o)}).length === 1)`)}export async function xhsSwitch(t,e,o){const i=await(()=>t.evaluate(`((label)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);if(rows.length!==1)return null; const input=rows[0].querySelector('input[type="checkbox"]');return input ? {checked:input.checked,nth:[...document.querySelectorAll('.custom-switch-card .d-switch')].indexOf(rows[0].querySelector('.d-switch'))}:null;})(${JSON.stringify(e)})`))();if(!i||i.nth<0)throw new d("未找到发布设置开关:"+e+";已停止提交");if(i?.checked===o)return;await t.click(".custom-switch-card .d-switch",{nth:i.nth});await t.wait({time:0.2});if(e==="原创声明"&&o&&await t.evaluate("!!document.querySelector('.originalContainer')")){await l(t,".originalContainer .d-checkbox");await l(t,".originalContainer button","声明原创")}await r(t,`((label,value)=>{const rows=[...document.querySelectorAll('.custom-switch-card')].filter(e=>e.querySelector('.custom-switch-text-content > span')?.textContent.trim()===label);return rows.length===1 && rows[0].querySelector('input[type="checkbox"]')?.checked===value;})(${JSON.stringify(e)},${o})`,e)}async function C(t,e,o){const n=XHS_DECLARATIONS[o],i=await p(t,".d-select-description",n);if(i&&!["reprint","self-shot"].includes(o))return;await l(t,".d-select",i?n:"添加内容类型声明");if(o==="reprint"||o==="self-shot")await l(t,".declaration-drop-down .d-option-name","内容来源声明");await l(t,".d-popover .d-option-content",n);if(o==="reprint"){await u(t,'input[placeholder="请输入媒体名称"]',e.source);await l(t,".self-shooting-contain button","确认")}if(o==="self-shot"){await u(t,'input[placeholder="下拉选择地点"]',e["shot-location"],!1);await r(t,`!![...document.querySelectorAll('.el-autocomplete-suggestion .name')].find(e=>e.textContent.trim()===${JSON.stringify(e["shot-location"])})`,"拍摄地点候选");await l(t,".el-autocomplete-suggestion .name",e["shot-location"],!1);await u(t,".self-shooting-contain .d-datepicker-input-filter input",e["shot-date"]);await l(t,".self-shooting-contain button","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1) && !document.querySelector('.self-shooting-contain')`,n)}async function O(t){const e=await t.evaluate(`(() => {
|
|
2
|
+
const preview = document.querySelector('.cover-plugin-preview');
|
|
3
|
+
if (!preview) return {error: '未找到视频封面区(.cover-plugin-preview)'};
|
|
4
|
+
const entries = [...preview.querySelectorAll('.cover-edit-entry')].filter(e => e.textContent.trim() === '编辑封面');
|
|
5
|
+
if (entries.length !== 1) return {error: '封面区「编辑封面」入口应唯一,找到 ' + entries.length + ';封面区现有文字:' + preview.innerText.replace(/\\s+/g, ' ').trim().slice(0, 80)};
|
|
6
|
+
entries[0].click();
|
|
7
|
+
return {ok: true};
|
|
8
|
+
})()`);if(!e?.ok)throw new d(`发布设置 视频封面:${e?.error||"页面响应异常"};已停止提交`);await r(t,"[...document.querySelectorAll('.d-modal .d-tabs-header-label')].some(e => e.getClientRects().length && e.textContent.trim() === '上传封面')","打开设置封面弹窗",1e4)}export async function setXhsPublishSettings(t,e){const o=validateXhsSettings(e);if(e.original!==void 0)await xhsSwitch(t,"原创声明",e.original);if(o.declaration)await C(t,e,o.declaration);if(e["allow-duet"]!==void 0)await xhsSwitch(t,"允许合拍",e["allow-duet"]);if(e["allow-copy"]!==void 0)await xhsSwitch(t,"允许正文复制",e["allow-copy"]);if(e.visibility){const n=m[e.visibility];if(!await p(t,".d-select-description",n)){const i=await t.evaluate(`([...document.querySelectorAll('.d-select-description')].filter(e=>${JSON.stringify(Object.values(m))}.includes(e.textContent.trim())).map(e=>e.textContent.trim()))`);if(i.length!==1)throw new d("无法确定当前可见范围;已停止提交");await y(t,i[0]);await h(t,".custom-option .name",n)}if(o.audience.length){for(const i of o.audience){await u(t,'.d-modal input[placeholder="搜索用户"]',i,!1);await r(t,`!![...document.querySelectorAll('.d-modal .left .user-list *')].find(e=>!e.children.length&&e.textContent.trim()===${JSON.stringify(i)})`,"可选用户 "+i);await l(t,".d-modal .left .user-list .user-name",i)}await l(t,".d-modal .confirm-btn","确认")}await r(t,`([...document.querySelectorAll('.d-select-description')].filter(e=>e.textContent.trim()===${JSON.stringify(n)}).length===1)`,"可见范围")}if(o.schedule){await xhsSwitch(t,"定时发布",!0);await u(t,".d-datepicker-input-filter input",o.schedule)}if(e.location){await y(t,"添加地点");await u(t,".d-select.focus input",e.location,!1);const n=`(({name,address})=>{const all=[...document.querySelectorAll('.d-popover .option-name')];const hits=all.filter(e=>e.getClientRects().length && e.textContent.trim()===name && (!address || e.parentElement.querySelector('.option-subname')?.textContent.trim()===address));return hits.length===1 ? all.indexOf(hits[0]) : -1;})(${JSON.stringify({name:e.location,address:e["location-address"]})})`;await r(t,`(${n})>=0`,"唯一地点(重名时指定 --location-address)");const i=await t.evaluate(n);if(i<0)throw new d("地点候选已变化,停止提交");await t.evaluate(`document.querySelectorAll('.d-popover .option-name')[${i}].click()`);await r(t,`!![...document.querySelectorAll('.d-select-description')].find(e=>e.textContent.trim()===${JSON.stringify(e.location)})`,"地点")}if(e["quote-note"]||e["quote-title"]){await l(t,".setting-card-text","引用笔记");if(e["quote-note"]){await l(t,".select-note-modal__tab","他人笔记");await u(t,'input[placeholder="请粘贴笔记链接 http://..."]',e["quote-note"],!1)}const n=e["quote-title"];await r(t,`([...document.querySelectorAll('.select-note-modal .note-card__title')].filter(e=>e.getClientRects().length ${n?"&& e.textContent.trim()==="+JSON.stringify(n):""}).length===1)`,"待引用笔记");const i=await w(t,".select-note-modal .note-card__title",n),S=await t.evaluate(`document.querySelectorAll('.select-note-modal .note-card__title')[${i.nth}].textContent.trim()`);await t.click(i.selector,{nth:i.nth});await l(t,".select-note-modal button","确认引用");await r(t,`!document.querySelector('.select-note-modal') && document.body.innerText.includes(${JSON.stringify("《")} + ${JSON.stringify(S)} + '》')`,"引用笔记")}if(e.activity){await h(t,".more","更多");const n=`((name)=>{const cards=[...document.querySelectorAll('.activity-card-drawer')].filter(e=>e.querySelector('.activity-name')?.textContent.trim()===name);return cards.length===1 ? {nth:[...document.querySelectorAll('.activity-card-drawer .activity-action')].indexOf(cards[0].querySelector('.activity-action')),selected:cards[0].querySelector('.activity-action')?.textContent.trim()==='取消关联'} : null;})(${JSON.stringify(e.activity)})`;await r(t,`!!(${n})`,"活动 "+e.activity);const i=await t.evaluate(n);if(!i.selected)await t.evaluate(`document.querySelectorAll('.activity-card-drawer .activity-action')[${i.nth}].click()`);await r(t,`(${n})?.selected === true`,"关联活动");await h(t,".d-drawer-close")}if(e.attachment){await f(t,'.file-relation-container input[type="file"]',[a.resolve(e.attachment)]);await r(t,`document.querySelector('.file-relation-container .setting-card-text')?.textContent.trim() === ${JSON.stringify(a.basename(e.attachment))} && !document.querySelector('.file-relation-container')?.textContent.includes('上传中')`,"附件上传",60000)}if(o.chapters||e.summary!==void 0)await x(t,o.chapters,e.summary);if(e.cover){const n=await t.evaluate("document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage");await O(t);await l(t,".d-modal .d-tabs-header-label","上传封面");await f(t,'.d-modal input[type="file"]',[a.resolve(e.cover)]);await r(t,"!!document.querySelector('#upload-cover-containner .cropper-canvas img')?.getAttribute('src')","封面图片载入",30000);if(e["cover-ratio"]){const i=e["cover-ratio"]==="original"?"原始":e["cover-ratio"];await l(t,".d-modal .crop-ratio-item",i);await r(t,`document.querySelector('.d-modal .crop-ratio-item-active')?.textContent.trim()===${JSON.stringify(i)}`,"封面裁剪比例")}await l(t,".d-modal button","确定");await r(t,`!document.querySelector('#upload-cover-containner') && document.querySelector('.cover-plugin-preview')?.getAttribute('aria-busy')==='false' && document.querySelector('.cover-plugin-preview > .cover > .default')?.style.backgroundImage !== ${JSON.stringify(n)}`,"视频封面上传",60000)}}
|
|
@@ -37,7 +37,7 @@ import{TOPIC_ID_ARG as C,parseTopics as I,attachTopics as q}from"./_shared/topic
|
|
|
37
37
|
`)}B({site:"xiaohongshu",name:"publish-video",access:"write",description:"小红书发布视频笔记(creator center UI 自动化)",domain:"creator.xiaohongshu.com",strategy:U.COOKIE,browser:!0,navigateBefore:!1,args:[{name:"content",required:!1,positional:!0,help:"笔记正文(字面文本,不展开 @文件 引用;长正文用 --file)"},{name:"file",required:!1,help:"从本机文件读取正文(UTF-8),与位置参数 <content> 二选一"},{name:"title",required:!0,help:"笔记标题(≤20字)"},{name:"video",required:!0,help:"视频文件路径 (mp4/mov/mkv/...)"},{name:"topics",required:!1,help:"话题名称,逗号分隔,最多10个;先用 topics 查询。无法准确选中时停止提交"},C,{name:"draft",type:"bool",default:!1,help:"暂存为草稿,不直接发布"},{name:"ai-generated",type:"boolean",help:"声明内容由 AI 生成(发布和草稿均支持;设置失败时停止提交)"},...D],columns:["status","detail"],func:async(t,e)=>{R(e);if(!t)throw Error("Browser page required");const i=String(e.title??"").trim(),n=e.file?String(e.file).trim():"";let o=String(e.content??"").trim();if(n){if(o)throw new s("正文位置参数和 --file 只能二选一");const r=p.resolve(n);if(!_.existsSync(r))throw new s(`--file 指向的文件不存在: ${r}`);o=_.readFileSync(r,"utf-8").trim();if(!o)throw new s(`--file 指向的文件内容为空: ${r}`)}const c=I(e),h=c.map((r)=>r.name),l=Boolean(e.draft);if(!i)throw new s("--title 必填");if(i.length>y)throw new s(`标题 ${i.length} 字,需 ≤ ${y} 字`);if(!o)throw new s("缺少正文:给位置参数 <content>,或用 --file <本机文件路径>");k(o,{fileFlag:"--file"});if(o.length>x)throw new s(`正文 ${o.length} 字,需 ≤ ${x} 字`);if(!e.video)throw new s("--video 必填");if(h.length>S)throw new s(`话题过多: ${h.length}(最多 ${S} 个)`);const v=G(String(e.video));await t.goto(J);await t.evaluate(`(() => {
|
|
38
38
|
document.documentElement.setAttribute('data-ppcli-composer-reload', 'pending');
|
|
39
39
|
setTimeout(() => location.reload(), 100);
|
|
40
|
-
})()`);await L(t
|
|
40
|
+
})()`);await L(t,`!!document.documentElement && !document.documentElement.hasAttribute('data-ppcli-composer-reload') && !!document.querySelector('input[type="file"]')`,"新的视频发布表单",30000);let d="";for(let r=0;r<30;r++){await t.wait({time:0.5});d=await t.evaluate("() => location.href");if(d.includes("creator.xiaohongshu.com"))break}if(!d.includes("creator.xiaohongshu.com")){await t.screenshot({path:"/tmp/xhs_video_redirect_debug.png"});throw new a(`被重定向离开创作者中心(当前 ${d})——登录态可能已过期。`+"用 ppcli xiaohongshu creator-profile 重新登录。截图: /tmp/xhs_video_redirect_debug.png")}const g=await K(t,v);if(!g.ok){await t.screenshot({path:"/tmp/xhs_video_upload_debug.png"});throw new a(`视频上传失败: ${g.error??"unknown"}。截图: /tmp/xhs_video_upload_debug.png`)}if(!await Q(t)){await t.screenshot({path:"/tmp/xhs_video_form_debug.png"});throw new a("上传后编辑表单未就绪(标题/正文未出现)。截图: /tmp/xhs_video_form_debug.png")}process.stderr.write(` 等待视频转码(可发布状态)...
|
|
41
41
|
`);if(!await z(t)){await t.screenshot({path:"/tmp/xhs_video_transcode_debug.png"});throw new a("视频转码超时(10min),发布按钮未解禁。截图: /tmp/xhs_video_transcode_debug.png")}await W(t,i);await t.wait({time:0.4});await Z(t,o);await t.wait({time:0.5});let m=[];if(h.length){m=await q(t,[b],c);const r=h.filter((P)=>!m.includes(P));if(r.length){await t.screenshot({path:"/tmp/xhs_video_topic_debug.png"});throw new a(`话题未能生成实体: ${r.join(", ")}(联想下拉未出现或无匹配项)。截图: /tmp/xhs_video_topic_debug.png`)}}await F(t,e);const M=await t.evaluate("(() => { const b = document.querySelector('xhs-publish-btn'); return !!b && b.getAttribute('submit-disabled') === 'false'; })()");if(!l&&!M){await t.screenshot({path:"/tmp/xhs_video_prepublish_debug.png"});throw new a("发布前复查:发布按钮不可用(submit-disabled≠false)。截图: /tmp/xhs_video_prepublish_debug.png")}const f=await tt(t,l);if(!f?.ok){await t.screenshot({path:"/tmp/xhs_video_submit_debug.png"});throw new a(`找不到「${l?"暂存离开":"发布"}」触发方式(hosts=${f?.hosts??0}${f?.lastMethodError?`, lastMethodError=${f.lastMethodError}`:""})。截图: /tmp/xhs_video_submit_debug.png`)}await t.wait({time:4});let u=await t.evaluate("() => location.href");const N=l?["草稿已保存","暂存成功","保存成功","保存于"]:["发布成功","上传成功"],w=await t.evaluate(`
|
|
42
42
|
((markers) => {
|
|
43
43
|
for (const el of document.querySelectorAll('*')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "publishport-opencli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.59",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": false
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"dev": "tsx src/main.ts",
|
|
47
47
|
"dev:bun": "bun src/main.ts",
|
|
48
|
+
"prerelease": "npm run build && git diff --exit-code --stat -- cli-manifest.json",
|
|
48
49
|
"release": "npm version patch -m \"chore(release): %s\" && git push origin HEAD && git push origin \"$(git describe --tags --abbrev=0)\"",
|
|
49
50
|
"build": "npm run clean-dist && npm run copy-yaml && npm run build-manifest",
|
|
50
51
|
"minify:release": "bun scripts/minify-release.mjs",
|